diff --git a/packages/openapi-generator/corpus/test-array-property.ts b/packages/openapi-generator/corpus/test-array-property.ts index b8b0d1cc..5361741a 100644 --- a/packages/openapi-generator/corpus/test-array-property.ts +++ b/packages/openapi-generator/corpus/test-array-property.ts @@ -33,7 +33,6 @@ export const Routes = h.apiSpec({ "/test": { "get": { "summary": "MyRoute", - "description": "", "parameters": [], "responses": { "200": { diff --git a/packages/openapi-generator/corpus/test-boolean-literal.ts b/packages/openapi-generator/corpus/test-boolean-literal.ts index 3b15fa20..fdba635f 100644 --- a/packages/openapi-generator/corpus/test-boolean-literal.ts +++ b/packages/openapi-generator/corpus/test-boolean-literal.ts @@ -33,7 +33,6 @@ export const Routes = h.apiSpec({ "/test": { "get": { "summary": "MyRoute", - "description": "", "parameters": [], "responses": { "200": { diff --git a/packages/openapi-generator/corpus/test-discriminated-union.ts b/packages/openapi-generator/corpus/test-discriminated-union.ts index 73017102..4b9301ff 100644 --- a/packages/openapi-generator/corpus/test-discriminated-union.ts +++ b/packages/openapi-generator/corpus/test-discriminated-union.ts @@ -36,7 +36,6 @@ export const Routes = h.apiSpec({ "/test": { "get": { "summary": "MyRoute", - "description": "", "parameters": [], "responses": { "200": { diff --git a/packages/openapi-generator/corpus/test-intersection-flattening.ts b/packages/openapi-generator/corpus/test-intersection-flattening.ts index 9759fd18..6a9f1539 100644 --- a/packages/openapi-generator/corpus/test-intersection-flattening.ts +++ b/packages/openapi-generator/corpus/test-intersection-flattening.ts @@ -33,7 +33,6 @@ export const Routes = h.apiSpec({ "/test": { "get": { "summary": "MyRoute", - "description": "", "parameters": [], "responses": { "200": { diff --git a/packages/openapi-generator/corpus/test-multi-route.ts b/packages/openapi-generator/corpus/test-multi-route.ts index b2fe2c0e..7ae476f0 100644 --- a/packages/openapi-generator/corpus/test-multi-route.ts +++ b/packages/openapi-generator/corpus/test-multi-route.ts @@ -68,7 +68,6 @@ export const Routes = h.apiSpec({ "/test/{id}/first": { "get": { "summary": "FirstRoute", - "description": "", "parameters": [ { "name": "horse", @@ -115,7 +114,6 @@ export const Routes = h.apiSpec({ "/test/{id}/second": { "get": { "summary": "SecondRoute", - "description": "", "parameters": [ { "name": "horse", diff --git a/packages/openapi-generator/corpus/test-multi-union.ts b/packages/openapi-generator/corpus/test-multi-union.ts index 0b6259fe..9ae41155 100644 --- a/packages/openapi-generator/corpus/test-multi-union.ts +++ b/packages/openapi-generator/corpus/test-multi-union.ts @@ -33,7 +33,6 @@ export const Routes = h.apiSpec({ "/test": { "get": { "summary": "MyRoute", - "description": "", "parameters": [], "responses": { "200": { diff --git a/packages/openapi-generator/corpus/test-null-param.ts b/packages/openapi-generator/corpus/test-null-param.ts index 8389ab98..1de47cad 100644 --- a/packages/openapi-generator/corpus/test-null-param.ts +++ b/packages/openapi-generator/corpus/test-null-param.ts @@ -33,7 +33,6 @@ export const Routes = h.apiSpec({ "/test": { "get": { "summary": "MyRoute", - "description": "", "parameters": [], "responses": { "200": { diff --git a/packages/openapi-generator/corpus/test-optional-property.ts b/packages/openapi-generator/corpus/test-optional-property.ts index 12f8a4c9..f06f920d 100644 --- a/packages/openapi-generator/corpus/test-optional-property.ts +++ b/packages/openapi-generator/corpus/test-optional-property.ts @@ -38,11 +38,9 @@ export const Routes = h.apiSpec({ "/test": { "get": { "summary": "MyRoute", - "description": "", "parameters": [ { "name": "req", - "description": "", "schema": { "type": "string" }, @@ -51,7 +49,6 @@ export const Routes = h.apiSpec({ }, { "name": "opt", - "description": "", "schema": { "type": "string" }, diff --git a/packages/openapi-generator/corpus/test-record-type.ts b/packages/openapi-generator/corpus/test-record-type.ts index 1553ab83..25fd32fb 100644 --- a/packages/openapi-generator/corpus/test-record-type.ts +++ b/packages/openapi-generator/corpus/test-record-type.ts @@ -33,7 +33,6 @@ export const Routes = h.apiSpec({ "/test": { "get": { "summary": "MyRoute", - "description": "", "parameters": [], "responses": { "200": { diff --git a/packages/openapi-generator/corpus/test-single-route-multi-method.ts b/packages/openapi-generator/corpus/test-single-route-multi-method.ts index 8ace87b2..52e182a3 100644 --- a/packages/openapi-generator/corpus/test-single-route-multi-method.ts +++ b/packages/openapi-generator/corpus/test-single-route-multi-method.ts @@ -59,7 +59,6 @@ export const Routes = h.apiSpec({ "/test/{id}": { "get": { "summary": "FirstRoute", - "description": "", "parameters": [ { "name": "id", @@ -86,7 +85,6 @@ export const Routes = h.apiSpec({ }, "post": { "summary": "SecondRoute", - "description": "", "parameters": [ { "name": "id", diff --git a/packages/openapi-generator/corpus/test-string-union.ts b/packages/openapi-generator/corpus/test-string-union.ts index a86cc082..70f0bb9a 100644 --- a/packages/openapi-generator/corpus/test-string-union.ts +++ b/packages/openapi-generator/corpus/test-string-union.ts @@ -33,7 +33,6 @@ export const Routes = h.apiSpec({ "/test": { "get": { "summary": "MyRoute", - "description": "", "parameters": [], "responses": { "200": { diff --git a/packages/openapi-generator/corpus/test-unknown-property.ts b/packages/openapi-generator/corpus/test-unknown-property.ts index 11c540e8..3a68a2d0 100644 --- a/packages/openapi-generator/corpus/test-unknown-property.ts +++ b/packages/openapi-generator/corpus/test-unknown-property.ts @@ -40,7 +40,6 @@ export const Routes = h.apiSpec({ "/test/{id}": { "post": { "summary": "MyRoute", - "description": "", "parameters": [ { "name": "id", diff --git a/packages/openapi-generator/corpus/test-version-tag.ts b/packages/openapi-generator/corpus/test-version-tag.ts index be50af66..d1b7a917 100644 --- a/packages/openapi-generator/corpus/test-version-tag.ts +++ b/packages/openapi-generator/corpus/test-version-tag.ts @@ -38,7 +38,6 @@ export const Routes = h.apiSpec({ "/test": { "get": { "summary": "MyRoute", - "description": "", "parameters": [], "responses": { "200": { diff --git a/packages/openapi-generator/src/project.ts b/packages/openapi-generator/src/project.ts index 587a6b96..2a42c373 100644 --- a/packages/openapi-generator/src/project.ts +++ b/packages/openapi-generator/src/project.ts @@ -1,4 +1,4 @@ -import { flow, pipe } from 'fp-ts/function'; +import { pipe } from 'fp-ts/function'; import * as A from 'fp-ts/Alt'; import * as RA from 'fp-ts/ReadonlyArray'; import * as E from 'fp-ts/Either'; @@ -55,65 +55,63 @@ const routesForSymbol = variableDeclarationOfSymbol(sym), E.chain(schemaForApiSpec(memo)), E.map( - flow( - RA.reduce( - {}, - ( - paths: PathSpec, - { - path, - method, - query, - params, - body, - responses, - summary, - description, - isPrivate, - }, - ) => - isPrivate && !includeInternal - ? paths - : { - ...paths, - [path]: { - ...paths[path], - [method]: { - summary, - description, - ...(isPrivate ? { 'x-internal': true } : {}), - parameters: [ - ...(query as ParameterList), - ...(params as ParameterList), - ], - responses: responses.reduce( - (acc, { code, schema: { schema } }) => ({ - ...acc, - [code]: { - description: '', - content: { - 'application/json': { schema }, - }, + RA.reduce( + {}, + ( + paths: PathSpec, + { + path, + method, + query, + params, + body, + responses, + summary, + description, + isPrivate, + }, + ) => + isPrivate && !includeInternal + ? paths + : { + ...paths, + [path]: { + ...paths[path], + [method]: { + summary, + ...(description !== undefined ? { description } : {}), + ...(isPrivate ? { 'x-internal': true } : {}), + parameters: [ + ...(query as ParameterList), + ...(params as ParameterList), + ], + responses: responses.reduce( + (acc, { code, schema: { schema } }) => ({ + ...acc, + [code]: { + description: '', // DISCUSS: This field actually is required, is there a better default for this? + content: { + 'application/json': { schema }, }, - }), - {}, - ), - ...(body !== undefined - ? { - requestBody: { - content: { - 'application/json': { - schema: body.schema, - }, + }, + }), + {}, + ), + ...(body !== undefined + ? { + requestBody: { + content: { + 'application/json': { + schema: body.schema, }, - required: body.required, }, - } - : {}), - }, + required: body.required, + }, + } + : {}), }, }, - ), + }, ), ), ); diff --git a/packages/openapi-generator/src/route.ts b/packages/openapi-generator/src/route.ts index 7bfe68ad..d1f81827 100644 --- a/packages/openapi-generator/src/route.ts +++ b/packages/openapi-generator/src/route.ts @@ -101,7 +101,9 @@ const parametersFromCodecOutputSym = (paramIn: 'query' | 'path') => schema, required, in: paramIn, - description: description[description.length - 1] ?? '', + ...(description.length > 0 + ? { description: description[description.length - 1] } + : {}), })), ), ), @@ -150,7 +152,7 @@ const routeSummary = (init: Node) => { } }; -const routeDescription = (init: Node) => { +const routeDescription = (init: Node): { description?: string; isPrivate: boolean } => { return pipe( E.fromNullable('No symbol for initializer')(init.getSymbol()), E.chain((sym) => @@ -158,7 +160,7 @@ const routeDescription = (init: Node) => { (sym.getAliasedSymbol() ?? sym).getValueDeclaration(), ), ), - E.chain((decl) => { + E.chain((decl): E.Either => { let current: Node | undefined = decl; while (current !== undefined) { const comments = current.getLeadingCommentRanges(); @@ -182,7 +184,7 @@ const routeDescription = (init: Node) => { } return E.left('no comment found'); }), - E.getOrElse(() => ({ description: '', isPrivate: false })), + E.getOrElseW(() => ({ isPrivate: false })), ); };