|
1 | 1 | import { ApiOperation, ApiQuery, ApiResponse } from '@nestjs/swagger';
|
2 | 2 | import { Type } from '@nestjs/common';
|
3 |
| -import { ObjectTyped, EntityClass } from '@klerick/json-api-nestjs-shared'; |
| 3 | +import { |
| 4 | + ObjectTyped, |
| 5 | + EntityClass, |
| 6 | + FilterOperand, |
| 7 | +} from '@klerick/json-api-nestjs-shared'; |
4 | 8 |
|
5 | 9 | import {
|
6 | 10 | assertIsKeysOfObject,
|
@@ -72,13 +76,44 @@ export function getAll<E extends object, IdKey extends string = 'id'>(
|
72 | 76 | },
|
73 | 77 | description: `Object of field for select field from "${entity.name}" resource`,
|
74 | 78 | })(controller, methodName, descriptor);
|
75 |
| - |
| 79 | + // https://github.com/OAI/OpenAPI-Specification/issues/1706#issuecomment-2704374644 need wait fix deepObject |
76 | 80 | ApiQuery({
|
77 | 81 | name: 'filter',
|
78 | 82 | required: false,
|
79 | 83 | style: 'deepObject',
|
80 | 84 | schema: {
|
81 | 85 | type: 'object',
|
| 86 | + properties: { |
| 87 | + ...props.reduce((acum, i) => { |
| 88 | + Reflect.set(acum, String(i), { |
| 89 | + type: 'object', |
| 90 | + properties: Object.keys(FilterOperand).reduce((acum, name) => { |
| 91 | + Reflect.set(acum, String(name), { |
| 92 | + type: 'string', |
| 93 | + }); |
| 94 | + return acum; |
| 95 | + }, {}), |
| 96 | + minProperties: 1, |
| 97 | + additionalProperties: false, |
| 98 | + }); |
| 99 | + return acum; |
| 100 | + }, {}), |
| 101 | + ...relationTree.reduce((acum, i) => { |
| 102 | + Reflect.set(acum, String(i), { |
| 103 | + type: 'object', |
| 104 | + properties: Object.keys(FilterOperand).reduce((acum, name) => { |
| 105 | + Reflect.set(acum, String(name), { |
| 106 | + type: 'string', |
| 107 | + }); |
| 108 | + return acum; |
| 109 | + }, {}), |
| 110 | + minProperties: 1, |
| 111 | + additionalProperties: false, |
| 112 | + }); |
| 113 | + return acum; |
| 114 | + }, {}), |
| 115 | + }, |
| 116 | + additionalProperties: false, |
82 | 117 | },
|
83 | 118 | examples: {
|
84 | 119 | simpleExample: {
|
@@ -204,16 +239,20 @@ export function getAll<E extends object, IdKey extends string = 'id'>(
|
204 | 239 | required: false,
|
205 | 240 | schema: {
|
206 | 241 | type: 'object',
|
| 242 | + examples: [ |
| 243 | + { |
| 244 | + number: DEFAULT_QUERY_PAGE, |
| 245 | + size: DEFAULT_PAGE_SIZE, |
| 246 | + }, |
| 247 | + ], |
207 | 248 | properties: {
|
208 | 249 | number: {
|
209 | 250 | type: 'integer',
|
210 | 251 | minimum: 1,
|
211 |
| - example: DEFAULT_QUERY_PAGE, |
212 | 252 | },
|
213 | 253 | size: {
|
214 | 254 | type: 'integer',
|
215 | 255 | minimum: 1,
|
216 |
| - example: DEFAULT_PAGE_SIZE, |
217 | 256 | maximum: 500,
|
218 | 257 | },
|
219 | 258 | },
|
|
0 commit comments