mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-06 04:21:09 +00:00
refactor(asyncapi): updated asyncapi v2 typings to conform to JSON Schema draft-07 (#1608)
Co-authored-by: Jeremy Fiel <jeremy.fiel@adp.com>
This commit is contained in:
6
.changeset/new-poets-smile.md
Normal file
6
.changeset/new-poets-smile.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@redocly/openapi-core": patch
|
||||||
|
"@redocly/cli": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Updated AsyncAPI v2 typings to abide by JSON Schema draft-07 specification.
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -334,11 +334,8 @@ const MessageExample: NodeType = {
|
|||||||
const Schema: NodeType = {
|
const Schema: NodeType = {
|
||||||
properties: {
|
properties: {
|
||||||
$id: { type: 'string' },
|
$id: { type: 'string' },
|
||||||
id: { type: 'string' },
|
|
||||||
$schema: { type: 'string' },
|
$schema: { type: 'string' },
|
||||||
definitions: 'NamedSchemas',
|
definitions: 'NamedSchemas',
|
||||||
$defs: 'NamedSchemas',
|
|
||||||
$vocabulary: { type: 'string' },
|
|
||||||
externalDocs: 'ExternalDocs',
|
externalDocs: 'ExternalDocs',
|
||||||
discriminator: 'Discriminator',
|
discriminator: 'Discriminator',
|
||||||
myArbitraryKeyword: { type: 'boolean' },
|
myArbitraryKeyword: { type: 'boolean' },
|
||||||
@@ -359,16 +356,14 @@ const Schema: NodeType = {
|
|||||||
required: { type: 'array', items: { type: 'string' } },
|
required: { type: 'array', items: { type: 'string' } },
|
||||||
enum: { type: 'array' },
|
enum: { type: 'array' },
|
||||||
type: (value: any) => {
|
type: (value: any) => {
|
||||||
if (Array.isArray(value)) {
|
return Array.isArray(value)
|
||||||
return {
|
? {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
items: { enum: ['object', 'array', 'string', 'number', 'integer', 'boolean', 'null'] },
|
items: { enum: ['object', 'array', 'string', 'number', 'integer', 'boolean', 'null'] },
|
||||||
};
|
}
|
||||||
} else {
|
: {
|
||||||
return {
|
enum: ['object', 'array', 'string', 'number', 'integer', 'boolean', 'null'],
|
||||||
enum: ['object', 'array', 'string', 'number', 'integer', 'boolean', 'null'],
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
allOf: listOf('Schema'),
|
allOf: listOf('Schema'),
|
||||||
anyOf: listOf('Schema'),
|
anyOf: listOf('Schema'),
|
||||||
@@ -377,35 +372,12 @@ const Schema: NodeType = {
|
|||||||
if: 'Schema',
|
if: 'Schema',
|
||||||
then: 'Schema',
|
then: 'Schema',
|
||||||
else: 'Schema',
|
else: 'Schema',
|
||||||
dependentSchemas: listOf('Schema'),
|
|
||||||
prefixItems: listOf('Schema'),
|
|
||||||
contains: 'Schema',
|
contains: 'Schema',
|
||||||
minContains: { type: 'integer', minimum: 0 },
|
|
||||||
maxContains: { type: 'integer', minimum: 0 },
|
|
||||||
patternProperties: { type: 'object' },
|
patternProperties: { type: 'object' },
|
||||||
propertyNames: 'Schema',
|
propertyNames: 'Schema',
|
||||||
unevaluatedItems: (value: unknown) => {
|
|
||||||
if (typeof value === 'boolean') {
|
|
||||||
return { type: 'boolean' };
|
|
||||||
} else {
|
|
||||||
return 'Schema';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
unevaluatedProperties: (value: unknown) => {
|
|
||||||
if (typeof value === 'boolean') {
|
|
||||||
return { type: 'boolean' };
|
|
||||||
} else {
|
|
||||||
return 'Schema';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
summary: { type: 'string' },
|
|
||||||
properties: 'SchemaProperties',
|
properties: 'SchemaProperties',
|
||||||
items: (value: any) => {
|
items: (value: any) => {
|
||||||
if (typeof value === 'boolean') {
|
return Array.isArray(value) ? listOf('Schema') : 'Schema';
|
||||||
return { type: 'boolean' };
|
|
||||||
} else {
|
|
||||||
return 'Schema';
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
additionalProperties: (value: any) => {
|
additionalProperties: (value: any) => {
|
||||||
return typeof value === 'boolean' ? { type: 'boolean' } : 'Schema';
|
return typeof value === 'boolean' ? { type: 'boolean' } : 'Schema';
|
||||||
@@ -417,23 +389,22 @@ const Schema: NodeType = {
|
|||||||
default: null,
|
default: null,
|
||||||
readOnly: { type: 'boolean' },
|
readOnly: { type: 'boolean' },
|
||||||
writeOnly: { type: 'boolean' },
|
writeOnly: { type: 'boolean' },
|
||||||
// xml: 'Xml',
|
|
||||||
examples: { type: 'array' },
|
examples: { type: 'array' },
|
||||||
example: { isExample: true },
|
example: { isExample: true },
|
||||||
deprecated: { type: 'boolean' },
|
deprecated: { type: 'boolean' },
|
||||||
const: null,
|
const: null,
|
||||||
$comment: { type: 'string' },
|
$comment: { type: 'string' },
|
||||||
dependencies: { type: 'object' }, // TODO
|
additionalItems: (value: any) => {
|
||||||
|
return typeof value === 'boolean' ? { type: 'boolean' } : 'Schema';
|
||||||
|
},
|
||||||
|
dependencies: 'Dependencies',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const SchemaProperties: NodeType = {
|
const SchemaProperties: NodeType = {
|
||||||
properties: {},
|
properties: {},
|
||||||
additionalProperties: (value: any) => {
|
additionalProperties: (value: any) => {
|
||||||
if (typeof value === 'boolean') {
|
return typeof value === 'boolean' ? { type: 'boolean' } : 'Schema';
|
||||||
return { type: 'boolean' };
|
|
||||||
}
|
|
||||||
return 'Schema';
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -584,6 +555,13 @@ const SecurityScheme: NodeType = {
|
|||||||
extensionsPrefix: 'x-',
|
extensionsPrefix: 'x-',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Dependencies: NodeType = {
|
||||||
|
properties: {},
|
||||||
|
additionalProperties: (value: any) => {
|
||||||
|
return Array.isArray(value) ? { type: 'array', items: { type: 'string' } } : 'Schema';
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// --- Per-protocol node types
|
// --- Per-protocol node types
|
||||||
|
|
||||||
// http
|
// http
|
||||||
@@ -1133,4 +1111,5 @@ export const AsyncApi2Types: Record<string, NodeType> = {
|
|||||||
MessageTrait,
|
MessageTrait,
|
||||||
MessageTraitList: listOf('MessageTrait'),
|
MessageTraitList: listOf('MessageTrait'),
|
||||||
CorrelationId,
|
CorrelationId,
|
||||||
|
Dependencies,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user