@asyncapi/react-component 1.0.0-next.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -36
- package/browser/index.js +32 -14
- package/browser/index.js.LICENSE.txt +88 -0
- package/browser/standalone/index.js +32 -43
- package/browser/standalone/index.js.LICENSE.txt +112 -0
- package/browser/standalone/without-parser.js +14 -41
- package/browser/standalone/without-parser.js.LICENSE.txt +110 -0
- package/browser/without-parser.js +14 -12
- package/browser/without-parser.js.LICENSE.txt +86 -0
- package/lib/cjs/components/Bindings.js +14 -5
- package/lib/cjs/components/Bindings.js.map +1 -1
- package/lib/cjs/components/CollapseButton.js +11 -7
- package/lib/cjs/components/CollapseButton.js.map +1 -1
- package/lib/cjs/components/Extensions.js +4 -3
- package/lib/cjs/components/Extensions.js.map +1 -1
- package/lib/cjs/components/Href.js +2 -1
- package/lib/cjs/components/Href.js.map +1 -1
- package/lib/cjs/components/JSONSnippet.js +2 -1
- package/lib/cjs/components/JSONSnippet.js.map +1 -1
- package/lib/cjs/components/Markdown.js +3 -2
- package/lib/cjs/components/Markdown.js.map +1 -1
- package/lib/cjs/components/Schema.js +77 -60
- package/lib/cjs/components/Schema.js.map +1 -1
- package/lib/cjs/components/Tag.js +3 -2
- package/lib/cjs/components/Tag.js.map +1 -1
- package/lib/cjs/components/Tags.js +3 -2
- package/lib/cjs/components/Tags.js.map +1 -1
- package/lib/cjs/components/index.js +5 -1
- package/lib/cjs/components/index.js.map +1 -1
- package/lib/cjs/config/config.js.map +1 -1
- package/lib/cjs/config/default.js +9 -1
- package/lib/cjs/config/default.js.map +1 -1
- package/lib/cjs/config/index.js +5 -1
- package/lib/cjs/config/index.js.map +1 -1
- package/lib/cjs/constants.js +12 -48
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/containers/AsyncApi/AsyncApi.js +28 -12
- package/lib/cjs/containers/AsyncApi/AsyncApi.js.map +1 -1
- package/lib/cjs/containers/AsyncApi/Layout.js +33 -21
- package/lib/cjs/containers/AsyncApi/Layout.js.map +1 -1
- package/lib/cjs/containers/AsyncApi/Standalone.js +8 -2
- package/lib/cjs/containers/AsyncApi/Standalone.js.map +1 -1
- package/lib/cjs/containers/Error/Error.js +4 -3
- package/lib/cjs/containers/Error/Error.js.map +1 -1
- package/lib/cjs/containers/Info/Info.js +11 -10
- package/lib/cjs/containers/Info/Info.js.map +1 -1
- package/lib/cjs/containers/Messages/Message.js +23 -10
- package/lib/cjs/containers/Messages/Message.js.map +1 -1
- package/lib/cjs/containers/Messages/MessageExample.js +25 -13
- package/lib/cjs/containers/Messages/MessageExample.js.map +1 -1
- package/lib/cjs/containers/Messages/Messages.js +14 -9
- package/lib/cjs/containers/Messages/Messages.js.map +1 -1
- package/lib/cjs/containers/Operations/Operation.js +88 -38
- package/lib/cjs/containers/Operations/Operation.js.map +1 -1
- package/lib/cjs/containers/Operations/Operations.js +20 -13
- package/lib/cjs/containers/Operations/Operations.js.map +1 -1
- package/lib/cjs/containers/Schemas/Schema.js +21 -0
- package/lib/cjs/containers/Schemas/Schema.js.map +1 -0
- package/lib/cjs/containers/Schemas/Schemas.js +29 -0
- package/lib/cjs/containers/Schemas/Schemas.js.map +1 -0
- package/lib/cjs/containers/Servers/Security.js +150 -0
- package/lib/cjs/containers/Servers/Security.js.map +1 -0
- package/lib/cjs/containers/Servers/Server.js +15 -8
- package/lib/cjs/containers/Servers/Server.js.map +1 -1
- package/lib/cjs/containers/Servers/Servers.js +12 -7
- package/lib/cjs/containers/Servers/Servers.js.map +1 -1
- package/lib/cjs/containers/Sidebar/Sidebar.js +201 -141
- package/lib/cjs/containers/Sidebar/Sidebar.js.map +1 -1
- package/lib/cjs/contexts/index.js +6 -1
- package/lib/cjs/contexts/index.js.map +1 -1
- package/lib/cjs/contexts/useConfig.js +10 -0
- package/lib/cjs/contexts/useConfig.js.map +1 -0
- package/lib/cjs/contexts/useSpec.js +7 -3
- package/lib/cjs/contexts/useSpec.js.map +1 -1
- package/lib/cjs/helpers/bindingsHelpers.js +24 -0
- package/lib/cjs/helpers/bindingsHelpers.js.map +1 -0
- package/lib/cjs/helpers/common.js +17 -0
- package/lib/cjs/helpers/common.js.map +1 -0
- package/lib/cjs/helpers/index.js +6 -3
- package/lib/cjs/helpers/index.js.map +1 -1
- package/lib/cjs/helpers/marked.js +2 -2
- package/lib/cjs/helpers/marked.js.map +1 -1
- package/lib/cjs/helpers/message.js +39 -9
- package/lib/cjs/helpers/message.js.map +1 -1
- package/lib/cjs/helpers/parser.js +16 -15
- package/lib/cjs/helpers/parser.js.map +1 -1
- package/lib/cjs/helpers/schema.js +186 -149
- package/lib/cjs/helpers/schema.js.map +1 -1
- package/lib/cjs/helpers/server.js +49 -0
- package/lib/cjs/helpers/server.js.map +1 -1
- package/lib/cjs/helpers/specification.js +36 -21
- package/lib/cjs/helpers/specification.js.map +1 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.js +4 -51
- package/lib/cjs/types.js.map +1 -1
- package/lib/cjs/without-parser.js.map +1 -1
- package/lib/esm/components/Bindings.js +12 -4
- package/lib/esm/components/Bindings.js.map +1 -1
- package/lib/esm/components/CollapseButton.js +9 -6
- package/lib/esm/components/CollapseButton.js.map +1 -1
- package/lib/esm/components/Extensions.js +2 -2
- package/lib/esm/components/Extensions.js.map +1 -1
- package/lib/esm/components/Href.js.map +1 -1
- package/lib/esm/components/JSONSnippet.js.map +1 -1
- package/lib/esm/components/Markdown.js +1 -1
- package/lib/esm/components/Markdown.js.map +1 -1
- package/lib/esm/components/Schema.js +71 -59
- package/lib/esm/components/Schema.js.map +1 -1
- package/lib/esm/components/Tag.js +1 -1
- package/lib/esm/components/Tag.js.map +1 -1
- package/lib/esm/components/Tags.js +1 -1
- package/lib/esm/components/Tags.js.map +1 -1
- package/lib/esm/components/index.js.map +1 -1
- package/lib/esm/config/config.js.map +1 -1
- package/lib/esm/config/default.js +9 -1
- package/lib/esm/config/default.js.map +1 -1
- package/lib/esm/config/index.js.map +1 -1
- package/lib/esm/constants.js +10 -47
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/containers/AsyncApi/AsyncApi.js +22 -10
- package/lib/esm/containers/AsyncApi/AsyncApi.js.map +1 -1
- package/lib/esm/containers/AsyncApi/Layout.js +28 -20
- package/lib/esm/containers/AsyncApi/Layout.js.map +1 -1
- package/lib/esm/containers/AsyncApi/Standalone.js +3 -1
- package/lib/esm/containers/AsyncApi/Standalone.js.map +1 -1
- package/lib/esm/containers/Error/Error.js +2 -2
- package/lib/esm/containers/Error/Error.js.map +1 -1
- package/lib/esm/containers/Info/Info.js +8 -8
- package/lib/esm/containers/Info/Info.js.map +1 -1
- package/lib/esm/containers/Messages/Message.js +21 -9
- package/lib/esm/containers/Messages/Message.js.map +1 -1
- package/lib/esm/containers/Messages/MessageExample.js +17 -11
- package/lib/esm/containers/Messages/MessageExample.js.map +1 -1
- package/lib/esm/containers/Messages/Messages.js +13 -9
- package/lib/esm/containers/Messages/Messages.js.map +1 -1
- package/lib/esm/containers/Operations/Operation.js +87 -39
- package/lib/esm/containers/Operations/Operation.js.map +1 -1
- package/lib/esm/containers/Operations/Operations.js +19 -13
- package/lib/esm/containers/Operations/Operations.js.map +1 -1
- package/lib/esm/containers/Schemas/Schema.js +14 -0
- package/lib/esm/containers/Schemas/Schema.js.map +1 -0
- package/lib/esm/containers/Schemas/Schemas.js +22 -0
- package/lib/esm/containers/Schemas/Schemas.js.map +1 -0
- package/lib/esm/containers/Servers/Security.js +143 -0
- package/lib/esm/containers/Servers/Security.js.map +1 -0
- package/lib/esm/containers/Servers/Server.js +15 -9
- package/lib/esm/containers/Servers/Server.js.map +1 -1
- package/lib/esm/containers/Servers/Servers.js +11 -7
- package/lib/esm/containers/Servers/Servers.js.map +1 -1
- package/lib/esm/containers/Sidebar/Sidebar.js +191 -136
- package/lib/esm/containers/Sidebar/Sidebar.js.map +1 -1
- package/lib/esm/contexts/index.js +1 -0
- package/lib/esm/contexts/index.js.map +1 -1
- package/lib/esm/contexts/useConfig.js +6 -0
- package/lib/esm/contexts/useConfig.js.map +1 -0
- package/lib/esm/contexts/useSpec.js +2 -2
- package/lib/esm/contexts/useSpec.js.map +1 -1
- package/lib/esm/helpers/bindingsHelpers.js +21 -0
- package/lib/esm/helpers/bindingsHelpers.js.map +1 -0
- package/lib/esm/helpers/common.js +14 -0
- package/lib/esm/helpers/common.js.map +1 -0
- package/lib/esm/helpers/index.js +1 -2
- package/lib/esm/helpers/index.js.map +1 -1
- package/lib/esm/helpers/marked.js +1 -1
- package/lib/esm/helpers/marked.js.map +1 -1
- package/lib/esm/helpers/message.js +38 -8
- package/lib/esm/helpers/message.js.map +1 -1
- package/lib/esm/helpers/parser.js +17 -13
- package/lib/esm/helpers/parser.js.map +1 -1
- package/lib/esm/helpers/schema.js +182 -142
- package/lib/esm/helpers/schema.js.map +1 -1
- package/lib/esm/helpers/server.js +49 -0
- package/lib/esm/helpers/server.js.map +1 -1
- package/lib/esm/helpers/specification.js +36 -18
- package/lib/esm/helpers/specification.js.map +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.js +2 -46
- package/lib/esm/types.js.map +1 -1
- package/lib/esm/without-parser.js.map +1 -1
- package/lib/types/components/Bindings.d.ts +2 -1
- package/lib/types/components/Bindings.d.ts.map +1 -1
- package/lib/types/components/CollapseButton.d.ts +1 -0
- package/lib/types/components/CollapseButton.d.ts.map +1 -1
- package/lib/types/components/Extensions.d.ts.map +1 -1
- package/lib/types/components/Schema.d.ts +5 -4
- package/lib/types/components/Schema.d.ts.map +1 -1
- package/lib/types/components/Tag.d.ts +2 -2
- package/lib/types/components/Tag.d.ts.map +1 -1
- package/lib/types/components/Tags.d.ts +2 -2
- package/lib/types/components/Tags.d.ts.map +1 -1
- package/lib/types/config/config.d.ts +8 -0
- package/lib/types/config/config.d.ts.map +1 -1
- package/lib/types/config/default.d.ts.map +1 -1
- package/lib/types/constants.d.ts +10 -26
- package/lib/types/constants.d.ts.map +1 -1
- package/lib/types/containers/AsyncApi/AsyncApi.d.ts +2 -2
- package/lib/types/containers/AsyncApi/AsyncApi.d.ts.map +1 -1
- package/lib/types/containers/AsyncApi/Layout.d.ts +2 -2
- package/lib/types/containers/AsyncApi/Layout.d.ts.map +1 -1
- package/lib/types/containers/AsyncApi/Standalone.d.ts +2 -2
- package/lib/types/containers/AsyncApi/Standalone.d.ts.map +1 -1
- package/lib/types/containers/Info/Info.d.ts.map +1 -1
- package/lib/types/containers/Messages/Message.d.ts +3 -2
- package/lib/types/containers/Messages/Message.d.ts.map +1 -1
- package/lib/types/containers/Messages/MessageExample.d.ts +5 -4
- package/lib/types/containers/Messages/MessageExample.d.ts.map +1 -1
- package/lib/types/containers/Messages/Messages.d.ts.map +1 -1
- package/lib/types/containers/Operations/Operation.d.ts +4 -3
- package/lib/types/containers/Operations/Operation.d.ts.map +1 -1
- package/lib/types/containers/Operations/Operations.d.ts.map +1 -1
- package/lib/types/containers/Schemas/Schema.d.ts +9 -0
- package/lib/types/containers/Schemas/Schema.d.ts.map +1 -0
- package/lib/types/containers/Schemas/Schemas.d.ts +3 -0
- package/lib/types/containers/Schemas/Schemas.d.ts.map +1 -0
- package/lib/types/containers/Servers/Security.d.ts +10 -0
- package/lib/types/containers/Servers/Security.d.ts.map +1 -0
- package/lib/types/containers/Servers/Server.d.ts +2 -2
- package/lib/types/containers/Servers/Server.d.ts.map +1 -1
- package/lib/types/containers/Servers/Servers.d.ts.map +1 -1
- package/lib/types/containers/Sidebar/Sidebar.d.ts +1 -9
- package/lib/types/containers/Sidebar/Sidebar.d.ts.map +1 -1
- package/lib/types/contexts/index.d.ts +1 -0
- package/lib/types/contexts/index.d.ts.map +1 -1
- package/lib/types/contexts/useConfig.d.ts +5 -0
- package/lib/types/contexts/useConfig.d.ts.map +1 -0
- package/lib/types/contexts/useSpec.d.ts +3 -5
- package/lib/types/contexts/useSpec.d.ts.map +1 -1
- package/lib/types/helpers/bindingsHelpers.d.ts +8 -0
- package/lib/types/helpers/bindingsHelpers.d.ts.map +1 -0
- package/lib/types/helpers/common.d.ts +5 -0
- package/lib/types/helpers/common.d.ts.map +1 -0
- package/lib/types/helpers/index.d.ts +1 -2
- package/lib/types/helpers/index.d.ts.map +1 -1
- package/lib/types/helpers/message.d.ts +4 -3
- package/lib/types/helpers/message.d.ts.map +1 -1
- package/lib/types/helpers/parser.d.ts.map +1 -1
- package/lib/types/helpers/schema.d.ts +16 -12
- package/lib/types/helpers/schema.d.ts.map +1 -1
- package/lib/types/helpers/server.d.ts +6 -1
- package/lib/types/helpers/server.d.ts.map +1 -1
- package/lib/types/helpers/specification.d.ts +7 -4
- package/lib/types/helpers/specification.d.ts.map +1 -1
- package/lib/types/types.d.ts +12 -305
- package/lib/types/types.d.ts.map +1 -1
- package/package.json +30 -17
- package/styles/default.css +752 -658
- package/styles/default.min.css +3 -3
- package/lib/cjs/containers/Servers/ServerSecurity.js +0 -101
- package/lib/cjs/containers/Servers/ServerSecurity.js.map +0 -1
- package/lib/cjs/helpers/bemClasses.js +0 -49
- package/lib/cjs/helpers/bemClasses.js.map +0 -1
- package/lib/cjs/helpers/toKebabCase.js +0 -15
- package/lib/cjs/helpers/toKebabCase.js.map +0 -1
- package/lib/esm/containers/Servers/ServerSecurity.js +0 -95
- package/lib/esm/containers/Servers/ServerSecurity.js.map +0 -1
- package/lib/esm/helpers/bemClasses.js +0 -46
- package/lib/esm/helpers/bemClasses.js.map +0 -1
- package/lib/esm/helpers/toKebabCase.js +0 -11
- package/lib/esm/helpers/toKebabCase.js.map +0 -1
- package/lib/types/containers/Servers/ServerSecurity.d.ts +0 -8
- package/lib/types/containers/Servers/ServerSecurity.d.ts.map +0 -1
- package/lib/types/helpers/bemClasses.d.ts +0 -14
- package/lib/types/helpers/bemClasses.d.ts.map +0 -1
- package/lib/types/helpers/toKebabCase.d.ts +0 -2
- package/lib/types/helpers/toKebabCase.d.ts.map +0 -1
|
@@ -26,24 +26,54 @@ var MessageHelpers = (function () {
|
|
|
26
26
|
return schema;
|
|
27
27
|
};
|
|
28
28
|
MessageHelpers.getPayloadExamples = function (msg) {
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
var _a;
|
|
30
|
+
var examples = msg.examples().all();
|
|
31
|
+
if (examples.some(function (e) { return e.hasPayload(); })) {
|
|
32
|
+
var messageExamples = examples
|
|
33
|
+
.flatMap(function (e) {
|
|
34
|
+
if (!e.payload()) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
name: e.name(),
|
|
39
|
+
summary: e.summary(),
|
|
40
|
+
example: e.payload(),
|
|
41
|
+
};
|
|
42
|
+
})
|
|
43
|
+
.filter(Boolean);
|
|
44
|
+
if (messageExamples.length > 0) {
|
|
45
|
+
return messageExamples;
|
|
46
|
+
}
|
|
32
47
|
}
|
|
33
48
|
var payload = msg.payload();
|
|
34
49
|
if (payload && payload.examples()) {
|
|
35
|
-
return payload.examples();
|
|
50
|
+
return (_a = payload.examples()) === null || _a === void 0 ? void 0 : _a.map(function (example) { return ({ example: example }); });
|
|
36
51
|
}
|
|
37
52
|
return;
|
|
38
53
|
};
|
|
39
54
|
MessageHelpers.getHeadersExamples = function (msg) {
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
55
|
+
var _a;
|
|
56
|
+
var examples = msg.examples().all();
|
|
57
|
+
if (examples.some(function (e) { return e.hasHeaders(); })) {
|
|
58
|
+
var messageExamples = examples
|
|
59
|
+
.flatMap(function (e) {
|
|
60
|
+
if (!e.hasHeaders()) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
name: e.name(),
|
|
65
|
+
summary: e.summary(),
|
|
66
|
+
example: e.headers(),
|
|
67
|
+
};
|
|
68
|
+
})
|
|
69
|
+
.filter(Boolean);
|
|
70
|
+
if (messageExamples.length > 0) {
|
|
71
|
+
return messageExamples;
|
|
72
|
+
}
|
|
43
73
|
}
|
|
44
74
|
var headers = msg.headers();
|
|
45
75
|
if (headers && headers.examples()) {
|
|
46
|
-
return headers.examples();
|
|
76
|
+
return (_a = headers.examples()) === null || _a === void 0 ? void 0 : _a.map(function (example) { return ({ example: example }); });
|
|
47
77
|
}
|
|
48
78
|
return;
|
|
49
79
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/helpers/message.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/helpers/message.ts"],"names":[],"mappings":"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","sourcesContent":["import { MessageInterface } from '@asyncapi/parser';\n// @ts-ignore\nimport { sample } from 'openapi-sampler';\n\nimport { MessageExample } from '../types';\n\nexport class MessageHelpers {\n static generateExample(schema: any, options: any = {}) {\n try {\n return this.sanitizeExample(sample(schema, options)) || '';\n } catch (e) {\n return '';\n }\n }\n\n static sanitizeExample(schema: any): any {\n if (typeof schema === 'object' && schema && !Array.isArray(schema)) {\n return Object.entries(schema).reduce((obj, [propertyName, property]) => {\n if (\n !propertyName.startsWith('x-parser-') &&\n !propertyName.startsWith('x-schema-private-')\n ) {\n obj[propertyName] = this.sanitizeExample(property);\n }\n return obj;\n }, {});\n }\n return schema;\n }\n\n static getPayloadExamples(\n msg: MessageInterface,\n ): MessageExample[] | undefined {\n const examples = msg.examples().all();\n\n if (examples.some(e => e.hasPayload())) {\n const messageExamples = examples\n .flatMap(e => {\n if (!e.payload()) {\n return;\n }\n return {\n name: e.name(),\n summary: e.summary(),\n example: e.payload(),\n };\n })\n .filter(Boolean) as MessageExample[];\n\n if (messageExamples.length > 0) {\n return messageExamples;\n }\n }\n\n const payload = msg.payload();\n if (payload && payload.examples()) {\n return payload.examples()?.map(example => ({ example }));\n }\n\n return;\n }\n\n static getHeadersExamples(\n msg: MessageInterface,\n ): MessageExample[] | undefined {\n const examples = msg.examples().all();\n if (examples.some(e => e.hasHeaders())) {\n const messageExamples = examples\n .flatMap(e => {\n if (!e.hasHeaders()) {\n return;\n }\n return {\n name: e.name(),\n summary: e.summary(),\n example: e.headers(),\n };\n })\n .filter(Boolean) as MessageExample[];\n\n if (messageExamples.length > 0) {\n return messageExamples;\n }\n }\n\n const headers = msg.headers();\n if (headers && headers.examples()) {\n return headers.examples()?.map(example => ({ example }));\n }\n\n return;\n }\n}\n"]}
|
|
@@ -34,26 +34,29 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
import {
|
|
38
|
-
import
|
|
39
|
-
import
|
|
37
|
+
import { Parser as AsyncapiParser, fromURL } from '@asyncapi/parser';
|
|
38
|
+
import { OpenAPISchemaParser } from '@asyncapi/openapi-schema-parser';
|
|
39
|
+
import { ProtoBuffSchemaParser } from '@asyncapi/protobuf-schema-parser';
|
|
40
|
+
import { AvroSchemaParser } from '@asyncapi/avro-schema-parser';
|
|
40
41
|
import { VALIDATION_ERRORS_TYPE } from '../constants';
|
|
41
|
-
|
|
42
|
-
registerSchemaParser(
|
|
42
|
+
var asyncapiParser = new AsyncapiParser();
|
|
43
|
+
asyncapiParser.registerSchemaParser(OpenAPISchemaParser());
|
|
44
|
+
asyncapiParser.registerSchemaParser(AvroSchemaParser());
|
|
45
|
+
asyncapiParser.registerSchemaParser(ProtoBuffSchemaParser());
|
|
43
46
|
var Parser = (function () {
|
|
44
47
|
function Parser() {
|
|
45
48
|
}
|
|
46
49
|
Parser.parse = function (content, parserOptions) {
|
|
47
50
|
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var
|
|
51
|
+
var document_1, err_1;
|
|
49
52
|
return __generator(this, function (_a) {
|
|
50
53
|
switch (_a.label) {
|
|
51
54
|
case 0:
|
|
52
55
|
_a.trys.push([0, 2, , 3]);
|
|
53
|
-
return [4, parse(content, parserOptions)];
|
|
56
|
+
return [4, asyncapiParser.parse(content, parserOptions)];
|
|
54
57
|
case 1:
|
|
55
|
-
|
|
56
|
-
return [2, { asyncapi:
|
|
58
|
+
document_1 = (_a.sent()).document;
|
|
59
|
+
return [2, { asyncapi: document_1 }];
|
|
57
60
|
case 2:
|
|
58
61
|
err_1 = _a.sent();
|
|
59
62
|
return [2, this.handleError(err_1)];
|
|
@@ -64,15 +67,16 @@ var Parser = (function () {
|
|
|
64
67
|
};
|
|
65
68
|
Parser.parseFromUrl = function (arg, parserOptions) {
|
|
66
69
|
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
-
var
|
|
70
|
+
var fromResult, document_2, err_2;
|
|
68
71
|
return __generator(this, function (_a) {
|
|
69
72
|
switch (_a.label) {
|
|
70
73
|
case 0:
|
|
71
74
|
_a.trys.push([0, 2, , 3]);
|
|
72
|
-
|
|
75
|
+
fromResult = fromURL(asyncapiParser, arg.url, arg.requestOptions);
|
|
76
|
+
return [4, fromResult.parse(parserOptions)];
|
|
73
77
|
case 1:
|
|
74
|
-
|
|
75
|
-
return [2, { asyncapi:
|
|
78
|
+
document_2 = (_a.sent()).document;
|
|
79
|
+
return [2, { asyncapi: document_2 }];
|
|
76
80
|
case 2:
|
|
77
81
|
err_2 = _a.sent();
|
|
78
82
|
return [2, this.handleError(err_2)];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/helpers/parser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/helpers/parser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAIhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,IAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC;AAC5C,cAAc,CAAC,oBAAoB,CAAC,mBAAmB,EAAE,CAAC,CAAC;AAC3D,cAAc,CAAC,oBAAoB,CAAC,gBAAgB,EAAE,CAAC,CAAC;AACxD,cAAc,CAAC,oBAAoB,CAAC,qBAAqB,EAAE,CAAC,CAAC;AAE7D;IAAA;IAsCA,CAAC;IArCc,YAAK,GAAlB,UACE,OAAqB,EACrB,aAAmB;;;;;;;wBAGI,WAAM,cAAc,CAAC,KAAK,CAAC,OAAO,EAAE,aAAa,CAAC,EAAA;;wBAA/D,aAAa,CAAA,SAAkD,CAAA,SAAvD;wBAChB,WAAO,EAAE,QAAQ,EAAE,UAAQ,EAAE,EAAC;;;wBAE9B,WAAO,IAAI,CAAC,WAAW,CAAC,KAAkB,CAAC,EAAC;;;;;KAE/C;IAEY,mBAAY,GAAzB,UACE,GAA4B,EAC5B,aAAmB;;;;;;;wBAGX,UAAU,GAAG,OAAO,CACxB,cAAc,EACd,GAAG,CAAC,GAAG,EACP,GAAG,CAAC,cAAqB,CAC1B,CAAC;wBACmB,WAAM,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC,EAAA;;wBAAlD,aAAa,CAAA,SAAqC,CAAA,SAA1C;wBAChB,WAAO,EAAE,QAAQ,EAAE,UAAQ,EAAE,EAAC;;;wBAE9B,WAAO,IAAI,CAAC,WAAW,CAAC,KAAkB,CAAC,EAAC;;;;;KAE/C;IAEc,kBAAW,GAAG,UAAC,GAAgB;QAC5C,IAAI,GAAG,CAAC,IAAI,KAAK,sBAAsB,EAAE;YACvC,OAAO;gBACL,KAAK,EAAE,GAAG;aACX,CAAC;SACH;QACD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IACxB,CAAC,CAAC;IACJ,aAAC;CAAA,AAtCD,IAsCC;SAtCY,MAAM","sourcesContent":["import { Parser as AsyncapiParser, fromURL } from '@asyncapi/parser';\nimport { OpenAPISchemaParser } from '@asyncapi/openapi-schema-parser';\nimport { ProtoBuffSchemaParser } from '@asyncapi/protobuf-schema-parser';\nimport { AvroSchemaParser } from '@asyncapi/avro-schema-parser';\n\nimport { ErrorObject, ParserReturn, FetchingSchemaInterface } from '../types';\n\nimport { VALIDATION_ERRORS_TYPE } from '../constants';\n\nconst asyncapiParser = new AsyncapiParser();\nasyncapiParser.registerSchemaParser(OpenAPISchemaParser());\nasyncapiParser.registerSchemaParser(AvroSchemaParser());\nasyncapiParser.registerSchemaParser(ProtoBuffSchemaParser());\n\nexport class Parser {\n static async parse(\n content: string | any,\n parserOptions?: any,\n ): Promise<ParserReturn> {\n try {\n const { document } = await asyncapiParser.parse(content, parserOptions);\n return { asyncapi: document };\n } catch (err) {\n return this.handleError(err as ErrorObject);\n }\n }\n\n static async parseFromUrl(\n arg: FetchingSchemaInterface,\n parserOptions?: any,\n ): Promise<ParserReturn> {\n try {\n const fromResult = fromURL(\n asyncapiParser,\n arg.url,\n arg.requestOptions as any,\n );\n const { document } = await fromResult.parse(parserOptions);\n return { asyncapi: document };\n } catch (err) {\n return this.handleError(err as ErrorObject);\n }\n }\n\n private static handleError = (err: ErrorObject): ParserReturn => {\n if (err.type === VALIDATION_ERRORS_TYPE) {\n return {\n error: err,\n };\n }\n return { error: err };\n };\n}\n"]}
|
|
@@ -1,17 +1,80 @@
|
|
|
1
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { SchemaV2 as SchemaClass, } from '@asyncapi/parser';
|
|
13
|
+
export var SchemaCustomTypes;
|
|
14
|
+
(function (SchemaCustomTypes) {
|
|
15
|
+
SchemaCustomTypes["ANY"] = "any";
|
|
16
|
+
SchemaCustomTypes["RESTRICTED_ANY"] = "restricted any";
|
|
17
|
+
SchemaCustomTypes["NEVER"] = "never";
|
|
18
|
+
SchemaCustomTypes["UNKNOWN"] = "unknown";
|
|
19
|
+
})(SchemaCustomTypes || (SchemaCustomTypes = {}));
|
|
20
|
+
var jsonSchemaTypes = [
|
|
21
|
+
'string',
|
|
22
|
+
'number',
|
|
23
|
+
'integer',
|
|
24
|
+
'boolean',
|
|
25
|
+
'array',
|
|
26
|
+
'object',
|
|
27
|
+
'null',
|
|
28
|
+
];
|
|
29
|
+
var jsonSchemaKeywordTypes = {
|
|
30
|
+
maxLength: 'string',
|
|
31
|
+
minLength: 'string',
|
|
32
|
+
pattern: 'string',
|
|
33
|
+
contentMediaType: 'string',
|
|
34
|
+
contentEncoding: 'string',
|
|
35
|
+
multipleOf: 'number',
|
|
36
|
+
maximum: 'number',
|
|
37
|
+
exclusiveMaximum: 'number',
|
|
38
|
+
minimum: 'number',
|
|
39
|
+
exclusiveMinimum: 'number',
|
|
40
|
+
items: 'array',
|
|
41
|
+
maxItems: 'array',
|
|
42
|
+
minItems: 'array',
|
|
43
|
+
uniqueItems: 'array',
|
|
44
|
+
contains: 'array',
|
|
45
|
+
additionalItems: 'array',
|
|
46
|
+
maxProperties: 'object',
|
|
47
|
+
minProperties: 'object',
|
|
48
|
+
required: 'object',
|
|
49
|
+
properties: 'object',
|
|
50
|
+
patternProperties: 'object',
|
|
51
|
+
propertyNames: 'object',
|
|
52
|
+
dependencies: 'object',
|
|
53
|
+
additionalProperties: 'object',
|
|
54
|
+
};
|
|
55
|
+
var jsonSchemaKeywords = Object.keys(jsonSchemaKeywordTypes);
|
|
2
56
|
var SchemaHelpers = (function () {
|
|
3
57
|
function SchemaHelpers() {
|
|
4
58
|
}
|
|
5
59
|
SchemaHelpers.toSchemaType = function (schema) {
|
|
6
60
|
var _this = this;
|
|
7
|
-
if (schema
|
|
8
|
-
return
|
|
61
|
+
if (!schema || typeof schema.json !== 'function') {
|
|
62
|
+
return SchemaCustomTypes.UNKNOWN;
|
|
9
63
|
}
|
|
10
|
-
if (schema
|
|
11
|
-
|
|
64
|
+
if (schema.isBooleanSchema()) {
|
|
65
|
+
if (schema.json() === true) {
|
|
66
|
+
return SchemaCustomTypes.ANY;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return SchemaCustomTypes.NEVER;
|
|
70
|
+
}
|
|
12
71
|
}
|
|
13
72
|
if (Object.keys(schema.json()).length === 0) {
|
|
14
|
-
return
|
|
73
|
+
return SchemaCustomTypes.ANY;
|
|
74
|
+
}
|
|
75
|
+
var not = schema.not();
|
|
76
|
+
if (not && this.inferType(not) === SchemaCustomTypes.ANY) {
|
|
77
|
+
return SchemaCustomTypes.NEVER;
|
|
15
78
|
}
|
|
16
79
|
var type = this.inferType(schema);
|
|
17
80
|
if (Array.isArray(type)) {
|
|
@@ -20,23 +83,24 @@ var SchemaHelpers = (function () {
|
|
|
20
83
|
type = this.toType(type, schema);
|
|
21
84
|
var combinedType = this.toCombinedType(schema);
|
|
22
85
|
if (type && combinedType) {
|
|
23
|
-
return type
|
|
86
|
+
return "".concat(type, " ").concat(combinedType);
|
|
24
87
|
}
|
|
25
88
|
if (combinedType) {
|
|
26
89
|
return combinedType;
|
|
27
90
|
}
|
|
28
91
|
return type;
|
|
29
92
|
};
|
|
30
|
-
SchemaHelpers.prettifyValue = function (value) {
|
|
93
|
+
SchemaHelpers.prettifyValue = function (value, strict) {
|
|
94
|
+
if (strict === void 0) { strict = true; }
|
|
31
95
|
var typeOf = typeof value;
|
|
32
96
|
if (typeOf === 'string') {
|
|
33
|
-
return "\""
|
|
97
|
+
return strict ? "\"".concat(value, "\"") : value;
|
|
34
98
|
}
|
|
35
99
|
if (typeOf === 'number' || typeOf === 'bigint' || typeOf === 'boolean') {
|
|
36
|
-
return value;
|
|
100
|
+
return "".concat(value);
|
|
37
101
|
}
|
|
38
102
|
if (Array.isArray(value)) {
|
|
39
|
-
return "["
|
|
103
|
+
return "[".concat(value.toString(), "]");
|
|
40
104
|
}
|
|
41
105
|
return JSON.stringify(value);
|
|
42
106
|
};
|
|
@@ -74,6 +138,8 @@ var SchemaHelpers = (function () {
|
|
|
74
138
|
if (schema.oneOf() ||
|
|
75
139
|
schema.anyOf() ||
|
|
76
140
|
schema.allOf() ||
|
|
141
|
+
Object.keys(schema.properties() || {}).length > 0 ||
|
|
142
|
+
schema.items() ||
|
|
77
143
|
schema.not() ||
|
|
78
144
|
schema.if() ||
|
|
79
145
|
schema.then() ||
|
|
@@ -88,20 +154,19 @@ var SchemaHelpers = (function () {
|
|
|
88
154
|
};
|
|
89
155
|
SchemaHelpers.serverVariablesToSchema = function (urlVariables) {
|
|
90
156
|
var _a;
|
|
91
|
-
if (!urlVariables ||
|
|
157
|
+
if (!urlVariables || urlVariables.length === 0) {
|
|
92
158
|
return undefined;
|
|
93
159
|
}
|
|
160
|
+
var obj = {};
|
|
161
|
+
urlVariables.all().forEach(function (variable) {
|
|
162
|
+
obj[variable.id()] = __assign({}, (variable.json() || {}));
|
|
163
|
+
obj[variable.id()].type = 'string';
|
|
164
|
+
});
|
|
94
165
|
var json = (_a = {
|
|
95
166
|
type: 'object',
|
|
96
|
-
properties:
|
|
97
|
-
|
|
98
|
-
obj[urlName] = Object.assign({}, url.json());
|
|
99
|
-
obj[urlName].type = 'string';
|
|
100
|
-
return obj;
|
|
101
|
-
}, {}),
|
|
102
|
-
required: Object.keys(urlVariables)
|
|
167
|
+
properties: obj,
|
|
168
|
+
required: Object.keys(obj)
|
|
103
169
|
},
|
|
104
|
-
_a[this.extRenderType] = false,
|
|
105
170
|
_a[this.extRenderAdditionalInfo] = false,
|
|
106
171
|
_a);
|
|
107
172
|
return new SchemaClass(json);
|
|
@@ -109,22 +174,26 @@ var SchemaHelpers = (function () {
|
|
|
109
174
|
SchemaHelpers.parametersToSchema = function (parameters) {
|
|
110
175
|
var _a;
|
|
111
176
|
var _this = this;
|
|
112
|
-
if (!parameters ||
|
|
177
|
+
if (!parameters || parameters.isEmpty()) {
|
|
113
178
|
return undefined;
|
|
114
179
|
}
|
|
180
|
+
var obj = {};
|
|
181
|
+
parameters.all().forEach(function (parameter) {
|
|
182
|
+
var _a;
|
|
183
|
+
var parameterSchema = parameter.schema();
|
|
184
|
+
obj[parameter.id()] = __assign({}, ((_a = parameterSchema === null || parameterSchema === void 0 ? void 0 : parameterSchema.json()) !== null && _a !== void 0 ? _a : {}));
|
|
185
|
+
obj[parameter.id()].description = parameter.hasDescription()
|
|
186
|
+
? parameter.description()
|
|
187
|
+
: undefined;
|
|
188
|
+
obj[parameter.id()][_this.extParameterLocation] = parameter.hasLocation()
|
|
189
|
+
? parameter.location()
|
|
190
|
+
: undefined;
|
|
191
|
+
});
|
|
115
192
|
var json = (_a = {
|
|
116
193
|
type: 'object',
|
|
117
|
-
properties:
|
|
118
|
-
|
|
119
|
-
obj[paramaterName] = Object.assign({}, parameter.schema().json());
|
|
120
|
-
obj[paramaterName].description =
|
|
121
|
-
parameter.description() || obj[paramaterName].description;
|
|
122
|
-
obj[paramaterName][_this.extParameterLocation] = parameter.location();
|
|
123
|
-
return obj;
|
|
124
|
-
}, {}),
|
|
125
|
-
required: Object.keys(parameters)
|
|
194
|
+
properties: obj,
|
|
195
|
+
required: Object.keys(obj)
|
|
126
196
|
},
|
|
127
|
-
_a[this.extRenderType] = false,
|
|
128
197
|
_a[this.extRenderAdditionalInfo] = false,
|
|
129
198
|
_a);
|
|
130
199
|
return new SchemaClass(json);
|
|
@@ -137,14 +206,17 @@ var SchemaHelpers = (function () {
|
|
|
137
206
|
if (!value || typeof value.extensions !== 'function') {
|
|
138
207
|
return;
|
|
139
208
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
209
|
+
var extensions = value.extensions();
|
|
210
|
+
var filteredExtensions = {};
|
|
211
|
+
for (var _i = 0, _a = extensions.all(); _i < _a.length; _i++) {
|
|
212
|
+
var ext = _a[_i];
|
|
213
|
+
var extType = ext;
|
|
214
|
+
if (!extType.id().startsWith('x-parser-') &&
|
|
215
|
+
!extType.id().startsWith('x-schema-private-')) {
|
|
216
|
+
filteredExtensions[extType.id()] = extType.value();
|
|
145
217
|
}
|
|
146
|
-
|
|
147
|
-
|
|
218
|
+
}
|
|
219
|
+
return filteredExtensions;
|
|
148
220
|
};
|
|
149
221
|
SchemaHelpers.getDependentRequired = function (propertyName, schema) {
|
|
150
222
|
var dependentRequired = [];
|
|
@@ -180,34 +252,46 @@ var SchemaHelpers = (function () {
|
|
|
180
252
|
type: 'object',
|
|
181
253
|
properties: Object.entries(records).reduce(function (obj, _a) {
|
|
182
254
|
var propertyName = _a[0], propertySchema = _a[1];
|
|
183
|
-
obj[propertyName] =
|
|
255
|
+
obj[propertyName] = __assign({}, (propertySchema.json() || {}));
|
|
184
256
|
return obj;
|
|
185
257
|
}, {})
|
|
186
258
|
},
|
|
187
|
-
_a[this.extRenderType] = false,
|
|
188
259
|
_a[this.extRenderAdditionalInfo] = false,
|
|
189
260
|
_a);
|
|
190
261
|
return new SchemaClass(json);
|
|
191
262
|
};
|
|
192
263
|
SchemaHelpers.toType = function (type, schema) {
|
|
193
|
-
|
|
264
|
+
if (schema.isCircular()) {
|
|
265
|
+
return type;
|
|
266
|
+
}
|
|
194
267
|
if (type === 'array') {
|
|
195
268
|
var items = schema.items();
|
|
196
|
-
var types = void 0;
|
|
197
269
|
if (Array.isArray(items)) {
|
|
198
|
-
|
|
199
|
-
types = types.length ? types : 'unknown';
|
|
270
|
+
return this.toItemsType(items, schema);
|
|
200
271
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
types = types || 'unknown';
|
|
272
|
+
if (!items) {
|
|
273
|
+
return "array<".concat(SchemaCustomTypes.ANY, ">");
|
|
204
274
|
}
|
|
205
|
-
return "array<"
|
|
275
|
+
return "array<".concat(this.toSchemaType(items) || SchemaCustomTypes.UNKNOWN, ">");
|
|
206
276
|
}
|
|
207
277
|
return type;
|
|
208
278
|
};
|
|
279
|
+
SchemaHelpers.toItemsType = function (items, schema) {
|
|
280
|
+
var _this = this;
|
|
281
|
+
var types = items.map(function (item) { return _this.toSchemaType(item); }).join(', ');
|
|
282
|
+
var additionalItems = schema.additionalItems();
|
|
283
|
+
if (additionalItems !== undefined && additionalItems !== false) {
|
|
284
|
+
var additionalType = additionalItems === true
|
|
285
|
+
? SchemaCustomTypes.ANY
|
|
286
|
+
: this.toSchemaType(additionalItems);
|
|
287
|
+
return "tuple<".concat(types ||
|
|
288
|
+
SchemaCustomTypes.UNKNOWN, ", ...optional<").concat(additionalType, ">>");
|
|
289
|
+
}
|
|
290
|
+
return "tuple<".concat(types || SchemaCustomTypes.UNKNOWN, ">");
|
|
291
|
+
};
|
|
209
292
|
SchemaHelpers.toCombinedType = function (schema) {
|
|
210
|
-
|
|
293
|
+
var oneOf = schema.oneOf();
|
|
294
|
+
if (oneOf) {
|
|
211
295
|
return 'oneOf';
|
|
212
296
|
}
|
|
213
297
|
if (schema.anyOf()) {
|
|
@@ -219,49 +303,36 @@ var SchemaHelpers = (function () {
|
|
|
219
303
|
return;
|
|
220
304
|
};
|
|
221
305
|
SchemaHelpers.inferType = function (schema) {
|
|
222
|
-
var
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if (jsonTypes !== undefined) {
|
|
228
|
-
if (Array.isArray(jsonTypes)) {
|
|
229
|
-
for (var i = 0, l = jsonTypes.length; i < l; i++) {
|
|
230
|
-
possibleTypes[jsonTypes[i]] = undefined;
|
|
306
|
+
var types = schema.type();
|
|
307
|
+
if (types !== undefined) {
|
|
308
|
+
if (Array.isArray(types)) {
|
|
309
|
+
if (types.includes('integer') && types.includes('number')) {
|
|
310
|
+
types = types.filter(function (t) { return t !== 'integer'; });
|
|
231
311
|
}
|
|
312
|
+
return types.length === 1 ? types[0] : types;
|
|
232
313
|
}
|
|
233
|
-
|
|
234
|
-
possibleTypes[jsonTypes] = undefined;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
for (var i = 0; i < keywordsLength; i++) {
|
|
238
|
-
var keyword = keywords[i];
|
|
239
|
-
if (jsonSchema[keyword] !== undefined) {
|
|
240
|
-
possibleTypes[this.jsonSchemaKeywordTypes[keyword]] = undefined;
|
|
241
|
-
}
|
|
314
|
+
return types;
|
|
242
315
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
possibleTypes[typeof value] = undefined;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
var types = Object.keys(possibleTypes);
|
|
250
|
-
if (types.length === 1) {
|
|
251
|
-
return types[0];
|
|
316
|
+
var constValue = schema.const();
|
|
317
|
+
if (constValue !== undefined) {
|
|
318
|
+
return typeof constValue;
|
|
252
319
|
}
|
|
253
|
-
|
|
254
|
-
|
|
320
|
+
var enumValue = schema.enum();
|
|
321
|
+
if (Array.isArray(enumValue) && enumValue.length) {
|
|
322
|
+
var inferredType = Array.from(new Set(enumValue.map(function (e) { return typeof e; })));
|
|
323
|
+
return inferredType.length === 1 ? inferredType[0] : inferredType;
|
|
255
324
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
325
|
+
var schemaKeys = Object.keys(schema.json() || {}) || [];
|
|
326
|
+
var hasInferredTypes = jsonSchemaKeywords.some(function (key) {
|
|
327
|
+
return schemaKeys.includes(key);
|
|
328
|
+
});
|
|
329
|
+
if (hasInferredTypes === true) {
|
|
330
|
+
return SchemaCustomTypes.RESTRICTED_ANY;
|
|
260
331
|
}
|
|
261
|
-
if (
|
|
262
|
-
return
|
|
332
|
+
if (this.toCombinedType(schema)) {
|
|
333
|
+
return '';
|
|
263
334
|
}
|
|
264
|
-
return
|
|
335
|
+
return SchemaCustomTypes.ANY;
|
|
265
336
|
};
|
|
266
337
|
SchemaHelpers.humanizeNumberRangeConstraint = function (min, exclusiveMin, max, exclusiveMax) {
|
|
267
338
|
var hasExclusiveMin = exclusiveMin !== undefined;
|
|
@@ -292,58 +363,65 @@ var SchemaHelpers = (function () {
|
|
|
292
363
|
}
|
|
293
364
|
var strigifiedMultipleOf = multipleOf.toString(10);
|
|
294
365
|
if (!/^0\.0*1$/.test(strigifiedMultipleOf)) {
|
|
295
|
-
return "multiple of "
|
|
366
|
+
return "multiple of ".concat(strigifiedMultipleOf);
|
|
296
367
|
}
|
|
297
|
-
return "decimal places <= "
|
|
368
|
+
return "decimal places <= ".concat(strigifiedMultipleOf.split('.')[1].length);
|
|
298
369
|
};
|
|
299
370
|
SchemaHelpers.humanizeRangeConstraint = function (description, min, max) {
|
|
300
371
|
var stringRange;
|
|
301
372
|
if (min !== undefined && max !== undefined) {
|
|
302
373
|
if (min === max) {
|
|
303
|
-
stringRange = min
|
|
374
|
+
stringRange = "".concat(min, " ").concat(description);
|
|
304
375
|
}
|
|
305
376
|
else {
|
|
306
|
-
stringRange = "[ "
|
|
377
|
+
stringRange = "[ ".concat(min, " .. ").concat(max, " ] ").concat(description);
|
|
307
378
|
}
|
|
308
379
|
}
|
|
309
380
|
else if (max !== undefined) {
|
|
310
|
-
stringRange = "<= "
|
|
381
|
+
stringRange = "<= ".concat(max, " ").concat(description);
|
|
311
382
|
}
|
|
312
383
|
else if (min !== undefined) {
|
|
313
384
|
if (min === 1) {
|
|
314
385
|
stringRange = 'non-empty';
|
|
315
386
|
}
|
|
316
387
|
else {
|
|
317
|
-
stringRange = ">= "
|
|
388
|
+
stringRange = ">= ".concat(min, " ").concat(description);
|
|
318
389
|
}
|
|
319
390
|
}
|
|
320
391
|
return stringRange;
|
|
321
392
|
};
|
|
322
393
|
SchemaHelpers.jsonFieldToSchema = function (value) {
|
|
323
|
-
var _a, _b, _c;
|
|
394
|
+
var _a, _b, _c, _d;
|
|
324
395
|
var _this = this;
|
|
325
|
-
if (
|
|
326
|
-
var str = typeof value.toString === 'function' ? value.toString() : value;
|
|
396
|
+
if (value === undefined || value === null) {
|
|
327
397
|
return _a = {
|
|
328
398
|
type: 'string',
|
|
329
|
-
const:
|
|
399
|
+
const: ''
|
|
330
400
|
},
|
|
331
401
|
_a[this.extRawValue] = true,
|
|
332
402
|
_a;
|
|
333
403
|
}
|
|
404
|
+
if (typeof value !== 'object') {
|
|
405
|
+
var str = typeof value.toString === 'function' ? value.toString() : value;
|
|
406
|
+
return _b = {
|
|
407
|
+
type: 'string',
|
|
408
|
+
const: str
|
|
409
|
+
},
|
|
410
|
+
_b[this.extRawValue] = true,
|
|
411
|
+
_b;
|
|
412
|
+
}
|
|
334
413
|
if (this.isJSONSchema(value)) {
|
|
335
414
|
return value;
|
|
336
415
|
}
|
|
337
416
|
if (Array.isArray(value)) {
|
|
338
|
-
return
|
|
417
|
+
return _c = {
|
|
339
418
|
type: 'array',
|
|
340
419
|
items: value.map(function (v) { return _this.jsonFieldToSchema(v); })
|
|
341
420
|
},
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
_b;
|
|
421
|
+
_c[this.extRenderAdditionalInfo] = false,
|
|
422
|
+
_c;
|
|
345
423
|
}
|
|
346
|
-
return
|
|
424
|
+
return _d = {
|
|
347
425
|
type: 'object',
|
|
348
426
|
properties: Object.entries(value).reduce(function (obj, _a) {
|
|
349
427
|
var k = _a[0], v = _a[1];
|
|
@@ -351,60 +429,22 @@ var SchemaHelpers = (function () {
|
|
|
351
429
|
return obj;
|
|
352
430
|
}, {})
|
|
353
431
|
},
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
_c;
|
|
432
|
+
_d[this.extRenderAdditionalInfo] = false,
|
|
433
|
+
_d;
|
|
357
434
|
};
|
|
358
435
|
SchemaHelpers.isJSONSchema = function (value) {
|
|
359
|
-
var _this = this;
|
|
360
436
|
if (value &&
|
|
361
437
|
typeof value === 'object' &&
|
|
362
|
-
(
|
|
438
|
+
(jsonSchemaTypes.includes(value.type) ||
|
|
363
439
|
(Array.isArray(value.type) &&
|
|
364
|
-
value.type.some(function (t) { return !
|
|
440
|
+
value.type.some(function (t) { return !jsonSchemaTypes.includes(t); })))) {
|
|
365
441
|
return true;
|
|
366
442
|
}
|
|
367
443
|
return false;
|
|
368
444
|
};
|
|
369
|
-
SchemaHelpers.extRenderType = 'x-schema-private-render-type';
|
|
370
445
|
SchemaHelpers.extRenderAdditionalInfo = 'x-schema-private-render-additional-info';
|
|
371
446
|
SchemaHelpers.extRawValue = 'x-schema-private-raw-value';
|
|
372
447
|
SchemaHelpers.extParameterLocation = 'x-schema-private-parameter-location';
|
|
373
|
-
SchemaHelpers.jsonSchemaTypes = [
|
|
374
|
-
'string',
|
|
375
|
-
'number',
|
|
376
|
-
'integer',
|
|
377
|
-
'boolean',
|
|
378
|
-
'array',
|
|
379
|
-
'object',
|
|
380
|
-
'null',
|
|
381
|
-
];
|
|
382
|
-
SchemaHelpers.jsonSchemaKeywordTypes = {
|
|
383
|
-
maxLength: 'string',
|
|
384
|
-
minLength: 'string',
|
|
385
|
-
pattern: 'string',
|
|
386
|
-
contentMediaType: 'string',
|
|
387
|
-
contentEncoding: 'string',
|
|
388
|
-
multipleOf: 'number',
|
|
389
|
-
maximum: 'number',
|
|
390
|
-
exclusiveMaximum: 'number',
|
|
391
|
-
minimum: 'number',
|
|
392
|
-
exclusiveMinimum: 'number',
|
|
393
|
-
items: 'array',
|
|
394
|
-
maxItems: 'array',
|
|
395
|
-
minItems: 'array',
|
|
396
|
-
uniqueItems: 'array',
|
|
397
|
-
contains: 'array',
|
|
398
|
-
additionalItems: 'array',
|
|
399
|
-
maxProperties: 'object',
|
|
400
|
-
minProperties: 'object',
|
|
401
|
-
required: 'object',
|
|
402
|
-
properties: 'object',
|
|
403
|
-
patternProperties: 'object',
|
|
404
|
-
propertyNames: 'object',
|
|
405
|
-
dependencies: 'object',
|
|
406
|
-
additionalProperties: 'object',
|
|
407
|
-
};
|
|
408
448
|
return SchemaHelpers;
|
|
409
449
|
}());
|
|
410
450
|
export { SchemaHelpers };
|