Skip to content

Commit

Permalink
feat: spike on url encoding of json object in query param
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakrkris committed Nov 19, 2019
1 parent fe83941 commit 2649c50
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/todo/src/__tests__/acceptance/todo.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe('TodoApplication', () => {

await client
.get('/todos')
.query({filter: {where: {isComplete: false}}})
.query({filter: encodeURIComponent(JSON.stringify({where: {isComplete: false}})) })
.expect(200, [toJSON(todoInProgress)]);
});

Expand Down
2 changes: 1 addition & 1 deletion examples/todo/src/controllers/todo.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class TodoController {
},
})
async findTodos(
@param.query.object('filter', getFilterSchemaFor(Todo))
@param.query.jsonObject('filter', getFilterSchemaFor(Todo))
filter?: Filter<Todo>,
): Promise<Todo[]> {
return this.todoRepo.find(filter);
Expand Down
35 changes: 35 additions & 0 deletions packages/openapi-v3/src/decorators/parameter.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,43 @@ export namespace param {
...spec,
});
},

/**
* Define a parameter accepting a url encoded string of a JSON object,
*
* parameter is created with explode: false
*
* @param name - Parameter name
* @param schema - Optional OpenAPI Schema describing the JSON object.
*/
jsonObject: function(
name: string,
schema: SchemaObject | ReferenceObject = {
type: 'object',
additionalProperties: true,
},
spec?: Partial<ParameterObject>,
) {

schema = {
type: 'object',
...schema,
};

return param({
name,
in: 'query',
content: {
"application/json": {
schema
}
}
...spec,
});
},
};


/**
* Header parameter decorator
*/
Expand Down

0 comments on commit 2649c50

Please sign in to comment.