@nestia/migrate 10.0.0 → 10.0.2

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.
@@ -32,10 +32,7 @@ export namespace NestiaMigrateSchemaProgrammer {
32
32
  schema: props.schema,
33
33
  });
34
34
  else if (OpenApiTypeChecker.isBoolean(props.schema))
35
- return writeBoolean({
36
- importer: props.importer,
37
- schema: props.schema,
38
- });
35
+ return writeBoolean();
39
36
  else if (OpenApiTypeChecker.isInteger(props.schema))
40
37
  return writeInteger({
41
38
  importer: props.importer,
@@ -101,48 +98,23 @@ export namespace NestiaMigrateSchemaProgrammer {
101
98
  importer: NestiaMigrateImportProgrammer;
102
99
  schema: OpenApi.IJsonSchema.IConstant;
103
100
  }): ts.TypeNode => {
104
- const intersection: ts.TypeNode[] = [
105
- ts.factory.createLiteralTypeNode(
106
- typeof props.schema.const === "boolean"
107
- ? props.schema.const === true
108
- ? ts.factory.createTrue()
109
- : ts.factory.createFalse()
110
- : typeof props.schema.const === "number"
111
- ? props.schema.const < 0
112
- ? ts.factory.createPrefixUnaryExpression(
113
- ts.SyntaxKind.MinusToken,
114
- ts.factory.createNumericLiteral(-props.schema.const),
115
- )
116
- : ts.factory.createNumericLiteral(props.schema.const)
117
- : ts.factory.createStringLiteral(props.schema.const),
118
- ),
119
- ];
120
- writePlugin({
121
- importer: props.importer,
122
- schema: props.schema,
123
- regular: typia.misc.literals<keyof OpenApi.IJsonSchema.IConstant>(),
124
- intersection,
125
- });
126
- return intersection.length === 1
127
- ? intersection[0]
128
- : ts.factory.createIntersectionTypeNode(intersection);
101
+ return ts.factory.createLiteralTypeNode(
102
+ typeof props.schema.const === "boolean"
103
+ ? props.schema.const === true
104
+ ? ts.factory.createTrue()
105
+ : ts.factory.createFalse()
106
+ : typeof props.schema.const === "number"
107
+ ? props.schema.const < 0
108
+ ? ts.factory.createPrefixUnaryExpression(
109
+ ts.SyntaxKind.MinusToken,
110
+ ts.factory.createNumericLiteral(-props.schema.const),
111
+ )
112
+ : ts.factory.createNumericLiteral(props.schema.const)
113
+ : ts.factory.createStringLiteral(props.schema.const),
114
+ );
129
115
  };
130
116
 
131
- const writeBoolean = (props: {
132
- importer: NestiaMigrateImportProgrammer;
133
- schema: OpenApi.IJsonSchema.IBoolean;
134
- }): ts.TypeNode => {
135
- const intersection: ts.TypeNode[] = [TypeFactory.keyword("boolean")];
136
- writePlugin({
137
- importer: props.importer,
138
- regular: typia.misc.literals<keyof OpenApi.IJsonSchema.IBoolean>(),
139
- intersection,
140
- schema: props.schema,
141
- });
142
- return intersection.length === 1
143
- ? intersection[0]
144
- : ts.factory.createIntersectionTypeNode(intersection);
145
- };
117
+ const writeBoolean = (): ts.TypeNode => TypeFactory.keyword("boolean");
146
118
 
147
119
  const writeInteger = (props: {
148
120
  importer: NestiaMigrateImportProgrammer;
@@ -193,12 +165,6 @@ export namespace NestiaMigrateSchemaProgrammer {
193
165
  intersection.push(
194
166
  props.importer.tag("MultipleOf", props.schema.multipleOf),
195
167
  );
196
- writePlugin({
197
- importer: props.importer,
198
- regular: typia.misc.literals<keyof OpenApi.IJsonSchema.INumber>(),
199
- intersection,
200
- schema: props.schema,
201
- });
202
168
  return intersection.length === 1
203
169
  ? intersection[0]
204
170
  : ts.factory.createIntersectionTypeNode(intersection);
@@ -234,12 +200,6 @@ export namespace NestiaMigrateSchemaProgrammer {
234
200
  intersection.push(
235
201
  props.importer.tag("ContentMediaType", props.schema.contentMediaType),
236
202
  );
237
- writePlugin({
238
- importer: props.importer,
239
- regular: typia.misc.literals<keyof OpenApi.IJsonSchema.IString>(),
240
- intersection,
241
- schema: props.schema,
242
- });
243
203
  return intersection.length === 1
244
204
  ? intersection[0]
245
205
  : ts.factory.createIntersectionTypeNode(intersection);
@@ -268,12 +228,6 @@ export namespace NestiaMigrateSchemaProgrammer {
268
228
  intersection.push(props.importer.tag("MaxItems", props.schema.maxItems));
269
229
  if (props.schema.uniqueItems === true)
270
230
  intersection.push(props.importer.tag("UniqueItems"));
271
- writePlugin({
272
- importer: props.importer,
273
- regular: typia.misc.literals<keyof OpenApi.IJsonSchema.IArray>(),
274
- intersection,
275
- schema: props.schema,
276
- });
277
231
  return intersection.length === 1
278
232
  ? intersection[0]
279
233
  : ts.factory.createIntersectionTypeNode(intersection);
@@ -283,8 +237,8 @@ export namespace NestiaMigrateSchemaProgrammer {
283
237
  components: OpenApi.IComponents;
284
238
  importer: NestiaMigrateImportProgrammer;
285
239
  schema: OpenApi.IJsonSchema.ITuple;
286
- }): ts.TypeNode => {
287
- const tuple: ts.TypeNode = ts.factory.createTupleTypeNode([
240
+ }): ts.TypeNode =>
241
+ ts.factory.createTupleTypeNode([
288
242
  ...props.schema.prefixItems.map((item) =>
289
243
  write({
290
244
  components: props.components,
@@ -313,17 +267,6 @@ export namespace NestiaMigrateSchemaProgrammer {
313
267
  ]
314
268
  : []),
315
269
  ]);
316
- const intersection: ts.TypeNode[] = [tuple];
317
- writePlugin({
318
- importer: props.importer,
319
- regular: typia.misc.literals<keyof OpenApi.IJsonSchema.ITuple>(),
320
- intersection,
321
- schema: props.schema,
322
- });
323
- return intersection.length === 1
324
- ? intersection[0]
325
- : ts.factory.createIntersectionTypeNode(intersection);
326
- };
327
270
 
328
271
  const writeObject = (props: {
329
272
  components: OpenApi.IComponents;
@@ -461,18 +404,38 @@ export namespace NestiaMigrateSchemaProgrammer {
461
404
  }
462
405
  const createNode = (text: string) => ts.factory.createTypeReferenceNode(text);
463
406
 
464
- const writeComment = (schema: OpenApi.IJsonSchema): string =>
465
- [
407
+ const writeComment = (schema: OpenApi.IJsonSchema): string => {
408
+ interface IPlugin {
409
+ key: string;
410
+ value: undefined | string | number | boolean;
411
+ }
412
+ const plugins: IPlugin[] = [];
413
+ if (schema.title !== undefined)
414
+ plugins.push({
415
+ key: "title",
416
+ value: schema.title,
417
+ });
418
+ if (schema.deprecated === true)
419
+ plugins.push({
420
+ key: "deprecated",
421
+ value: undefined,
422
+ });
423
+ for (const [key, value] of Object.entries(schema))
424
+ if (key.startsWith("x-") && typia.is<boolean | number | string>(value))
425
+ plugins.push({
426
+ key,
427
+ value,
428
+ });
429
+ return [
466
430
  ...(schema.description?.length
467
431
  ? [eraseCommentTags(schema.description)]
468
432
  : []),
469
- ...(schema.description?.length &&
470
- (schema.title !== undefined || schema.deprecated === true)
471
- ? [""]
472
- : []),
473
- ...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
474
- ...(schema.deprecated === true ? [`@deprecated`] : []),
433
+ ...(schema.description?.length && plugins.length !== 0 ? [""] : []),
434
+ ...plugins.map((p) =>
435
+ p.value === undefined ? `@${p.key}` : `@${p.key} ${String(p.value)}`,
436
+ ),
475
437
  ].join("\n");
438
+ };
476
439
 
477
440
  const eraseCommentTags = (description: string): string => {
478
441
  const lines: string[] = description.split("\n");
@@ -481,24 +444,6 @@ const eraseCommentTags = (description: string): string => {
481
444
  .join("\n");
482
445
  };
483
446
 
484
- const writePlugin = (props: {
485
- importer: NestiaMigrateImportProgrammer;
486
- regular: string[];
487
- intersection: ts.TypeNode[];
488
- schema: Record<string, any>;
489
- }) => {
490
- const extra: any = {};
491
- for (const [key, value] of Object.entries(props.schema))
492
- if (
493
- value !== undefined &&
494
- false === props.regular.includes(key) &&
495
- key.startsWith("x-")
496
- )
497
- extra[key] = value;
498
- if (Object.keys(extra).length !== 0)
499
- props.intersection.push(props.importer.tag("JsonSchemaPlugin", extra));
500
- };
501
-
502
447
  const COMMENT_TAGS = [
503
448
  // string
504
449
  "@format",