Skip to content

Commit de19946

Browse files
Update swagger.md
1 parent e8ffa19 commit de19946

File tree

1 file changed

+1
-38
lines changed

1 file changed

+1
-38
lines changed

content/recipes/swagger.md

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ With `isArray` set to **true**, the `enum` can be selected as a **multi-select**
158158

159159
<figure><img src="/assets/enum_query_array.gif" /></figure>
160160

161-
#### Enums Schema
161+
#### Enums schema
162162

163163
By default, the `enum` property will add a raw definition of [Enum](https://swagger.io/docs/specification/data-models/enums/) on the `parameter`.
164164

@@ -173,35 +173,18 @@ CatDetail:
173173
- Persian
174174
- Tabby
175175
- Siamese
176-
...
177-
178-
CatInformation:
179-
type: 'object'
180-
properties:
181-
...
182-
- breed:
183-
type: 'string'
184-
enum:
185-
- Persian
186-
- Tabby
187-
- Siamese
188-
...
189176
```
190177
191178
The above specification works fine for most cases. However, if you are utilizing a tool that takes the specification as **input** and generates **client-side** code, you might run into a problem with the generated code containing duplicated `enums`. Consider the following code snippet:
192179

193180
```typescript
194181
// generated client-side code
195182
export class CatDetail {
196-
...
197183
breed: CatDetailEnum;
198-
...
199184
}
200185
201186
export class CatInformation {
202-
...
203187
breed: CatInformationEnum;
204-
...
205188
}
206189
207190
export enum CatDetailEnum {
@@ -224,17 +207,8 @@ To address this issue, you can pass an `enumName` next to `enum` property in you
224207

225208
```typescript
226209
export class CatDetail {
227-
...
228210
@ApiProperty({ enum: CatBreed, enumName: 'CatBreed' })
229211
breed: CatBreed;
230-
...
231-
}
232-
233-
export class CatInformation {
234-
...
235-
@ApiProperty({ enum: CatBreed, enumName: 'CatBreed' })
236-
breed: CatBreed;
237-
...
238212
}
239213
```
240214

@@ -248,17 +222,6 @@ CatDetail:
248222
- breed:
249223
schema:
250224
$ref: '#/components/schemas/CatBreed'
251-
...
252-
253-
CatInformation:
254-
type: 'object'
255-
properties:
256-
...
257-
- breed:
258-
schema:
259-
$ref: '#/components/schemas/CatBreed'
260-
...
261-
262225
CatBreed:
263226
type: string
264227
enum:

0 commit comments

Comments
 (0)