-
-
Notifications
You must be signed in to change notification settings - Fork 292
Open
Labels
Description
Describe the bug
Following our exchange and your fix in release 7.87.4, I use to swagger-editor from openapi to analyze the generated swagger for property that can be Array or null described by Schema annotation and functions.
In particular, label("string with space") create error in the swagger (last case in code snippet)
Please find in code snippet the different case tested and expected swagger if needed.
To Reproduce
Get the code snippets and inject it in one of your model
Expected behavior
I expect a openapi swagger syntactically correct
Code snippets
// first example: correct without label()
//code
@Schema(
array()
.items(
string()
.pattern(/[a-zA-Z]{1,20}/)
.minLength(1)
.maxLength(20)
)
.nullable(true)
.description("string array")
)
stringArray?: string[] | null;
//openapi swagger => OK
stringArray:
type: array
items:
type: string
pattern: '[a-zA-Z]{1,20}'
minLength: 1
maxLength: 20
description: string array
nullable: true
----------------
// second example: introducing label()
//code
@Schema(
array()
.items(
string()
.pattern(/[a-zA-Z]{1,20}/)
.minLength(1)
.maxLength(20)
)
.nullable(true)
.description("string array")
.label("stringarray")
)
stringArray?: string[] | null;
//openapi swagger => syntactically correct but can be enhanced
stringArray:
anyOf: //useless
- $ref: '#/components/schemas/stringarray'
nullable: true //will be ignored
schemas:
stringarray:
type: array
items:
type: string
pattern: '[a-zA-Z]{1,20}'
minLength: 1
maxLength: 20
description: string array
nullable: true
//correct swagger would be:
stringArray:
- $ref: '#/components/schemas/stringarray'
schemas:
stringarray:
type: array
items:
type: string
pattern: '[a-zA-Z]{1,20}'
minLength: 1
maxLength: 20
description: string array
nullable: true
----------------
// third example: incorrect with label("string with space")
//code
@Schema(
array()
.items(
string()
.pattern(/[a-zA-Z]{1,20}/)
.minLength(1)
.maxLength(20)
)
.nullable(true)
.description("string array")
.label("string array")
)
stringArray?: string[] | null;
//openapi swagger: Incorrect (the error description is provided by the swagger-editor)
stringArray:
anyOf:
- $ref: '#/components/schemas/string array' //Error: should match format "uri-reference", format: uri-reference, $ref values must be RFC3986-compliant percent-encoded URIs
nullable: true
schemas:
string array: //Error: Declaration was declared but never use in the document. Component names can only contain the characters A-Z a-z 0-9 - . _
type: array
items:
type: string
pattern: '[a-zA-Z]{1,20}'
minLength: 1
maxLength: 20
description: string array
nullable: true
Repository URL example
No response
OS
macOS
Node version
Node v22.19.0
Library version
v7.87.4
Additional context
Link to openapi swagger editor: https://editor.swagger.io/
I use the official docker image