@alagoni97/cli 0.72.1
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/LICENSE +201 -0
- package/README.md +336 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.mjs +3 -0
- package/bin/run.cmd +3 -0
- package/bin/run.mjs +4 -0
- package/dist/LoggingInterface.d.ts +123 -0
- package/dist/LoggingInterface.js +300 -0
- package/dist/PersistedConfig.d.ts +46 -0
- package/dist/PersistedConfig.js +94 -0
- package/dist/browser/adapters/output.d.ts +69 -0
- package/dist/browser/adapters/output.js +91 -0
- package/dist/browser/config.d.ts +18 -0
- package/dist/browser/config.js +59 -0
- package/dist/browser/generate.d.ts +20 -0
- package/dist/browser/generate.js +129 -0
- package/dist/browser/index.d.ts +17 -0
- package/dist/browser/index.js +26 -0
- package/dist/browser/parser.d.ts +9 -0
- package/dist/browser/parser.js +61 -0
- package/dist/browser/shims/asyncapi-parser.d.ts +30 -0
- package/dist/browser/shims/asyncapi-parser.js +52 -0
- package/dist/browser/shims/fs.d.ts +190 -0
- package/dist/browser/shims/fs.js +188 -0
- package/dist/browser/shims/json-schema-ref-parser.d.ts +73 -0
- package/dist/browser/shims/json-schema-ref-parser.js +246 -0
- package/dist/browser/shims/swagger-parser.d.ts +20 -0
- package/dist/browser/shims/swagger-parser.js +40 -0
- package/dist/codegen/configurationSchemaBuilder.d.ts +15 -0
- package/dist/codegen/configurationSchemaBuilder.js +48 -0
- package/dist/codegen/configurations.d.ts +29 -0
- package/dist/codegen/configurations.js +260 -0
- package/dist/codegen/detection.d.ts +19 -0
- package/dist/codegen/detection.js +174 -0
- package/dist/codegen/errors.d.ts +111 -0
- package/dist/codegen/errors.js +352 -0
- package/dist/codegen/generators/generic/custom.d.ts +75 -0
- package/dist/codegen/generators/generic/custom.js +66 -0
- package/dist/codegen/generators/index.d.ts +14 -0
- package/dist/codegen/generators/index.js +42 -0
- package/dist/codegen/generators/typescript/channels/asyncapi.d.ts +10 -0
- package/dist/codegen/generators/typescript/channels/asyncapi.js +131 -0
- package/dist/codegen/generators/typescript/channels/index.d.ts +8 -0
- package/dist/codegen/generators/typescript/channels/index.js +142 -0
- package/dist/codegen/generators/typescript/channels/openapi.d.ts +9 -0
- package/dist/codegen/generators/typescript/channels/openapi.js +168 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/index.d.ts +7 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/index.js +149 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishExchange.d.ts +5 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishExchange.js +106 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishQueue.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishQueue.js +102 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/subscribeQueue.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/subscribeQueue.js +133 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/express.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/express.js +100 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/fetch.d.ts +5 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/fetch.js +144 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/index.d.ts +6 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/index.js +132 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/client.d.ts +10 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/client.js +224 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/common-types.d.ts +14 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/common-types.js +800 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/index.d.ts +8 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/index.js +96 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/security.d.ts +48 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/security.js +491 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/index.d.ts +6 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/index.js +127 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/publish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/publish.js +108 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/subscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/subscribe.js +154 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/utils.d.ts +11 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/utils.js +58 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/index.d.ts +6 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/index.js +113 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/publish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/publish.js +99 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/subscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/subscribe.js +186 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/corePublish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/corePublish.js +90 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreReply.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreReply.js +142 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreRequest.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreRequest.js +100 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreSubscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreSubscribe.js +143 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/index.d.ts +11 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/index.js +224 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPublish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPublish.js +89 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPullSubscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPullSubscribe.js +146 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPushSubscription.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPushSubscription.js +149 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/utils.d.ts +35 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/utils.js +120 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/index.d.ts +7 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/index.js +152 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/publish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/publish.js +64 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/register.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/register.js +115 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/subscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/subscribe.js +151 -0
- package/dist/codegen/generators/typescript/channels/types.d.ts +181 -0
- package/dist/codegen/generators/typescript/channels/types.js +131 -0
- package/dist/codegen/generators/typescript/channels/utils.d.ts +64 -0
- package/dist/codegen/generators/typescript/channels/utils.js +163 -0
- package/dist/codegen/generators/typescript/client/index.d.ts +8 -0
- package/dist/codegen/generators/typescript/client/index.js +61 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/corePublish.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/corePublish.js +53 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/coreSubscribe.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/coreSubscribe.js +90 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetStreamPullSubscription.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetStreamPullSubscription.js +83 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPublish.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPublish.js +54 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPushSubscription.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPushSubscription.js +82 -0
- package/dist/codegen/generators/typescript/client/protocols/nats.d.ts +2 -0
- package/dist/codegen/generators/typescript/client/protocols/nats.js +182 -0
- package/dist/codegen/generators/typescript/client/types.d.ts +49 -0
- package/dist/codegen/generators/typescript/client/types.js +37 -0
- package/dist/codegen/generators/typescript/headers.d.ts +54 -0
- package/dist/codegen/generators/typescript/headers.js +138 -0
- package/dist/codegen/generators/typescript/index.d.ts +7 -0
- package/dist/codegen/generators/typescript/index.js +38 -0
- package/dist/codegen/generators/typescript/models.d.ts +21761 -0
- package/dist/codegen/generators/typescript/models.js +64 -0
- package/dist/codegen/generators/typescript/parameters.d.ts +37 -0
- package/dist/codegen/generators/typescript/parameters.js +101 -0
- package/dist/codegen/generators/typescript/payloads.d.ts +73 -0
- package/dist/codegen/generators/typescript/payloads.js +250 -0
- package/dist/codegen/generators/typescript/types.d.ts +34 -0
- package/dist/codegen/generators/typescript/types.js +70 -0
- package/dist/codegen/generators/typescript/utils.d.ts +38 -0
- package/dist/codegen/generators/typescript/utils.js +195 -0
- package/dist/codegen/index.d.ts +7 -0
- package/dist/codegen/index.js +38 -0
- package/dist/codegen/inputs/asyncapi/generators/headers.d.ts +3 -0
- package/dist/codegen/inputs/asyncapi/generators/headers.js +41 -0
- package/dist/codegen/inputs/asyncapi/generators/parameters.d.ts +14 -0
- package/dist/codegen/inputs/asyncapi/generators/parameters.js +120 -0
- package/dist/codegen/inputs/asyncapi/generators/payloads.d.ts +16 -0
- package/dist/codegen/inputs/asyncapi/generators/payloads.js +124 -0
- package/dist/codegen/inputs/asyncapi/generators/types.d.ts +9 -0
- package/dist/codegen/inputs/asyncapi/generators/types.js +61 -0
- package/dist/codegen/inputs/asyncapi/index.d.ts +1 -0
- package/dist/codegen/inputs/asyncapi/index.js +7 -0
- package/dist/codegen/inputs/asyncapi/parser.d.ts +4 -0
- package/dist/codegen/inputs/asyncapi/parser.js +90 -0
- package/dist/codegen/inputs/index.d.ts +3 -0
- package/dist/codegen/inputs/index.js +19 -0
- package/dist/codegen/inputs/jsonschema/generators/index.d.ts +1 -0
- package/dist/codegen/inputs/jsonschema/generators/index.js +5 -0
- package/dist/codegen/inputs/jsonschema/generators/models.d.ts +7 -0
- package/dist/codegen/inputs/jsonschema/generators/models.js +26 -0
- package/dist/codegen/inputs/jsonschema/index.d.ts +1 -0
- package/dist/codegen/inputs/jsonschema/index.js +7 -0
- package/dist/codegen/inputs/jsonschema/parser.d.ts +31 -0
- package/dist/codegen/inputs/jsonschema/parser.js +128 -0
- package/dist/codegen/inputs/openapi/generators/headers.d.ts +3 -0
- package/dist/codegen/inputs/openapi/generators/headers.js +101 -0
- package/dist/codegen/inputs/openapi/generators/parameters.d.ts +10 -0
- package/dist/codegen/inputs/openapi/generators/parameters.js +852 -0
- package/dist/codegen/inputs/openapi/generators/payloads.d.ts +3 -0
- package/dist/codegen/inputs/openapi/generators/payloads.js +231 -0
- package/dist/codegen/inputs/openapi/generators/types.d.ts +9 -0
- package/dist/codegen/inputs/openapi/generators/types.js +86 -0
- package/dist/codegen/inputs/openapi/index.d.ts +2 -0
- package/dist/codegen/inputs/openapi/index.js +8 -0
- package/dist/codegen/inputs/openapi/parser.d.ts +4 -0
- package/dist/codegen/inputs/openapi/parser.js +115 -0
- package/dist/codegen/inputs/openapi/security.d.ts +56 -0
- package/dist/codegen/inputs/openapi/security.js +193 -0
- package/dist/codegen/modelina/index.d.ts +2 -0
- package/dist/codegen/modelina/index.js +20 -0
- package/dist/codegen/modelina/presets/index.d.ts +3 -0
- package/dist/codegen/modelina/presets/index.js +14 -0
- package/dist/codegen/modelina/presets/primitives.d.ts +34 -0
- package/dist/codegen/modelina/presets/primitives.js +211 -0
- package/dist/codegen/modelina/presets/union.d.ts +33 -0
- package/dist/codegen/modelina/presets/union.js +197 -0
- package/dist/codegen/modelina/presets/validation.d.ts +66 -0
- package/dist/codegen/modelina/presets/validation.js +183 -0
- package/dist/codegen/modelina/types.d.ts +61845 -0
- package/dist/codegen/modelina/types.js +412 -0
- package/dist/codegen/output/filesystem.d.ts +30 -0
- package/dist/codegen/output/filesystem.js +61 -0
- package/dist/codegen/output/index.d.ts +16 -0
- package/dist/codegen/output/index.js +57 -0
- package/dist/codegen/output/memory.d.ts +54 -0
- package/dist/codegen/output/memory.js +81 -0
- package/dist/codegen/output/modelina.d.ts +30 -0
- package/dist/codegen/output/modelina.js +30 -0
- package/dist/codegen/output/types.d.ts +47 -0
- package/dist/codegen/output/types.js +6 -0
- package/dist/codegen/renderer.d.ts +13 -0
- package/dist/codegen/renderer.js +309 -0
- package/dist/codegen/schemaPostProcess.d.ts +25 -0
- package/dist/codegen/schemaPostProcess.js +38 -0
- package/dist/codegen/types.d.ts +285187 -0
- package/dist/codegen/types.js +177 -0
- package/dist/codegen/utils.d.ts +126 -0
- package/dist/codegen/utils.js +373 -0
- package/dist/commands/base.d.ts +18 -0
- package/dist/commands/base.js +59 -0
- package/dist/commands/generate.d.ts +46 -0
- package/dist/commands/generate.js +305 -0
- package/dist/commands/init.d.ts +55 -0
- package/dist/commands/init.js +544 -0
- package/dist/commands/telemetry.d.ts +25 -0
- package/dist/commands/telemetry.js +115 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +35 -0
- package/dist/telemetry/anonymize.d.ts +19 -0
- package/dist/telemetry/anonymize.js +73 -0
- package/dist/telemetry/collector.d.ts +26 -0
- package/dist/telemetry/collector.js +57 -0
- package/dist/telemetry/config.d.ts +32 -0
- package/dist/telemetry/config.js +97 -0
- package/dist/telemetry/events.d.ts +72 -0
- package/dist/telemetry/events.js +5 -0
- package/dist/telemetry/index.d.ts +46 -0
- package/dist/telemetry/index.js +91 -0
- package/dist/telemetry/notice.d.ts +8 -0
- package/dist/telemetry/notice.js +50 -0
- package/dist/telemetry/sender.d.ts +14 -0
- package/dist/telemetry/sender.js +125 -0
- package/dist/utils/gitignore.d.ts +66 -0
- package/dist/utils/gitignore.js +111 -0
- package/dist/utils/inputSource.d.ts +3 -0
- package/dist/utils/inputSource.js +26 -0
- package/dist/utils/refResolvers.d.ts +29 -0
- package/dist/utils/refResolvers.js +83 -0
- package/dist/utils/remoteFetch.d.ts +18 -0
- package/dist/utils/remoteFetch.js +64 -0
- package/oclif.manifest.json +510 -0
- package/package.json +155 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractSecuritySchemes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Extracts security schemes from an OpenAPI document.
|
|
6
|
+
* Handles both OpenAPI 3.x (components.securitySchemes) and
|
|
7
|
+
* Swagger 2.0 (securityDefinitions) formats.
|
|
8
|
+
*/
|
|
9
|
+
function extractSecuritySchemes(document) {
|
|
10
|
+
// Check if OpenAPI 3.x document
|
|
11
|
+
if ('openapi' in document) {
|
|
12
|
+
return extractOpenAPI3SecuritySchemes(document);
|
|
13
|
+
}
|
|
14
|
+
// Check if Swagger 2.0 document
|
|
15
|
+
if ('swagger' in document) {
|
|
16
|
+
return extractSwagger2SecuritySchemes(document);
|
|
17
|
+
}
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
exports.extractSecuritySchemes = extractSecuritySchemes;
|
|
21
|
+
/**
|
|
22
|
+
* Extracts security schemes from OpenAPI 3.x documents.
|
|
23
|
+
*/
|
|
24
|
+
function extractOpenAPI3SecuritySchemes(document) {
|
|
25
|
+
const securitySchemes = document.components?.securitySchemes;
|
|
26
|
+
if (!securitySchemes) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const schemes = [];
|
|
30
|
+
for (const [name, scheme] of Object.entries(securitySchemes)) {
|
|
31
|
+
// Skip $ref - should be dereferenced already
|
|
32
|
+
if ('$ref' in scheme) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const securityScheme = scheme;
|
|
36
|
+
const extracted = extractOpenAPI3Scheme(name, securityScheme);
|
|
37
|
+
if (extracted) {
|
|
38
|
+
schemes.push(extracted);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return schemes;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Extracts a single OpenAPI 3.x security scheme.
|
|
45
|
+
*/
|
|
46
|
+
function extractOpenAPI3Scheme(name, scheme) {
|
|
47
|
+
switch (scheme.type) {
|
|
48
|
+
case 'apiKey':
|
|
49
|
+
return {
|
|
50
|
+
name,
|
|
51
|
+
type: 'apiKey',
|
|
52
|
+
apiKeyName: scheme.name,
|
|
53
|
+
apiKeyIn: scheme.in
|
|
54
|
+
};
|
|
55
|
+
case 'http':
|
|
56
|
+
return {
|
|
57
|
+
name,
|
|
58
|
+
type: 'http',
|
|
59
|
+
httpScheme: scheme.scheme,
|
|
60
|
+
bearerFormat: scheme.bearerFormat
|
|
61
|
+
};
|
|
62
|
+
case 'oauth2':
|
|
63
|
+
return {
|
|
64
|
+
name,
|
|
65
|
+
type: 'oauth2',
|
|
66
|
+
oauth2Flows: extractOAuth2Flows(scheme.flows)
|
|
67
|
+
};
|
|
68
|
+
case 'openIdConnect':
|
|
69
|
+
return {
|
|
70
|
+
name,
|
|
71
|
+
type: 'openIdConnect',
|
|
72
|
+
openIdConnectUrl: scheme.openIdConnectUrl
|
|
73
|
+
};
|
|
74
|
+
default:
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Extracts OAuth2 flows from OpenAPI 3.x OAuth2 security scheme.
|
|
80
|
+
*/
|
|
81
|
+
function extractOAuth2Flows(flows) {
|
|
82
|
+
const result = {};
|
|
83
|
+
if (flows.implicit) {
|
|
84
|
+
result.implicit = {
|
|
85
|
+
authorizationUrl: flows.implicit.authorizationUrl,
|
|
86
|
+
scopes: flows.implicit.scopes || {}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (flows.password) {
|
|
90
|
+
result.password = {
|
|
91
|
+
tokenUrl: flows.password.tokenUrl,
|
|
92
|
+
scopes: flows.password.scopes || {}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (flows.clientCredentials) {
|
|
96
|
+
result.clientCredentials = {
|
|
97
|
+
tokenUrl: flows.clientCredentials.tokenUrl,
|
|
98
|
+
scopes: flows.clientCredentials.scopes || {}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (flows.authorizationCode) {
|
|
102
|
+
result.authorizationCode = {
|
|
103
|
+
authorizationUrl: flows.authorizationCode.authorizationUrl,
|
|
104
|
+
tokenUrl: flows.authorizationCode.tokenUrl,
|
|
105
|
+
scopes: flows.authorizationCode.scopes || {}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Extracts security definitions from Swagger 2.0 documents.
|
|
112
|
+
*/
|
|
113
|
+
function extractSwagger2SecuritySchemes(document) {
|
|
114
|
+
const securityDefinitions = document.securityDefinitions;
|
|
115
|
+
if (!securityDefinitions) {
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
const schemes = [];
|
|
119
|
+
for (const [name, definition] of Object.entries(securityDefinitions)) {
|
|
120
|
+
const extracted = extractSwagger2Scheme(name, definition);
|
|
121
|
+
if (extracted) {
|
|
122
|
+
schemes.push(extracted);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return schemes;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Extracts a single Swagger 2.0 security definition.
|
|
129
|
+
*/
|
|
130
|
+
function extractSwagger2Scheme(name, definition) {
|
|
131
|
+
switch (definition.type) {
|
|
132
|
+
case 'apiKey':
|
|
133
|
+
return {
|
|
134
|
+
name,
|
|
135
|
+
type: 'apiKey',
|
|
136
|
+
apiKeyName: definition.name,
|
|
137
|
+
apiKeyIn: definition.in
|
|
138
|
+
};
|
|
139
|
+
case 'basic':
|
|
140
|
+
// Swagger 2.0 has a separate 'basic' type which maps to http basic
|
|
141
|
+
return {
|
|
142
|
+
name,
|
|
143
|
+
type: 'http',
|
|
144
|
+
httpScheme: 'basic'
|
|
145
|
+
};
|
|
146
|
+
case 'oauth2':
|
|
147
|
+
return {
|
|
148
|
+
name,
|
|
149
|
+
type: 'oauth2',
|
|
150
|
+
oauth2Flows: extractSwagger2OAuth2Flow(definition)
|
|
151
|
+
};
|
|
152
|
+
default:
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Extracts OAuth2 flow from Swagger 2.0 format.
|
|
158
|
+
* Swagger 2.0 uses single 'flow' field instead of 'flows' object.
|
|
159
|
+
*/
|
|
160
|
+
function extractSwagger2OAuth2Flow(definition) {
|
|
161
|
+
const result = {};
|
|
162
|
+
const scopes = definition.scopes || {};
|
|
163
|
+
switch (definition.flow) {
|
|
164
|
+
case 'implicit':
|
|
165
|
+
result.implicit = {
|
|
166
|
+
authorizationUrl: definition.authorizationUrl || '',
|
|
167
|
+
scopes
|
|
168
|
+
};
|
|
169
|
+
break;
|
|
170
|
+
case 'password':
|
|
171
|
+
result.password = {
|
|
172
|
+
tokenUrl: definition.tokenUrl || '',
|
|
173
|
+
scopes
|
|
174
|
+
};
|
|
175
|
+
break;
|
|
176
|
+
case 'application':
|
|
177
|
+
// Swagger 2.0 'application' maps to OpenAPI 3.x 'clientCredentials'
|
|
178
|
+
result.clientCredentials = {
|
|
179
|
+
tokenUrl: definition.tokenUrl || '',
|
|
180
|
+
scopes
|
|
181
|
+
};
|
|
182
|
+
break;
|
|
183
|
+
case 'accessCode':
|
|
184
|
+
// Swagger 2.0 'accessCode' maps to OpenAPI 3.x 'authorizationCode'
|
|
185
|
+
result.authorizationCode = {
|
|
186
|
+
authorizationUrl: definition.authorizationUrl || '',
|
|
187
|
+
tokenUrl: definition.tokenUrl || '',
|
|
188
|
+
scopes
|
|
189
|
+
};
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Export Zod types for TypeScript presets
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
// Export utility functions
|
|
20
|
+
__exportStar(require("./presets"), exports);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createValidationPreset, createUnionValidationPreset, safeStringify, type ValidationPresetOptions } from './validation';
|
|
2
|
+
export { createUnionPreset, type UnionPresetOptions } from './union';
|
|
3
|
+
export { createPrimitivesPreset, type PrimitivesPresetOptions } from './primitives';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPrimitivesPreset = exports.createUnionPreset = exports.safeStringify = exports.createUnionValidationPreset = exports.createValidationPreset = void 0;
|
|
4
|
+
// Core validation presets
|
|
5
|
+
var validation_1 = require("./validation");
|
|
6
|
+
Object.defineProperty(exports, "createValidationPreset", { enumerable: true, get: function () { return validation_1.createValidationPreset; } });
|
|
7
|
+
Object.defineProperty(exports, "createUnionValidationPreset", { enumerable: true, get: function () { return validation_1.createUnionValidationPreset; } });
|
|
8
|
+
Object.defineProperty(exports, "safeStringify", { enumerable: true, get: function () { return validation_1.safeStringify; } });
|
|
9
|
+
// Core union marshalling/unmarshalling presets
|
|
10
|
+
var union_1 = require("./union");
|
|
11
|
+
Object.defineProperty(exports, "createUnionPreset", { enumerable: true, get: function () { return union_1.createUnionPreset; } });
|
|
12
|
+
// Primitive and array type marshalling/unmarshalling presets
|
|
13
|
+
var primitives_1 = require("./primitives");
|
|
14
|
+
Object.defineProperty(exports, "createPrimitivesPreset", { enumerable: true, get: function () { return primitives_1.createPrimitivesPreset; } });
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ConstrainedMetaModel } from '@asyncapi/modelina';
|
|
2
|
+
import { TypeScriptRenderer } from '@asyncapi/modelina/lib/types/generators/typescript/TypeScriptRenderer';
|
|
3
|
+
import { BaseGeneratorContext } from './validation';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for the primitives preset
|
|
6
|
+
*/
|
|
7
|
+
export interface PrimitivesPresetOptions {
|
|
8
|
+
/** Whether to include validation methods in generated primitive types */
|
|
9
|
+
includeValidation: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a preset that adds marshalling/unmarshalling and validation methods
|
|
13
|
+
* to primitive types (string, number, boolean) and array types
|
|
14
|
+
*
|
|
15
|
+
* @param options Configuration for primitive generation
|
|
16
|
+
* @param context Generator context containing input type information
|
|
17
|
+
* @returns Modelina preset object with primitive marshalling functionality
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const preset = createPrimitivesPreset({
|
|
22
|
+
* includeValidation: true
|
|
23
|
+
* }, context);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function createPrimitivesPreset(options: PrimitivesPresetOptions, context: BaseGeneratorContext): {
|
|
27
|
+
type: {
|
|
28
|
+
self({ model, content, renderer }: {
|
|
29
|
+
model: ConstrainedMetaModel;
|
|
30
|
+
content: string;
|
|
31
|
+
renderer: TypeScriptRenderer;
|
|
32
|
+
}): string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPrimitivesPreset = void 0;
|
|
4
|
+
const modelina_1 = require("@asyncapi/modelina");
|
|
5
|
+
const validation_1 = require("./validation");
|
|
6
|
+
/**
|
|
7
|
+
* Check if the model is a primitive type (string, integer, float, boolean)
|
|
8
|
+
*/
|
|
9
|
+
function isPrimitiveModel(model) {
|
|
10
|
+
return (model instanceof modelina_1.ConstrainedStringModel ||
|
|
11
|
+
model instanceof modelina_1.ConstrainedIntegerModel ||
|
|
12
|
+
model instanceof modelina_1.ConstrainedFloatModel ||
|
|
13
|
+
model instanceof modelina_1.ConstrainedBooleanModel);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if the model is a null type (ConstrainedAnyModel with type: null in schema)
|
|
17
|
+
* Modelina converts null types to ConstrainedAnyModel
|
|
18
|
+
*/
|
|
19
|
+
function isNullModel(model) {
|
|
20
|
+
if (!(model instanceof modelina_1.ConstrainedAnyModel)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
// Check if the original input schema has type: null
|
|
24
|
+
const originalInput = model.originalInput;
|
|
25
|
+
return originalInput && originalInput.type === 'null';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check if the model is a date format string type (date or date-time)
|
|
29
|
+
* Note: 'time' format is NOT included because RFC 3339 time strings like "14:30:00"
|
|
30
|
+
* are not valid Date constructor arguments in JavaScript and would produce Invalid Date.
|
|
31
|
+
* Time values should remain as strings.
|
|
32
|
+
*/
|
|
33
|
+
function isDateFormatModel(model) {
|
|
34
|
+
if (!(model instanceof modelina_1.ConstrainedStringModel)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const format = model.originalInput?.format;
|
|
38
|
+
return format === 'date' || format === 'date-time';
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Render marshal function for null type
|
|
42
|
+
*/
|
|
43
|
+
function renderNullMarshal(model) {
|
|
44
|
+
return `export function marshal(payload: null): string {
|
|
45
|
+
return JSON.stringify(payload);
|
|
46
|
+
}`;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Render unmarshal function for null type
|
|
50
|
+
*/
|
|
51
|
+
function renderNullUnmarshal(model) {
|
|
52
|
+
return `export function unmarshal(json: string): null {
|
|
53
|
+
const parsed = JSON.parse(json);
|
|
54
|
+
if (parsed !== null) {
|
|
55
|
+
throw new Error('Expected null value');
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}`;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Render marshal function for primitive types
|
|
62
|
+
*/
|
|
63
|
+
function renderPrimitiveMarshal(model) {
|
|
64
|
+
return `export function marshal(payload: ${model.name}): string {
|
|
65
|
+
return JSON.stringify(payload);
|
|
66
|
+
}`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Render unmarshal function for primitive types
|
|
70
|
+
*/
|
|
71
|
+
function renderPrimitiveUnmarshal(model) {
|
|
72
|
+
// For string types, the input can be a JSON string (quoted) or the raw value
|
|
73
|
+
// We use 'any' for the json parameter since JSON.parse returns 'any'
|
|
74
|
+
return `export function unmarshal(json: string): ${model.name} {
|
|
75
|
+
return JSON.parse(json) as ${model.name};
|
|
76
|
+
}`;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Render unmarshal function for date format types
|
|
80
|
+
* Converts JSON string to JavaScript Date object
|
|
81
|
+
*/
|
|
82
|
+
function renderDateUnmarshal(model) {
|
|
83
|
+
return `export function unmarshal(json: string): ${model.name} {
|
|
84
|
+
const parsed = JSON.parse(json);
|
|
85
|
+
return new Date(parsed);
|
|
86
|
+
}`;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Render marshal function for date format types
|
|
90
|
+
* Note: JSON.stringify(Date) calls Date.toJSON() which returns ISO string
|
|
91
|
+
*/
|
|
92
|
+
function renderDateMarshal(model) {
|
|
93
|
+
return `export function marshal(payload: ${model.name}): string {
|
|
94
|
+
return JSON.stringify(payload);
|
|
95
|
+
}`;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Render marshal function for array types
|
|
99
|
+
*/
|
|
100
|
+
function renderArrayMarshal(model) {
|
|
101
|
+
const valueModel = model.valueModel;
|
|
102
|
+
// Check if array items have a marshal method (object types)
|
|
103
|
+
const hasItemMarshal = valueModel.type !== 'string' &&
|
|
104
|
+
valueModel.type !== 'number' &&
|
|
105
|
+
valueModel.type !== 'boolean';
|
|
106
|
+
if (hasItemMarshal) {
|
|
107
|
+
return `export function marshal(payload: ${model.name}): string {
|
|
108
|
+
return JSON.stringify(payload.map((item) => {
|
|
109
|
+
if (item && typeof item === 'object' && 'marshal' in item && typeof item.marshal === 'function') {
|
|
110
|
+
return JSON.parse(item.marshal());
|
|
111
|
+
}
|
|
112
|
+
return item;
|
|
113
|
+
}));
|
|
114
|
+
}`;
|
|
115
|
+
}
|
|
116
|
+
return `export function marshal(payload: ${model.name}): string {
|
|
117
|
+
return JSON.stringify(payload);
|
|
118
|
+
}`;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Render unmarshal function for array types
|
|
122
|
+
*/
|
|
123
|
+
function renderArrayUnmarshal(model) {
|
|
124
|
+
const valueModel = model.valueModel;
|
|
125
|
+
// Check if array items have an unmarshal method (only object types do)
|
|
126
|
+
// Exclude primitives, nested arrays, and union types - they don't have unmarshal methods
|
|
127
|
+
// Union types are just type aliases without static unmarshal methods
|
|
128
|
+
const hasItemUnmarshal = valueModel.type !== 'string' &&
|
|
129
|
+
valueModel.type !== 'number' &&
|
|
130
|
+
valueModel.type !== 'boolean' &&
|
|
131
|
+
!(valueModel instanceof modelina_1.ConstrainedArrayModel) &&
|
|
132
|
+
!(valueModel instanceof modelina_1.ConstrainedUnionModel);
|
|
133
|
+
if (hasItemUnmarshal) {
|
|
134
|
+
const itemTypeName = valueModel.name;
|
|
135
|
+
return `export function unmarshal(json: string | any[]): ${model.name} {
|
|
136
|
+
const arr = typeof json === 'string' ? JSON.parse(json) : json;
|
|
137
|
+
return arr.map((item: any) => {
|
|
138
|
+
if (item && typeof item === 'object') {
|
|
139
|
+
return ${itemTypeName}.unmarshal(item);
|
|
140
|
+
}
|
|
141
|
+
return item;
|
|
142
|
+
}) as ${model.name};
|
|
143
|
+
}`;
|
|
144
|
+
}
|
|
145
|
+
return `export function unmarshal(json: string | any[]): ${model.name} {
|
|
146
|
+
if (typeof json === 'string') {
|
|
147
|
+
return JSON.parse(json) as ${model.name};
|
|
148
|
+
}
|
|
149
|
+
return json as ${model.name};
|
|
150
|
+
}`;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Creates a preset that adds marshalling/unmarshalling and validation methods
|
|
154
|
+
* to primitive types (string, number, boolean) and array types
|
|
155
|
+
*
|
|
156
|
+
* @param options Configuration for primitive generation
|
|
157
|
+
* @param context Generator context containing input type information
|
|
158
|
+
* @returns Modelina preset object with primitive marshalling functionality
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const preset = createPrimitivesPreset({
|
|
163
|
+
* includeValidation: true
|
|
164
|
+
* }, context);
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
function createPrimitivesPreset(options, context) {
|
|
168
|
+
return {
|
|
169
|
+
type: {
|
|
170
|
+
self({ model, content, renderer }) {
|
|
171
|
+
// Handle primitive types (string, integer, float, boolean)
|
|
172
|
+
if (isPrimitiveModel(model)) {
|
|
173
|
+
// Use date-specific marshal/unmarshal for date formats
|
|
174
|
+
const isDate = isDateFormatModel(model);
|
|
175
|
+
const unmarshalFunc = isDate
|
|
176
|
+
? renderDateUnmarshal(model)
|
|
177
|
+
: renderPrimitiveUnmarshal(model);
|
|
178
|
+
const marshalFunc = isDate
|
|
179
|
+
? renderDateMarshal(model)
|
|
180
|
+
: renderPrimitiveMarshal(model);
|
|
181
|
+
return `${content}
|
|
182
|
+
|
|
183
|
+
${unmarshalFunc}
|
|
184
|
+
${marshalFunc}
|
|
185
|
+
${options.includeValidation ? (0, validation_1.generateTypescriptValidationCode)({ model, renderer, asClassMethods: false, context: context }) : ''}
|
|
186
|
+
`;
|
|
187
|
+
}
|
|
188
|
+
// Handle array types
|
|
189
|
+
if (model instanceof modelina_1.ConstrainedArrayModel) {
|
|
190
|
+
return `${content}
|
|
191
|
+
|
|
192
|
+
${renderArrayUnmarshal(model)}
|
|
193
|
+
${renderArrayMarshal(model)}
|
|
194
|
+
${options.includeValidation ? (0, validation_1.generateTypescriptValidationCode)({ model, renderer, asClassMethods: false, context: context }) : ''}
|
|
195
|
+
`;
|
|
196
|
+
}
|
|
197
|
+
// Handle null types (ConstrainedAnyModel with type: null in original schema)
|
|
198
|
+
if (isNullModel(model)) {
|
|
199
|
+
return `${content}
|
|
200
|
+
|
|
201
|
+
${renderNullUnmarshal(model)}
|
|
202
|
+
${renderNullMarshal(model)}
|
|
203
|
+
${options.includeValidation ? (0, validation_1.generateTypescriptValidationCode)({ model, renderer, asClassMethods: false, context: context }) : ''}
|
|
204
|
+
`;
|
|
205
|
+
}
|
|
206
|
+
return content;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
exports.createPrimitivesPreset = createPrimitivesPreset;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ConstrainedMetaModel } from '@asyncapi/modelina';
|
|
2
|
+
import { TypeScriptRenderer } from '@asyncapi/modelina/lib/types/generators/typescript/TypeScriptRenderer';
|
|
3
|
+
import { BaseGeneratorContext } from './validation';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for the union preset
|
|
6
|
+
*/
|
|
7
|
+
export interface UnionPresetOptions {
|
|
8
|
+
/** Whether to include validation methods in generated union types */
|
|
9
|
+
includeValidation: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a union preset that adds marshalling/unmarshalling methods to union types
|
|
13
|
+
*
|
|
14
|
+
* @param options Configuration for union generation
|
|
15
|
+
* @param context Generator context containing input type information
|
|
16
|
+
* @returns Modelina preset object with union marshalling functionality
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const preset = createUnionPreset({
|
|
21
|
+
* includeValidation: true
|
|
22
|
+
* }, context);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function createUnionPreset(options: UnionPresetOptions, context: BaseGeneratorContext): {
|
|
26
|
+
type: {
|
|
27
|
+
self({ model, content, renderer }: {
|
|
28
|
+
model: ConstrainedMetaModel;
|
|
29
|
+
content: string;
|
|
30
|
+
renderer: TypeScriptRenderer;
|
|
31
|
+
}): string;
|
|
32
|
+
};
|
|
33
|
+
};
|