From 9e90e7baf7b771d735f75df74034457cc4065ad4 Mon Sep 17 00:00:00 2001 From: "K.Himeno" Date: Thu, 18 Feb 2021 17:08:36 +0900 Subject: [PATCH] feat(comment): Use the defined comment (#19) --- src/Converter/v3/components/Header.ts | 1 - src/Converter/v3/components/Headers.ts | 1 - src/Converter/v3/components/MediaType.ts | 2 +- src/Converter/v3/components/Parameter.ts | 5 +-- src/Converter/v3/components/Parameters.ts | 2 -- src/Converter/v3/components/PathItems.ts | 1 - src/Converter/v3/components/RequestBodies.ts | 1 - src/Converter/v3/components/RequestBody.ts | 1 - src/Converter/v3/components/Responses.ts | 2 -- src/Converter/v3/components/Schema.ts | 1 + src/Converter/v3/components/Schemas.ts | 1 - .../v3/components/SecuritySchemas.ts | 1 - .../__snapshots__/snapshot-test.ts.snap | 34 ++++--------------- .../ForPathItems/FullRemoteReference.yml | 2 +- .../ForPathItems/FullRemoteReference.yml | 1 + .../components/responses/ResponseA.yml | 1 + 16 files changed, 14 insertions(+), 43 deletions(-) diff --git a/src/Converter/v3/components/Header.ts b/src/Converter/v3/components/Header.ts index 7eab25d3..6a6f702f 100644 --- a/src/Converter/v3/components/Header.ts +++ b/src/Converter/v3/components/Header.ts @@ -84,7 +84,6 @@ export const generateInterface = ( return factory.InterfaceDeclaration.create({ export: true, name: converterContext.escapeDeclarationText(name), - comment: `@see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#headerObject`, members: generatePropertySignatures(entryPoint, currentPoint, factory, headers, context, converterContext), }); }; diff --git a/src/Converter/v3/components/Headers.ts b/src/Converter/v3/components/Headers.ts index 5c463e0f..12d23463 100644 --- a/src/Converter/v3/components/Headers.ts +++ b/src/Converter/v3/components/Headers.ts @@ -22,7 +22,6 @@ export const generateNamespace = ( store.addComponent("headers", { kind: "namespace", name: Name.Components.Headers, - comment: `@see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#componentsObject`, }); Object.entries(headers).forEach(([name, header]) => { if (Guard.isReference(header)) { diff --git a/src/Converter/v3/components/MediaType.ts b/src/Converter/v3/components/MediaType.ts index 86e10913..db3c0d49 100644 --- a/src/Converter/v3/components/MediaType.ts +++ b/src/Converter/v3/components/MediaType.ts @@ -18,6 +18,7 @@ export const generatePropertySignature = ( name: converterContext.escapePropertySignatureName(protocol), optional: false, type: ToTypeNode.convert(entryPoint, currentPoint, factory, schema, context, converterContext), + comment: schema.description, }); }; @@ -50,6 +51,5 @@ export const generateInterface = ( export: true, name, members: generatePropertySignatures(entryPoint, currentPoint, factory, content, context, converterContext), - comment: `@see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#mediaTypeObject`, }); }; diff --git a/src/Converter/v3/components/Parameter.ts b/src/Converter/v3/components/Parameter.ts index 7c600ed5..c97346d4 100644 --- a/src/Converter/v3/components/Parameter.ts +++ b/src/Converter/v3/components/Parameter.ts @@ -53,6 +53,7 @@ export const generatePropertySignature = ( return factory.PropertySignature.create({ name: converterContext.escapePropertySignatureName(localRef.name), optional: false, + comment: localRef.description, type: factory.TypeReferenceNode.create({ name: context.resolveReferencePath(currentPoint, reference.path).name, }), @@ -62,6 +63,7 @@ export const generatePropertySignature = ( return factory.PropertySignature.create({ name: converterContext.escapePropertySignatureName(reference.data.name), optional: isPathProperty ? false : !reference.data.required, + comment: reference.data.description, type: ToTypeNode.convert( entryPoint, reference.referencePoint, @@ -77,6 +79,7 @@ export const generatePropertySignature = ( name: converterContext.escapePropertySignatureName(parameter.name), optional: isPathProperty ? false : !parameter.required, type: ToTypeNode.convert(entryPoint, currentPoint, factory, parameter.schema || { type: "null" }, context, converterContext), + comment: parameter.description, }); }; @@ -107,7 +110,6 @@ export const generateInterface = ( return factory.InterfaceDeclaration.create({ export: true, name, - comment: `@see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#headerObject`, members: generatePropertySignatures(entryPoint, currentPoint, store, factory, parameters, context, converterContext), }); }; @@ -128,7 +130,6 @@ export const generateAliasInterface = ( return factory.InterfaceDeclaration.create({ export: true, name: converterContext.escapeDeclarationText(name), - comment: `@see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#headerObject`, members: generatePropertySignatures(entryPoint, currentPoint, store, factory, parameters, context, converterContext), }); }; diff --git a/src/Converter/v3/components/Parameters.ts b/src/Converter/v3/components/Parameters.ts index de2cdcfe..f7ef0d72 100644 --- a/src/Converter/v3/components/Parameters.ts +++ b/src/Converter/v3/components/Parameters.ts @@ -23,7 +23,6 @@ export const generateNamespace = ( store.addComponent("parameters", { kind: "namespace", name: Name.Components.Parameters, - comment: `@see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#parameterObject`, }); Object.entries(parameters).forEach(([name, parameter]) => { @@ -81,7 +80,6 @@ export const generateNamespaceWithList = ( store.addComponent("parameters", { kind: "namespace", name: Name.Components.Parameters, - comment: `@see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#parameterObject`, }); parameters.forEach(parameter => { diff --git a/src/Converter/v3/components/PathItems.ts b/src/Converter/v3/components/PathItems.ts index 24cbd37e..9a71cbf7 100644 --- a/src/Converter/v3/components/PathItems.ts +++ b/src/Converter/v3/components/PathItems.ts @@ -24,7 +24,6 @@ export const generateNamespace = ( store.addComponent("pathItems", { kind: "namespace", name: Name.Components.PathItems, - comment: `@see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#componentsObject`, }); Object.entries(pathItems).forEach(([key, pathItem]) => { diff --git a/src/Converter/v3/components/RequestBodies.ts b/src/Converter/v3/components/RequestBodies.ts index 0c986b50..d9b0c2bb 100644 --- a/src/Converter/v3/components/RequestBodies.ts +++ b/src/Converter/v3/components/RequestBodies.ts @@ -23,7 +23,6 @@ export const generateNamespace = ( store.addComponent("requestBodies", { kind: "namespace", name: Name.Components.RequestBodies, - comment: `@see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#componentsObject`, }); Object.entries(requestBodies).forEach(([name, requestBody]) => { diff --git a/src/Converter/v3/components/RequestBody.ts b/src/Converter/v3/components/RequestBody.ts index 018db121..8cf4e168 100644 --- a/src/Converter/v3/components/RequestBody.ts +++ b/src/Converter/v3/components/RequestBody.ts @@ -28,7 +28,6 @@ export const generateInterface = ( export: true, name, members: contentSignatures, - comment: `@see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#requestBodyObject`, }); }; diff --git a/src/Converter/v3/components/Responses.ts b/src/Converter/v3/components/Responses.ts index 8025c660..64c920a7 100644 --- a/src/Converter/v3/components/Responses.ts +++ b/src/Converter/v3/components/Responses.ts @@ -27,7 +27,6 @@ export const generateNamespace = ( store.addComponent("responses", { kind: "namespace", name: Name.Components.Responses, - comment: `@see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#responsesObject`, }); Object.entries(responses).forEach(([name, response]) => { if (Guard.isReference(response)) { @@ -69,7 +68,6 @@ export const generateNamespaceWithStatusCode = ( store.addStatement(basePath, { kind: "namespace", name: Name.ComponentChild.Response, - comment: `@see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#responsesObject`, }); Object.entries(responses).forEach(([statusCode, response]) => { diff --git a/src/Converter/v3/components/Schema.ts b/src/Converter/v3/components/Schema.ts index 7eacc1f1..e7f8c507 100644 --- a/src/Converter/v3/components/Schema.ts +++ b/src/Converter/v3/components/Schema.ts @@ -26,6 +26,7 @@ export const generatePropertySignatures = ( return factory.PropertySignature.create({ name: convertContext.escapePropertySignatureName(propertyName), optional: !required.includes(propertyName), + comment: schema.description, type: factory.TypeNode.create({ type: "any", }), diff --git a/src/Converter/v3/components/Schemas.ts b/src/Converter/v3/components/Schemas.ts index e823bb85..f70a3d69 100644 --- a/src/Converter/v3/components/Schemas.ts +++ b/src/Converter/v3/components/Schemas.ts @@ -39,7 +39,6 @@ export const generateNamespace = ( store.addComponent("schemas", { kind: "namespace", name: Name.Components.Schemas, - comment: `@see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#schemaObject`, }); Object.entries(schemas).forEach(([name, targetSchema]) => { if (Guard.isReference(targetSchema)) { diff --git a/src/Converter/v3/components/SecuritySchemas.ts b/src/Converter/v3/components/SecuritySchemas.ts index 7f9b4f00..326a823b 100644 --- a/src/Converter/v3/components/SecuritySchemas.ts +++ b/src/Converter/v3/components/SecuritySchemas.ts @@ -17,7 +17,6 @@ export const generateNamespace = ( store.addComponent("securitySchemes", { kind: "namespace", name: Name.Components.SecuritySchemas, - comment: `@see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#securitySchemeObject`, }); Object.entries(requestBodies).forEach(([name, requestBody]) => { if (Guard.isReference(requestBody)) { diff --git a/test/__tests__/__snapshots__/snapshot-test.ts.snap b/test/__tests__/__snapshots__/snapshot-test.ts.snap index f32a3fbf..ac18dcef 100644 --- a/test/__tests__/__snapshots__/snapshot-test.ts.snap +++ b/test/__tests__/__snapshots__/snapshot-test.ts.snap @@ -10,7 +10,6 @@ exports[`Generate Code Snapshot Test api.test.domain 1`] = ` // -/** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#schemaObject */ export namespace Schemas { /** String Literal */ export type StringType = string; @@ -128,7 +127,6 @@ export namespace Schemas { children: Child[]; } } -/** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#componentsObject */ export namespace Headers { export type StringHeader = string; export type A = number; @@ -137,7 +135,6 @@ export namespace Headers { } export type ReferenceOfHeaderToSchema = Schemas.DirectRef.ForHeader; } -/** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#responsesObject */ export namespace Responses { /** * Status Code 100 @@ -151,35 +148,31 @@ export namespace Responses { export namespace SwitchingProtocol { } /** Type Reference - string */ export namespace LocalReferenceStringDateTimeType { - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#mediaTypeObject */ export interface Content { \\"application/json\\": Schemas.StringDateTimeType; } } /** Local Reference - object */ export namespace LocalReferenceObjectType { - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#mediaTypeObject */ export interface Content { \\"application/json\\": Schemas.ObjectHasPropertiesType; } } /** Response -> Schema */ export namespace ReferenceOfResponseToSchema { - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#mediaTypeObject */ export interface Content { \\"application/json\\": Schemas.DirectRef.ForResponse; } } /** response A definition */ export namespace ResponseA { - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#headerObject */ export interface Header { HeaderA: Headers.A; HeaderB: string; } - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#mediaTypeObject */ export interface Content { \\"application/json\\": { + /** responseA description */ name?: \\"responseA\\"; }; } @@ -187,7 +180,6 @@ export namespace Responses { export namespace Level1 { /** response B definition */ export namespace ResponseB { - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#mediaTypeObject */ export interface Content { \\"application/json\\": { name?: \\"responseB\\"; @@ -197,7 +189,6 @@ export namespace Responses { export namespace Level2 { /** response C definition */ export namespace ResponseC { - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#mediaTypeObject */ export interface Content { \\"application/json\\": { name?: \\"responseC\\"; @@ -209,21 +200,19 @@ export namespace Responses { export namespace ForPathItems { /** response A definition */ export namespace FullRemoteReference { - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#headerObject */ export interface Header { HeaderA: Headers.A; HeaderB: string; } - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#mediaTypeObject */ export interface Content { \\"application/json\\": { + /** responseA description */ name?: \\"responseA\\"; }; } } } } -/** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#parameterObject */ export namespace Parameters { /** parameters.StringQueryParams */ export type StringQueryParams = string; @@ -250,32 +239,27 @@ export namespace Parameters { }; }; } -/** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#componentsObject */ export namespace RequestBodies { /** Request body string type */ export namespace StringType { - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#requestBodyObject */ export interface Content { \\"application/json\\": string; } } /** Request body Local reference string type */ export namespace LocalReferenceStringType { - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#requestBodyObject */ export interface Content { \\"application/json\\": Schemas.StringHasEnumType; } } /** requestBodies -> schemas */ export namespace ReferenceOfRequestBodyToSchema { - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#requestBodyObject */ export interface Content { \\"application/json\\": Schemas.DirectRef.ForRequestBody; } } /** Remote Request body A */ export namespace RequestBodyA { - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#requestBodyObject */ export interface Content { \\"application/json\\": { body?: string; @@ -285,7 +269,6 @@ export namespace RequestBodies { export namespace Level1 { /** Remote Request body B */ export namespace RequestBodyB { - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#requestBodyObject */ export interface Content { \\"application/json\\": { body?: string; @@ -295,7 +278,6 @@ export namespace RequestBodies { export namespace Level2 { /** Remote Request body C */ export namespace RequestBodyC { - /** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#requestBodyObject */ export interface Content { \\"application/json\\": { body?: string; @@ -305,35 +287,32 @@ export namespace RequestBodies { } } } -/** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#headerObject */ export interface Parameter$getIncludeLocalReference { + /** parameters.StringQueryParams */ StringQuery: string; } -/** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#mediaTypeObject */ export interface Response$getIncludeLocalReference$Status$200 { \\"application/json\\": { meta: string; }; } -/** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#headerObject */ export interface Parameter$getIncludeRemoteReference { + /** remote reference parameter */ IncludeRemoteReference: number; } -/** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#requestBodyObject */ export interface RequestBody$getIncludeRemoteReference { \\"application/json\\": string; } -/** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#headerObject */ export interface Parameter$getFullRemoteReference { + /** Full Remote Reference */ FullRemoteReferenceQuery: Schemas.FullRemoteReference.ForParameters; } -/** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#mediaTypeObject */ export interface Response$getFullRemoteReference$Status$200 { \\"application/json\\": { + /** responseA description */ name?: \\"responseA\\"; }; } -/** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#mediaTypeObject */ export interface Response$getReferenceItems$Status$200 { \\"application/json\\": { books?: Schemas.Item[]; @@ -422,7 +401,6 @@ exports[`Generate Code Snapshot Test infer.domain 1`] = ` // -/** @see /~https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#schemaObject */ export namespace Schemas { export type InferArrayEmptyItems = {}[]; export type InferArrayType = string[]; diff --git a/test/api.test.domain/components/parameters/ForPathItems/FullRemoteReference.yml b/test/api.test.domain/components/parameters/ForPathItems/FullRemoteReference.yml index 6e3b8bee..cb6ef703 100644 --- a/test/api.test.domain/components/parameters/ForPathItems/FullRemoteReference.yml +++ b/test/api.test.domain/components/parameters/ForPathItems/FullRemoteReference.yml @@ -1,6 +1,6 @@ name: FullRemoteReferenceQuery in: query -description: Full Remote REference +description: Full Remote Reference required: true schema: $ref: "../../schemas/FullRemoteReference/ForParameters.yml" diff --git a/test/api.test.domain/components/responses/ForPathItems/FullRemoteReference.yml b/test/api.test.domain/components/responses/ForPathItems/FullRemoteReference.yml index 8396c337..7741c7d3 100644 --- a/test/api.test.domain/components/responses/ForPathItems/FullRemoteReference.yml +++ b/test/api.test.domain/components/responses/ForPathItems/FullRemoteReference.yml @@ -14,3 +14,4 @@ content: name: type: string enum: [responseA] + description: responseA description diff --git a/test/api.test.domain/components/responses/ResponseA.yml b/test/api.test.domain/components/responses/ResponseA.yml index 6282679b..aa4c3d4e 100644 --- a/test/api.test.domain/components/responses/ResponseA.yml +++ b/test/api.test.domain/components/responses/ResponseA.yml @@ -14,3 +14,4 @@ content: name: type: string enum: [responseA] + description: responseA description