Skip to content

Commit

Permalink
fix(openapi-v3): set required to true for path parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Aug 21, 2018
1 parent abb1dc4 commit 2b13247
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/openapi-v3/src/controller-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ function resolveControllerSpec(constructor: Function): ControllerSpec {
* }
* ```
*/
operationSpec.parameters = params.filter(p => p != null);
operationSpec.parameters = params.filter(p => p != null).map(p => {
// Per OpenAPI spec, `required` must be `true` for path parameters
if (p.in === 'path') {
p.required = true;
}
return p;
});
}

debug(' processing requestBody for method %s', op);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ describe('operation arguments', () => {
parameters: [
{name: 'type', in: 'query', schema: {type: 'string'}},
{name: 'token', in: 'header', schema: {type: 'string'}},
{name: 'location', in: 'path', schema: {type: 'string'}},
{
name: 'location',
in: 'path',
required: true,
schema: {type: 'string'},
},
],
requestBody: {
content: {
Expand All @@ -60,6 +65,7 @@ describe('operation arguments', () => {
},
},
};
expect(getControllerSpec(MyController)).to.eql(expectedSpec);
const spec = getControllerSpec(MyController);
expect(spec).to.eql(expectedSpec);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Routing metadata for parameters', () => {
const expectedParamSpec = {
name: 'name',
in: 'path',
required: true,
schema: {
type: 'string',
},
Expand All @@ -33,6 +34,7 @@ describe('Routing metadata for parameters', () => {
const expectedParamSpec = {
name: 'name',
in: 'path',
required: true,
schema: {
type: 'number',
},
Expand All @@ -50,6 +52,7 @@ describe('Routing metadata for parameters', () => {
const expectedParamSpec = {
name: 'name',
in: 'path',
required: true,
schema: {
type: 'integer',
format: 'int32',
Expand All @@ -72,6 +75,7 @@ describe('Routing metadata for parameters', () => {
{
name: 'name',
in: 'path',
required: true,
schema: {
type: 'boolean',
},
Expand All @@ -89,6 +93,7 @@ describe('Routing metadata for parameters', () => {
const expectedParamSpec = {
name: 'name',
in: 'path',
required: true,
schema: {
type: 'integer',
format: 'int64',
Expand All @@ -107,6 +112,7 @@ describe('Routing metadata for parameters', () => {
const expectedParamSpec = {
name: 'name',
in: 'path',
required: true,
schema: {
type: 'number',
format: 'float',
Expand All @@ -125,6 +131,7 @@ describe('Routing metadata for parameters', () => {
const expectedParamSpec = {
name: 'name',
in: 'path',
required: true,
schema: {
type: 'number',
format: 'double',
Expand All @@ -143,6 +150,7 @@ describe('Routing metadata for parameters', () => {
const expectedParamSpec = {
name: 'name',
in: 'path',
required: true,
schema: {
type: 'string',
format: 'byte',
Expand All @@ -161,6 +169,7 @@ describe('Routing metadata for parameters', () => {
const expectedParamSpec = {
name: 'name',
in: 'path',
required: true,
schema: {
type: 'string',
format: 'binary',
Expand All @@ -179,6 +188,7 @@ describe('Routing metadata for parameters', () => {
const expectedParamSpec = {
name: 'name',
in: 'path',
required: true,
schema: {
type: 'string',
format: 'date',
Expand All @@ -197,6 +207,7 @@ describe('Routing metadata for parameters', () => {
const expectedParamSpec = {
name: 'name',
in: 'path',
required: true,
schema: {
type: 'string',
format: 'date-time',
Expand All @@ -215,6 +226,7 @@ describe('Routing metadata for parameters', () => {
const expectedParamSpec = {
name: 'name',
in: 'path',
required: true,
schema: {
type: 'string',
format: 'password',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('Routing metadata for parameters', () => {
@param({
name: 'id',
in: 'path',
required: true,
})
id: string,
@param({
Expand Down Expand Up @@ -80,6 +81,7 @@ describe('Routing metadata for parameters', () => {
type: 'string',
},
in: 'path',
required: true,
})
.withParameter({
name: 'name',
Expand Down
1 change: 1 addition & 0 deletions packages/rest/test/unit/parser.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('operationArgsParser', () => {
name: 'id',
type: 'number',
in: 'path',
required: true,
},
]);
const route = givenResolvedRoute(spec, {id: 1});
Expand Down

0 comments on commit 2b13247

Please sign in to comment.