Skip to content

Commit

Permalink
fix asyncapi discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
udamir committed Jan 21, 2024
1 parent e13f7dc commit c0d81db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api-smart-diff",
"version": "1.0.0",
"version": "1.0.1",
"description": "Generate the diff between two API specifications (OpenAPI, AsyncAPI, GraphApi, JsonSchema)",
"module": "dist/index.mjs",
"main": "dist/index.cjs",
Expand Down
12 changes: 7 additions & 5 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import type { ComapreOptions, CompareEngine } from "./types"
import { compareJsonSchema } from "./jsonSchema"
import { compareGraphApi } from "./graphapi"
import { compareAsyncApi } from "./asyncapi"
import { compareOpenApi } from "./openapi"
import { isObject, isString } from "./utils"

export const discoverCompareEngine = (data: any): CompareEngine => {
if (typeof data !== "object" || !data) { return compareJsonSchema }
export const discoverCompareEngine = (data: unknown): CompareEngine => {
if (!isObject(data)) { return compareJsonSchema }

if (/3.+/.test(data.openapi ?? "")) return compareOpenApi
// if (/2.+/.test(data?.asyncapi || "")) return asyncApi2Rules
if ("openapi" in data && isString(data.openapi) && /3.+/.test(data.openapi)) return compareOpenApi
if ("asyncapi" in data && isString(data.asyncapi) && /2.+/.test(data.asyncapi)) return compareAsyncApi
// if (/2.+/.test(data?.swagger || "")) return swagger2Rules
if (data?.graphapi) return compareGraphApi
if ("graphapi" in data && data.graphapi) return compareGraphApi
return compareJsonSchema
}

Expand Down

0 comments on commit c0d81db

Please sign in to comment.