swagger-typescript-api 13.0.9 → 13.0.10

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.
Files changed (65) hide show
  1. package/dist/chunk-3S356DIU.cjs +105 -0
  2. package/dist/chunk-3S356DIU.cjs.map +1 -0
  3. package/dist/chunk-MTWJNW6B.js +65 -0
  4. package/dist/chunk-MTWJNW6B.js.map +1 -0
  5. package/dist/cli.cjs +43 -0
  6. package/dist/cli.cjs.map +1 -0
  7. package/dist/cli.js +36 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/lib.cjs +21 -0
  10. package/dist/lib.cjs.map +1 -0
  11. package/dist/lib.js +4 -0
  12. package/dist/lib.js.map +1 -0
  13. package/package.json +25 -14
  14. package/cli/constants.js +0 -6
  15. package/cli/execute.js +0 -180
  16. package/cli/index.js +0 -94
  17. package/cli/operations/display-help.js +0 -177
  18. package/cli/operations/display-version.js +0 -5
  19. package/cli/parse-args.js +0 -24
  20. package/cli/process-option.js +0 -75
  21. package/index.js +0 -344
  22. package/src/code-formatter.js +0 -114
  23. package/src/code-gen-process.js +0 -569
  24. package/src/commands/generate-templates/configuration.js +0 -31
  25. package/src/commands/generate-templates/index.js +0 -10
  26. package/src/commands/generate-templates/templates-gen-process.js +0 -205
  27. package/src/component-type-name-resolver.js +0 -42
  28. package/src/configuration.js +0 -445
  29. package/src/constants.js +0 -77
  30. package/src/index.js +0 -16
  31. package/src/schema-components-map.js +0 -76
  32. package/src/schema-parser/base-schema-parsers/array.js +0 -41
  33. package/src/schema-parser/base-schema-parsers/complex.js +0 -49
  34. package/src/schema-parser/base-schema-parsers/discriminator.js +0 -305
  35. package/src/schema-parser/base-schema-parsers/enum.js +0 -156
  36. package/src/schema-parser/base-schema-parsers/object.js +0 -103
  37. package/src/schema-parser/base-schema-parsers/primitive.js +0 -61
  38. package/src/schema-parser/complex-schema-parsers/all-of.js +0 -26
  39. package/src/schema-parser/complex-schema-parsers/any-of.js +0 -27
  40. package/src/schema-parser/complex-schema-parsers/not.js +0 -9
  41. package/src/schema-parser/complex-schema-parsers/one-of.js +0 -27
  42. package/src/schema-parser/mono-schema-parser.js +0 -46
  43. package/src/schema-parser/schema-formatters.js +0 -164
  44. package/src/schema-parser/schema-parser-fabric.js +0 -130
  45. package/src/schema-parser/schema-parser.js +0 -295
  46. package/src/schema-parser/schema-utils.js +0 -319
  47. package/src/schema-parser/util/enum-key-resolver.js +0 -24
  48. package/src/schema-routes/schema-routes.js +0 -1208
  49. package/src/schema-routes/util/specific-arg-name-resolver.js +0 -24
  50. package/src/schema-walker.js +0 -91
  51. package/src/swagger-schema-resolver.js +0 -195
  52. package/src/templates-worker.js +0 -243
  53. package/src/translators/javascript.js +0 -81
  54. package/src/translators/translator.js +0 -33
  55. package/src/type-name-formatter.js +0 -111
  56. package/src/util/file-system.js +0 -95
  57. package/src/util/id.js +0 -7
  58. package/src/util/internal-case.js +0 -7
  59. package/src/util/logger.js +0 -142
  60. package/src/util/name-resolver.js +0 -103
  61. package/src/util/object-assign.js +0 -17
  62. package/src/util/pascal-case.js +0 -7
  63. package/src/util/random.js +0 -11
  64. package/src/util/request.js +0 -63
  65. package/src/util/sort-by-property.js +0 -15
