Skip to content

Commit c21643b

Browse files
Merge pull request #715 from bitgopatmcl/VL-1839-no-required-false
2 parents b0b5ecb + da78e7e commit c21643b

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

packages/openapi-generator/src/openapi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function routeToOpenAPI(route: Route): [string, string, OpenAPIV3.OperationObjec
147147
? { description: p.schema.comment.description }
148148
: {}),
149149
in: p.type,
150-
required: p.required,
150+
...(p.required ? { required: true } : {}),
151151
...(p.explode ? { style: 'form', explode: true } : {}),
152152
schema: schema as any, // TODO: Something to disallow arrays
153153
};

packages/openapi-generator/test/openapi.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,3 +819,60 @@ testCase('schema parameter with title tag', TITLE_TAG, {
819819
schemas: {},
820820
},
821821
});
822+
823+
const OPTIONAL_PARAM = `
824+
import * as t from 'io-ts';
825+
import * as h from '@api-ts/io-ts-http';
826+
827+
export const route = h.httpRoute({
828+
path: '/foo',
829+
method: 'GET',
830+
request: h.httpRequest({
831+
query: {
832+
foo: h.optional(t.string),
833+
},
834+
}),
835+
response: {
836+
/** foo response */
837+
200: t.string
838+
},
839+
});
840+
`;
841+
842+
testCase('optional parameter', OPTIONAL_PARAM, {
843+
openapi: '3.0.3',
844+
info: {
845+
title: 'Test',
846+
version: '1.0.0',
847+
},
848+
paths: {
849+
'/foo': {
850+
get: {
851+
parameters: [
852+
{
853+
in: 'query',
854+
name: 'foo',
855+
schema: {
856+
type: 'string',
857+
},
858+
},
859+
],
860+
responses: {
861+
200: {
862+
description: 'foo response',
863+
content: {
864+
'application/json': {
865+
schema: {
866+
type: 'string',
867+
},
868+
},
869+
},
870+
},
871+
},
872+
},
873+
},
874+
},
875+
components: {
876+
schemas: {},
877+
},
878+
});

0 commit comments

Comments
 (0)