Skip to content

Commit

Permalink
fix: modify tests for query objects with spec deepObject to content
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakrkris committed Dec 31, 2019
1 parent 1ab2fd4 commit 084cbcc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
14 changes: 8 additions & 6 deletions packages/rest/src/__tests__/unit/coercion/paramObject.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import {test} from './utils';
const OPTIONAL_ANY_OBJECT: ParameterObject = {
in: 'query',
name: 'aparameter',
schema: {
type: 'object',
additionalProperties: true,
},
style: 'deepObject',
explode: true,
content: {
'application/json': {
schema: {
type: 'object',
additionalProperties: true,
},
}
}
};

const REQUIRED_ANY_OBJECT = {
Expand Down
8 changes: 5 additions & 3 deletions packages/rest/src/__tests__/unit/parser.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,11 @@ describe('operationArgsParser', () => {
{
name,
in: 'query',
style: 'deepObject',
explode: true,
schema,
content: {
'application/json': {
schema,
},
}
},
]);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/rest/src/coercion/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ export class Validator {
isAbsent(value: any) {
if (value === '' || value === undefined) return true;

const spec: ParameterObject = this.ctx.parameterSpec;
const schema: SchemaObject = this.ctx.parameterSpec.schema ?? {};
if (schema.type === 'object' && value === 'null') return true;

// if parameter is a query param and an object, validate for null values
if ((!spec.schema && spec.in === 'query' && spec.content) && (value === 'null' || value === null)) return true;

return false;
}
}

0 comments on commit 084cbcc

Please sign in to comment.