Description of the problem/issue
When generating schema of a field of type number (e.g., @Schema(type = "number", example = "428.94")), it appears that Swagger Core interprets the type as a string. This results in the example being serialized as a string instead of a number.
For instance :
@Schema(
description = "amount" + "
Example: 428.94",
type = "number",
example = "428.94",
requiredMode = REQUIRED)
BigDecimal amount;
In the generated OpenAPI schema, the example becomes:
properties:
amount:
type: number
description: "amount
Example: 428.94"
example: "428.94"
instead of :
properties:
amount:
type: number
description: "amount
Example: 428.94"
example: 428.94
Affected Version
e.g. 2.2.43
-
Create any DTO class with a number type field
@Schema(
description = "amount" + "
Example: 428.94",
type = "number",
example = "428.94",
requiredMode = REQUIRED)
BigDecimal amount;
-
Generate open api docs
./gradlew generateOpenApiDocs
-
Check the resulting yaml. It will have schema like
type: object
properties:
amount:
type: number
description: "amount
Example: 428.94"
example: "428.94"
- Run spectral lint
npm install -g @stoplight/spectral@6.5.0
spectral lint --format=stylish --fail-severity=warn file.yaml
Spectral will report errors
error oas3-valid-media-example "amount" property type must be string
error oas3-valid-schema-example "example" property type must be number
Expected Behavior
Generated yaml file should have example value as number
properties:
amount:
type: number
description: "amount
Example: 428.94"
example: 428.94
Actual Behavior
Generated yaml file has example value as a string
properties:
amount:
type: number
description: "amount
Example: 428.94"
example: "428.94"
Logs / Stack Traces
error oas3-valid-media-example "amount" property type must be string
error oas3-valid-schema-example "example" property type must be number
Checklist
- I have searched the existing issues and this is not a duplicate.
- I have provided sufficient information for maintainers to reproduce the issue.
Description of the problem/issue
When generating schema of a field of type number (e.g., @Schema(type = "number", example = "428.94")), it appears that Swagger Core interprets the type as a string. This results in the example being serialized as a string instead of a number.
For instance :
@Schema(
description = "amount" + "
Example: 428.94",
type = "number",
example = "428.94",
requiredMode = REQUIRED)
BigDecimal amount;
In the generated OpenAPI schema, the example becomes:
properties:
amount:
type: number
description: "amount
Example: 428.94"
example: "428.94"
instead of :
properties:
amount:
type: number
description: "amount
Example: 428.94"
example: 428.94
Affected Version
e.g. 2.2.43
Create any DTO class with a number type field
@Schema(
description = "amount" + "
Example: 428.94",
type = "number",
example = "428.94",
requiredMode = REQUIRED)
BigDecimal amount;
Generate open api docs
./gradlew generateOpenApiDocs
Check the resulting yaml. It will have schema like
type: object
properties:
amount:
type: number
description: "amount
Example: 428.94"
example: "428.94"
npm install -g @stoplight/spectral@6.5.0
spectral lint --format=stylish --fail-severity=warn file.yaml
Spectral will report errors
error oas3-valid-media-example "amount" property type must be string
error oas3-valid-schema-example "example" property type must be number
Expected Behavior
Generated yaml file should have example value as number
properties:
amount:
type: number
description: "amount
Example: 428.94"
example: 428.94
Actual Behavior
Generated yaml file has example value as a string
properties:
amount:
type: number
description: "amount
Example: 428.94"
example: "428.94"
Logs / Stack Traces
error oas3-valid-media-example "amount" property type must be string
error oas3-valid-schema-example "example" property type must be number
Checklist