The `type` field must be defined when the `nullable` field is used.
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 25.9k
- Forks
- 2.4k
- Avg merge
- 13h 10m
- Merged PRs (30d)
- 4
Description
Describe the bug
A clear and concise description of what the bug is.
I have an object "Discount" that has an attribute "type" that is an enum of Strings.
Discount:
required:
- type
- percentages
type: object
properties:
type:
allOf:
- $ref: '#/components/schemas/DiscountType'
- description: Discount type
enum:
- INVOICE_EXPENSE
- CONTRIBUTION_MARGIN
- INVESTMENT
example: INVESTMENT
nullable: false
percentages:
description: Percentages and invoice amounts according to the type of discount
minItems: 1
type: array
items:
$ref: '#/components/schemas/Percentage'
When I try to push my yaml file with the configuration above I get the error "The type field must be defined when the nullable field is used."
When I manually put "type: string" I am able to push it, but when I click to "Try it out" it gets an error in my "type" attribute.
On Swagger Editor I don't need to insert the "type: string" manually on my yaml file and when I click "Try it out" it works flawlessly.
Expected behavior
A clear and concise description of what you expected to happen.
Minimal reproducible OpenAPI snippet(if possible)
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided Discount OpenAPI YAML, especially the type property using allOf, $ref, enum, and nullable. Reproduce the validation error and compare the behavior with Swagger Editor; done means the schema is accepted without an unnecessary type declaration and Try it out handles the field correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, documentation
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100