@nestia/migrate 0.1.11 → 0.2.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.
@@ -14,11 +14,11 @@ export namespace RouteProgrammer {
14
14
  (props: { path: string; method: string }) =>
15
15
  (route: ISwaggerRoute): IMigrateRoute | null => {
16
16
  const body = emplaceBodySchema(emplaceReference(swagger)("body"))(
17
- route.requestBody?.content,
17
+ route.requestBody,
18
18
  );
19
19
  const response = emplaceBodySchema(
20
20
  emplaceReference(swagger)("response"),
21
- )((route.responses?.["200"] ?? route.responses?.["201"])?.content);
21
+ )(route.responses?.["201"] ?? route.responses?.["200"]);
22
22
  if (body === false || response === false) {
23
23
  console.log(
24
24
  `Failed to migrate ${props.method.toUpperCase()} ${
@@ -193,32 +193,47 @@ export namespace RouteProgrammer {
193
193
  body,
194
194
  response,
195
195
  description: describe(route),
196
+ "x-nestia-jsDocTags": route["x-nestia-jsDocTags"],
196
197
  };
197
198
  };
198
199
 
199
200
  const describe = (route: ISwaggerRoute): string | undefined => {
200
- const content: string[] = [];
201
+ const commentTags: string[] = [];
201
202
  const add = (text: string) => {
202
- if (!route.description || route.description.indexOf(text) === -1)
203
- content.push(text);
203
+ if (commentTags.every((line) => line !== text))
204
+ commentTags.push(text);
204
205
  };
205
- if (route.summary)
206
- add(
207
- (route.summary.endsWith(".")
208
- ? route.summary
209
- : route.summary + ".") + "\n",
210
- );
211
- if (route.description) {
212
- content.push(...route.description.split("\n"));
213
- if (!route.description.split("\n").at(-1)?.startsWith("@"))
214
- content.push("");
206
+
207
+ let description: string | undefined = route.description;
208
+ if (route.summary) {
209
+ const emended: string = route.summary.endsWith(".")
210
+ ? route.summary
211
+ : route.summary + ".";
212
+ if (
213
+ description !== undefined &&
214
+ !description?.startsWith(route.summary) &&
215
+ !route["x-nestia-jsDocTags"]?.some((t) => t.name === "summary")
216
+ )
217
+ description = `${emended}\n${description}`;
215
218
  }
216
219
  if (route.tags) route.tags.forEach((name) => add(`@tag ${name}`));
217
220
  if (route.deprecated) add("@deprecated");
218
221
  for (const security of route.security ?? [])
219
222
  for (const [name, scopes] of Object.entries(security))
220
223
  add(`@security ${[name, ...scopes].join("")}`);
221
- return content.length ? content.join("\n") : undefined;
224
+ for (const jsDocTag of route["x-nestia-jsDocTags"] ?? [])
225
+ if (jsDocTag.text?.length)
226
+ add(
227
+ `@${jsDocTag.name} ${jsDocTag.text
228
+ .map((text) => text.text)
229
+ .join("")}`,
230
+ );
231
+ else add(`@${jsDocTag.name}`);
232
+ return description?.length
233
+ ? commentTags.length
234
+ ? `${description}\n\n${commentTags.join("\n")}`
235
+ : description
236
+ : commentTags.join("\n");
222
237
  };
223
238
 
224
239
  const isNotObjectLiteral = (schema: ISwaggerSchema): boolean =>
@@ -235,14 +250,21 @@ export namespace RouteProgrammer {
235
250
 
236
251
  const emplaceBodySchema =
237
252
  (emplacer: (schema: ISwaggerSchema) => ISwaggerSchema.IReference) =>
238
- (
239
- content?: ISwaggerRoute.IContent,
240
- ): false | null | IMigrateRoute.IBody => {
241
- if (!content) return null;
253
+ (meta?: {
254
+ description?: string;
255
+ content?: ISwaggerRoute.IContent;
256
+ "x-nestia-encrypted"?: boolean;
257
+ }): false | null | IMigrateRoute.IBody => {
258
+ if (!meta?.content) return null;
242
259
 
243
260
  const entries: [string, { schema: ISwaggerSchema }][] =
244
- Object.entries(content);
245
- const json = entries.find((e) => e[0].includes("application/json"));
261
+ Object.entries(meta.content);
262
+ const json = entries.find((e) =>
263
+ meta["x-nestia-encrypted"] === true
264
+ ? e[0].includes("text/plain") ||
265
+ e[0].includes("application/json")
266
+ : e[0].includes("application/json"),
267
+ );
246
268
 
247
269
  if (json) {
248
270
  const { schema } = json[1];
@@ -251,6 +273,7 @@ export namespace RouteProgrammer {
251
273
  schema: isNotObjectLiteral(schema)
252
274
  ? schema
253
275
  : emplacer(schema),
276
+ "x-nestia-encrypted": meta["x-nestia-encrypted"],
254
277
  };
255
278
  }
256
279
 
@@ -275,7 +298,9 @@ export namespace RouteProgrammer {
275
298
  ? SchemaProgrammer.write(references)(route.response.schema)
276
299
  : "void";
277
300
  const decorator: string =
278
- route.body?.type === "text/plain"
301
+ route.body?.["x-nestia-encrypted"] === true
302
+ ? "@core.EncryptedRoute."
303
+ : route.body?.type === "text/plain"
279
304
  ? [`@Header("Content-Type", "text/plain")`, `@`].join("\n")
280
305
  : "@core.TypedRoute.";
281
306
  const content: string[] = [
@@ -293,15 +318,28 @@ export namespace RouteProgrammer {
293
318
  }`,
294
319
  `public async ${route.name}(`,
295
320
  ...route.parameters.map((p) => ` ${writeParameter(p)},`),
321
+ ...(route.headers
322
+ ? [
323
+ ` @core.TypedHeaders() headers: ${SchemaProgrammer.write(
324
+ references,
325
+ )(route.headers)},`,
326
+ ]
327
+ : []),
296
328
  ...(route.query
297
329
  ? [
298
330
  ` @core.TypedQuery() query: ${SchemaProgrammer.write(
299
331
  references,
300
- )(route.query)}`,
332
+ )(route.query)},`,
301
333
  ]
302
334
  : []),
303
335
  ...(route.body
304
- ? route.body.type === "application/json"
336
+ ? route.body["x-nestia-encrypted"] === true
337
+ ? [
338
+ ` @core.EncryptedBody() body: ${SchemaProgrammer.write(
339
+ references,
340
+ )(route.body.schema)},`,
341
+ ]
342
+ : route.body.type === "application/json"
305
343
  ? [
306
344
  ` @core.TypedBody() body: ${SchemaProgrammer.write(
307
345
  references,
@@ -313,7 +351,7 @@ export namespace RouteProgrammer {
313
351
  ...route.parameters.map(
314
352
  (p) => ` ${StringUtil.normalize(p.key)};`,
315
353
  ),
316
- // ...(route.headers ? ["headers;"] : []),
354
+ ...(route.headers ? [" headers;"] : []),
317
355
  ...(route.query ? [" query;"] : []),
318
356
  ...(route.body ? [" body;"] : []),
319
357
  ...(output !== "void"
@@ -1,3 +1,5 @@
1
+ import { IJsDocTagInfo } from "typia/lib/metadata/IJsDocTagInfo";
2
+
1
3
  import { ISwaggerSchema } from "./ISwaggeSchema";
2
4
 
3
5
  export interface IMigrateRoute {
@@ -10,6 +12,7 @@ export interface IMigrateRoute {
10
12
  body: IMigrateRoute.IBody | null;
11
13
  response: IMigrateRoute.IBody | null;
12
14
  description?: string;
15
+ "x-nestia-jsDocTags"?: IJsDocTagInfo[];
13
16
  }
14
17
  export namespace IMigrateRoute {
15
18
  export interface IParameter {
@@ -20,5 +23,6 @@ export namespace IMigrateRoute {
20
23
  export interface IBody {
21
24
  type: "text/plain" | "application/json";
22
25
  schema: ISwaggerSchema;
26
+ "x-nestia-encrypted"?: boolean;
23
27
  }
24
28
  }
@@ -1,3 +1,5 @@
1
+ import { IJsDocTagInfo } from "typia/lib/metadata/IJsDocTagInfo";
2
+
1
3
  import { ISwaggerSchema } from "./ISwaggeSchema";
2
4
 
3
5
  export interface ISwaggerRoute {
@@ -9,6 +11,7 @@ export interface ISwaggerRoute {
9
11
  deprecated?: boolean;
10
12
  security?: Record<string, string[]>[];
11
13
  tags?: string[];
14
+ "x-nestia-jsDocTags"?: IJsDocTagInfo[];
12
15
  }
13
16
  export namespace ISwaggerRoute {
14
17
  export interface IParameter {
@@ -34,7 +37,7 @@ export namespace ISwaggerRoute {
34
37
  >;
35
38
  export interface IContent {
36
39
  "text/plain"?: {
37
- schema: ISwaggerSchema.IString;
40
+ schema: ISwaggerSchema;
38
41
  };
39
42
  "application/json"?: {
40
43
  schema: ISwaggerSchema;