@@ -1,130 +0,0 @@
1
- import _ from "lodash";
2
- import { SchemaFormatters } from "./schema-formatters.js";
3
- import { SchemaParser } from "./schema-parser.js";
4
- import { SchemaUtils } from "./schema-utils.js";
5
-
6
- class SchemaParserFabric {
7
- /** @type {CodeGenConfig} */
8
- config;
9
- /** @type {Logger} */
10
- logger;
11
- /** @type {SchemaComponentsMap} */
12
- schemaComponentsMap;
13
- /** @type {TypeNameFormatter} */
14
- typeNameFormatter;
15
- /** @type {SchemaFormatters} */
16
- schemaFormatters;
17
- /** @type {TemplatesWorker} */
18
- templatesWorker;
19
- /** @type {SchemaUtils} */
20
- schemaUtils;
21
- /** @type {SchemaWalker} */
22
- schemaWalker;
23
-
24
- constructor({
25
- config,
26
- logger,
27
- templatesWorker,
28
- schemaComponentsMap,
29
- typeNameFormatter,
30
- schemaWalker,
31
- }) {
32
- this.config = config;
33
- this.logger = logger;
34
- this.schemaComponentsMap = schemaComponentsMap;
35
- this.typeNameFormatter = typeNameFormatter;
36
- this.templatesWorker = templatesWorker;
37
- this.schemaWalker = schemaWalker;
38
- this.schemaUtils = new SchemaUtils(this);
39
- this.schemaFormatters = new SchemaFormatters(this);
40
- }
41
-
42
- createSchemaParser = ({ schema, typeName, schemaPath }) => {
43
- return new SchemaParser(this, { schema, typeName, schemaPath });
44
- };
45
-
46
- /**
47
- *
48
- * @param content schema content
49
- * @param linkedSchema link content to attached schema
50
- * @param linkedComponent link content and other schema props to attached component
51
- * @param schemaPath
52
- * @param otherSchemaProps
53
- * @returns {{}}
54
- */
55
- createSchema = ({
56
- content,
57
- linkedSchema = {},
58
- linkedComponent,
59
- schemaPath,
60
- ...otherSchemaProps
61
- }) => {
62
- const parser = this.createSchemaParser({
63
- schema: linkedComponent || linkedSchema,
64
- schemaPath,
65
- });
66
- const parsed = parser.parseSchema();
67
- parsed.content = content;
68
- Object.assign(parsed, otherSchemaProps);
69
- if (linkedComponent) {
70
- linkedComponent.typeData = parsed;
71
- }
72
- return parser.schema;
73
- };
74
-
75
- createParsedComponent = ({ typeName, schema, schemaPath }) => {
76
- const schemaCopy = _.cloneDeep(schema);
77
- const customComponent = this.schemaComponentsMap.createComponent(
78
- this.schemaComponentsMap.createRef(["components", "schemas", typeName]),
79
- schemaCopy,
80
- );
81
- const parsed = this.parseSchema(schemaCopy, null, schemaPath);
82
-
83
- parsed.name = typeName;
84
- customComponent.typeData = parsed;
85
-
86
- return customComponent;
87
- };
88
-
89
- /**
90
- *
91
- * @param schema {any}
92
- * @param typeName {null | string}
93
- * @param [schemaPath] {string[]}
94
- * @return {Record<string, any>}
95
- */
96
- parseSchema = (schema, typeName = null, schemaPath = []) => {
97
- const schemaParser = this.createSchemaParser({
98
- schema,
99
- typeName,
100
- schemaPath,
101
- });
102
- return schemaParser.parseSchema();
103
- };
104
-
105
- /**
106
- *
107
- * @param schema {any}
108
- * @param typeName {null | string}
109
- * @param [schemaPath] {string[]}
110
- * @return {Record<string, any>}
111
- */
112
- getInlineParseContent = (schema, typeName, schemaPath) => {
113
- const parser = this.createSchemaParser({ schema, typeName, schemaPath });
114
- return parser.getInlineParseContent();
115
- };
116
-
117
- /**
118
- *
119
- * @param schema {any}
120
- * @param typeName {null | string}
121
- * @param [schemaPath] {string[]}
122
- * @return {Record<string, any>}
123
- */
124
- getParseContent = (schema, typeName, schemaPath) => {
125
- const parser = this.createSchemaParser({ schema, typeName, schemaPath });
126
- return parser.getParseContent();
127
- };
128
- }
129
-
130
- export { SchemaParserFabric };
@@ -1,295 +0,0 @@
1
- import _ from "lodash";
2
- import { SCHEMA_TYPES } from "../constants.js";
3
- import { sortByProperty } from "../util/sort-by-property.js";
4
- import { ArraySchemaParser } from "./base-schema-parsers/array.js";
5
- import { ComplexSchemaParser } from "./base-schema-parsers/complex.js";
6
- import { DiscriminatorSchemaParser } from "./base-schema-parsers/discriminator.js";
7
- import { EnumSchemaParser } from "./base-schema-parsers/enum.js";
8
- import { ObjectSchemaParser } from "./base-schema-parsers/object.js";
9
- import { PrimitiveSchemaParser } from "./base-schema-parsers/primitive.js";
10
- import { AllOfSchemaParser } from "./complex-schema-parsers/all-of.js";
11
- import { AnyOfSchemaParser } from "./complex-schema-parsers/any-of.js";
12
- import { NotSchemaParser } from "./complex-schema-parsers/not.js";
13
- import { OneOfSchemaParser } from "./complex-schema-parsers/one-of.js";
14
- import { SchemaFormatters } from "./schema-formatters.js";
15
- import { SchemaUtils } from "./schema-utils.js";
16
-
17
- class SchemaParser {
18
- /** @type {SchemaParserFabric} */
19
- schemaParserFabric;
20
- /** @type {CodeGenConfig} */
21
- config;
22
- /** @type {Logger} */
23
- logger;
24
- /** @type {SchemaComponentsMap} */
25
- schemaComponentsMap;
26
- /** @type {TypeNameFormatter} */
27
- typeNameFormatter;
28
- /** @type {SchemaFormatters} */
29
- schemaFormatters;
30
- /** @type {SchemaUtils} */
31
- schemaUtils;
32
- /** @type {TemplatesWorker} */
33
- templatesWorker;
34
- /** @type {SchemaWalker} */
35
- schemaWalker;
36
-
37
- typeName;
38
- schema;
39
- schemaPath = [];
40
-
41
- constructor(schemaParserFabric, { typeName, schema, schemaPath } = {}) {
42
- this.schemaParserFabric = schemaParserFabric;
43
- this.config = schemaParserFabric.config;
44
- this.logger = schemaParserFabric.logger;
45
- this.templatesWorker = schemaParserFabric.templatesWorker;
46
- this.schemaComponentsMap = schemaParserFabric.schemaComponentsMap;
47
- this.typeNameFormatter = schemaParserFabric.typeNameFormatter;
48
- this.schemaWalker = schemaParserFabric.schemaWalker;
49
- this.schemaFormatters = schemaParserFabric.schemaFormatters;
50
- this.schemaUtils = schemaParserFabric.schemaUtils;
51
-
52
- this.typeName = typeName || null;
53
- this.schema = schema;
54
- this.schemaPath = [...(schemaPath || [])];
55
- }
56
-
57
- _complexSchemaParsers = {
58
- [SCHEMA_TYPES.COMPLEX_ONE_OF]: (schema) => {
59
- const SchemaParser =
60
- this.config.schemaParsers.complexOneOf || OneOfSchemaParser;
61
- const schemaParser = new SchemaParser(
62
- this,
63
- schema,
64
- null,
65
- this.schemaPath,
66
- );
67
- return schemaParser.parse();
68
- },
69
- [SCHEMA_TYPES.COMPLEX_ALL_OF]: (schema) => {
70
- const SchemaParser =
71
- this.config.schemaParsers.complexAllOf || AllOfSchemaParser;
72
- const schemaParser = new SchemaParser(
73
- this,
74
- schema,
75
- null,
76
- this.schemaPath,
77
- );
78
- return schemaParser.parse();
79
- },
80
- [SCHEMA_TYPES.COMPLEX_ANY_OF]: (schema) => {
81
- const SchemaParser =
82
- this.config.schemaParsers.complexAnyOf || AnyOfSchemaParser;
83
- const schemaParser = new SchemaParser(
84
- this,
85
- schema,
86
- null,
87
- this.schemaPath,
88
- );
89
- return schemaParser.parse();
90
- },
91
- [SCHEMA_TYPES.COMPLEX_NOT]: (schema) => {
92
- const SchemaParser =
93
- this.config.schemaParsers.complexNot || NotSchemaParser;
94
- const schemaParser = new SchemaParser(
95
- this,
96
- schema,
97
- null,
98
- this.schemaPath,
99
- );
100
- return schemaParser.parse();
101
- },
102
- };
103
-
104
- _baseSchemaParsers = {
105
- [SCHEMA_TYPES.ENUM]: (schema, typeName) => {
106
- const SchemaParser = this.config.schemaParsers.enum || EnumSchemaParser;
107
- const schemaParser = new SchemaParser(
108
- this,
109
- schema,
110
- typeName,
111
- this.schemaPath,
112
- );
113
- return schemaParser.parse();
114
- },
115
- [SCHEMA_TYPES.OBJECT]: (schema, typeName) => {
116
- const SchemaParser =
117
- this.config.schemaParsers.object || ObjectSchemaParser;
118
- const schemaParser = new SchemaParser(
119
- this,
120
- schema,
121
- typeName,
122
- this.schemaPath,
123
- );
124
- return schemaParser.parse();
125
- },
126
- [SCHEMA_TYPES.COMPLEX]: (schema, typeName) => {
127
- const SchemaParser =
128
- this.config.schemaParsers.complex || ComplexSchemaParser;
129
- const schemaParser = new SchemaParser(
130
- this,
131
- schema,
132
- typeName,
133
- this.schemaPath,
134
- );
135
- return schemaParser.parse();
136
- },
137
- [SCHEMA_TYPES.PRIMITIVE]: (schema, typeName) => {
138
- const SchemaParser =
139
- this.config.schemaParsers.primitive || PrimitiveSchemaParser;
140
- const schemaParser = new SchemaParser(
141
- this,
142
- schema,
143
- typeName,
144
- this.schemaPath,
145
- );
146
- return schemaParser.parse();
147
- },
148
- [SCHEMA_TYPES.DISCRIMINATOR]: (schema, typeName) => {
149
- const SchemaParser =
150
- this.config.schemaParsers.discriminator || DiscriminatorSchemaParser;
151
- const schemaParser = new SchemaParser(
152
- this,
153
- schema,
154
- typeName,
155
- this.schemaPath,
156
- );
157
- return schemaParser.parse();
158
- },
159
- [SCHEMA_TYPES.ARRAY]: (schema, typeName) => {
160
- const SchemaParser = this.config.schemaParsers.array || ArraySchemaParser;
161
- const schemaParser = new SchemaParser(
162
- this,
163
- schema,
164
- typeName,
165
- this.schemaPath,
166
- );
167
- return schemaParser.parse();
168
- },
169
- };
170
-
171
- /**
172
- * @return {Record<string, any>}
173
- */
174
- parseSchema = () => {
175
- if (!this.schema)
176
- return this._baseSchemaParsers[SCHEMA_TYPES.PRIMITIVE](
177
- null,
178
- this.typeName,
179
- );
180
-
181
- let schemaType = null;
182
- let parsedSchema = null;
183
-
184
- if (typeof this.schema === "string") {
185
- return this.schema;
186
- }
187
-
188
- if (!this.schema.$parsed) {
189
- if (!this.typeName && this.schemaUtils.isRefSchema(this.schema)) {
190
- this.typeName = this.schemaUtils.getSchemaType(this.schema);
191
- }
192
-
193
- //#region swagger schemas fixes
194
-
195
- // schema has items but don't have array type
196
- if (
197
- this.schema.items &&
198
- !Array.isArray(this.schema.items) &&
199
- !this.schema.type
200
- ) {
201
- this.schema.type = SCHEMA_TYPES.ARRAY;
202
- }
203
- // schema is enum with one null value
204
- if (
205
- Array.isArray(this.schema.enum) &&
206
- this.schema.enum.length === 1 &&
207
- this.schema.enum[0] == null
208
- ) {
209
- this.logger.debug("invalid enum schema", this.schema);
210
- this.schema = { type: this.config.Ts.Keyword.Null };
211
- }
212
- // schema is response schema
213
- if ("content" in this.schema && typeof this.schema.content === "object") {
214
- const schema = this.extractSchemaFromResponseStruct(this.schema);
215
- const schemaParser = this.schemaParserFabric.createSchemaParser({
216
- schema,
217
- typeName: this.typeName,
218
- schemaPath: this.schemaPath,
219
- });
220
- this.schema.$parsed = schemaParser.parseSchema();
221
- return this.schema.$parsed;
222
- }
223
-
224
- //#endregion
225
-
226
- schemaType = this.schemaUtils.getInternalSchemaType(this.schema);
227
-
228
- this.schemaPath.push(this.typeName);
229
-
230
- _.merge(
231
- this.schema,
232
- this.config.hooks.onPreParseSchema(
233
- this.schema,
234
- this.typeName,
235
- schemaType,
236
- ),
237
- );
238
- parsedSchema = this._baseSchemaParsers[schemaType](
239
- this.schema,
240
- this.typeName,
241
- );
242
- this.schema.$parsed =
243
- this.config.hooks.onParseSchema(this.schema, parsedSchema) ||
244
- parsedSchema;
245
-
246
- if (
247
- this.config.sortTypes &&
248
- Array.isArray(this.schema.$parsed?.content)
249
- ) {
250
- this.schema.$parsed.content = this.schema.$parsed.content.sort(
251
- sortByProperty("name"),
252
- );
253
- }
254
- }
255
-
256
- this.schemaPath.pop();
257
-
258
- return this.schema.$parsed;
259
- };
260
-
261
- getInlineParseContent = () => {
262
- const parsedSchema = this.parseSchema();
263
- const formattedSchema = this.schemaFormatters.formatSchema(
264
- parsedSchema,
265
- "inline",
266
- );
267
- return formattedSchema.content;
268
- };
269
-
270
- getParseContent = () => {
271
- const parsedSchema = this.parseSchema();
272
- const formattedSchema = this.schemaFormatters.formatSchema(
273
- parsedSchema,
274
- "base",
275
- );
276
- return formattedSchema.content;
277
- };
278
-
279
- extractSchemaFromResponseStruct = (responseStruct) => {
280
- const { content, ...extras } = responseStruct;
281
-
282
- const firstResponse = _.first(_.values(content));
283
- const firstSchema = _.get(firstResponse, "schema");
284
-
285
- if (!firstSchema) return;
286
-
287
- return {
288
- ...extras,
289
- ..._.omit(firstResponse, "schema"),
290
- ...firstSchema,
291
- };
292
- };
293
- }
294
-
295
- export { SchemaParser };