Skip to content

Commit d081434

Browse files
authored
chore: remove swagger-parser validation (#140)
1 parent 8ad1db6 commit d081434

File tree

5 files changed

+63
-24
lines changed

5 files changed

+63
-24
lines changed

.changeset/ripe-ads-lie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@pactflow/openapi-pact-comparator": minor
3+
---
4+
5+
Remove swagger-parser validation as it is very slow

package-lock.json

Lines changed: 54 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"license": "Apache-2.0",
4242
"type": "module",
4343
"devDependencies": {
44-
"@apidevtools/swagger-parser": "10.1.1",
4544
"@changesets/cli": "2.28.1",
4645
"@eslint/js": "9.23.0",
4746
"@pactflow/swagger-mock-validator": "14.5.0",

src/compare/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export class Comparator {
3131
this.#config = new Map(DEFAULT_CONFIG);
3232
this.#oas = oas;
3333

34+
parseOas(oas);
35+
3436
const ajvOptions = {
3537
allErrors: true,
3638
discriminator: true,
@@ -51,7 +53,6 @@ export class Comparator {
5153

5254
async *compare(pact: Pact): AsyncGenerator<Result> {
5355
if (!this.#router) {
54-
await parseOas(this.#oas);
5556
for (const [key, value] of Object.entries(this.#oas.info)) {
5657
if (key.startsWith("x-opc-config-")) {
5758
this.#config.set(key.substring(13) as ConfigKeys, value);

src/documents/oas.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import type { OpenAPIV2, OpenAPIV3 } from "openapi-types";
2-
import SwaggerParser from "@apidevtools/swagger-parser";
3-
import { cloneDeep } from "lodash-es";
42

53
const isSwagger2 = (oas: OpenAPIV2.Document): boolean =>
64
Object.prototype.hasOwnProperty.call(oas, "swagger") &&
@@ -12,17 +10,15 @@ const isOpenApi3 = (oas: OpenAPIV3.Document): boolean =>
1210
typeof oas.openapi === "string" &&
1311
oas.openapi.indexOf("3.") === 0;
1412

15-
export const parse = async (
16-
oas: OpenAPIV2.Document | OpenAPIV3.Document,
17-
): Promise<void> => {
13+
export const parse = (oas: OpenAPIV2.Document | OpenAPIV3.Document): void => {
1814
if (
1915
!isSwagger2(oas as OpenAPIV2.Document) &&
2016
!isOpenApi3(oas as OpenAPIV3.Document)
2117
) {
2218
throw new ParserError();
2319
}
2420

25-
await SwaggerParser.validate(cloneDeep(oas));
21+
// FIXME: ideally, we validate the document here
2622
};
2723

2824
export class ParserError extends Error {

0 commit comments

Comments
 (0)