Skip to content

Commit

Permalink
Merge pull request #511 from paulRbr/truly-upgrade-asyncapi-spec
Browse files Browse the repository at this point in the history
deps: make sure to force the minimum version of AsyncAPI spec
  • Loading branch information
paulRbr authored Oct 2, 2023
2 parents e82a7b3 + 9f78524 commit 863e680
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"types": "lib/index.d.ts",
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^9.0.7",
"@asyncapi/specs": "^4.0.1",
"@asyncapi/specs": "^5.1.0",
"@clack/prompts": "^0.6.3",
"@oclif/command": "^1.8.16",
"@oclif/config": "^1.17.0",
Expand Down
19 changes: 11 additions & 8 deletions src/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@ import {
JSONSchema4Object,
JSONSchema6,
JSONSchema6Object,
JSONSchema7,
} from 'json-schema';
import path from 'path';

type SpecSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;

class SupportedFormat {
static readonly openapi: Record<string, SpecSchema> = {
'2.0': require('oas-schemas/schemas/v2.0/schema.json'),
'3.0': require('oas-schemas/schemas/v3.0/schema.json'),
'3.1': require('oas-schemas/schemas/v3.1/schema.json'),
};
static readonly asyncapi: Record<string, SpecSchema> = {
'2.0': asyncapi['2.0.0'],
'2.1': asyncapi['2.1.0'],
'2.2': asyncapi['2.2.0'],
'2.3': asyncapi['2.3.0'],
'2.4': asyncapi['2.4.0'],
'2.5': asyncapi['2.5.0'],
'2.6': asyncapi['2.6.0'],
'2.0': asyncapi.schemas['2.0.0'],
'2.1': asyncapi.schemas['2.1.0'],
'2.2': asyncapi.schemas['2.2.0'],
'2.3': asyncapi.schemas['2.3.0'],
'2.4': asyncapi.schemas['2.4.0'],
'2.5': asyncapi.schemas['2.5.0'],
'2.6': asyncapi.schemas['2.6.0'],
};
}

Expand Down Expand Up @@ -67,7 +70,7 @@ class API {
}
}

getSpec(definition: APIDefinition): Record<string, unknown> {
getSpec(definition: APIDefinition): SpecSchema {
if (API.isAsyncAPI(definition)) {
return SupportedFormat.asyncapi[this.versionWithoutPatch()];
} else {
Expand Down
9 changes: 0 additions & 9 deletions typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
// oas-schemas doesn't define TS types
declare module 'oas-schemas';

type SpecSchema = Record<string, unknown>;

// AsyncAPI doesn't define TS types
declare module '@asyncapi/specs' {
const asyncapi: Record<string, SpecSchema>;

export default asyncapi;
}

// Internals of json-schema-ref-parser doesn't expose types
declare module '@apidevtools/json-schema-ref-parser/lib/options';

Expand Down

0 comments on commit 863e680

Please sign in to comment.