Skip to content

Commit 7fd0578

Browse files
committed
fix(json-api-nestjs): Some fix for swagger
add json schema for filter use correct name of controller for delete rel
1 parent 2e7ecd2 commit 7fd0578

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

libs/json-api/json-api-nestjs/src/lib/modules/mixin/swagger/method/delete-relationship.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function deleteRelationship<
2929

3030
ApiOperation({
3131
summary: `Delete list of relation for resource "${entityName}"`,
32-
operationId: `${controller.name}_${methodName}`,
32+
operationId: `${controller.constructor.name}_${methodName}`,
3333
})(controller, methodName, descriptor);
3434

3535
ApiParam({

libs/json-api/json-api-nestjs/src/lib/modules/mixin/swagger/method/get-all.ts

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { ApiOperation, ApiQuery, ApiResponse } from '@nestjs/swagger';
22
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';
48

59
import {
610
assertIsKeysOfObject,
@@ -72,13 +76,44 @@ export function getAll<E extends object, IdKey extends string = 'id'>(
7276
},
7377
description: `Object of field for select field from "${entity.name}" resource`,
7478
})(controller, methodName, descriptor);
75-
79+
// https://github.com/OAI/OpenAPI-Specification/issues/1706#issuecomment-2704374644 need wait fix deepObject
7680
ApiQuery({
7781
name: 'filter',
7882
required: false,
7983
style: 'deepObject',
8084
schema: {
8185
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,
82117
},
83118
examples: {
84119
simpleExample: {
@@ -204,16 +239,20 @@ export function getAll<E extends object, IdKey extends string = 'id'>(
204239
required: false,
205240
schema: {
206241
type: 'object',
242+
examples: [
243+
{
244+
number: DEFAULT_QUERY_PAGE,
245+
size: DEFAULT_PAGE_SIZE,
246+
},
247+
],
207248
properties: {
208249
number: {
209250
type: 'integer',
210251
minimum: 1,
211-
example: DEFAULT_QUERY_PAGE,
212252
},
213253
size: {
214254
type: 'integer',
215255
minimum: 1,
216-
example: DEFAULT_PAGE_SIZE,
217256
maximum: 500,
218257
},
219258
},

0 commit comments

Comments
 (0)