Skip to content

Commit 38e4f3e

Browse files
committed
feat: spike on url encoding of json object in query param
1 parent fe83941 commit 38e4f3e

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

examples/todo/src/__tests__/acceptance/todo.acceptance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ describe('TodoApplication', () => {
189189

190190
await client
191191
.get('/todos')
192-
.query({filter: {where: {isComplete: false}}})
192+
.query({filter: encodeURIComponent(JSON.stringify({where: {isComplete: false}})) })
193193
.expect(200, [toJSON(todoInProgress)]);
194194
});
195195

examples/todo/src/controllers/todo.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class TodoController {
8484
},
8585
})
8686
async findTodos(
87-
@param.query.object('filter', getFilterSchemaFor(Todo))
87+
@param.query.jsonObject('filter', getFilterSchemaFor(Todo))
8888
filter?: Filter<Todo>,
8989
): Promise<Todo[]> {
9090
return this.todoRepo.find(filter);

packages/openapi-v3/src/decorators/parameter.decorator.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,47 @@ export namespace param {
218218
...spec,
219219
});
220220
},
221+
222+
/**
223+
* Define a parameter accepting a url encoded string of a JSON object,
224+
*
225+
* parameter is created with explode: false
226+
*
227+
* @param name - Parameter name
228+
* @param schema - Optional OpenAPI Schema describing the JSON object.
229+
*/
230+
jsonObject: function(
231+
name: string,
232+
schema: SchemaObject | ReferenceObject = {
233+
type: 'object',
234+
additionalProperties: true,
235+
},
236+
spec?: Partial<ParameterObject>,
237+
) {
238+
239+
schema = {
240+
type: 'object',
241+
...schema,
242+
};
243+
244+
let content = {
245+
"application/json": {
246+
schema
247+
}
248+
}
249+
250+
return param({
251+
name,
252+
in: 'query',
253+
style: 'deepObject',
254+
explode: false,
255+
content: content,
256+
...spec,
257+
});
258+
},
221259
};
222260

261+
223262
/**
224263
* Header parameter decorator
225264
*/

0 commit comments

Comments
 (0)