swagger-api / swagger-api/swagger-parser
enum default value changes when defined in referenced file
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
The default value of an enum changes depending on whether it is defined in the main input file or in a referenced file.
Although I'm new to swagger-parser, this seems like a bug to me. Using the flatten and resolveFully options doesn't make a difference.
Example 1
input1.yaml:
openapi: 3.0.3
info:
version: 1.0.0
title: Issue Demo
description: none
paths:
/test:
$ref: 'input1Child.yaml#/paths/~1test'
input1Child.yaml:
components:
parameters:
pets:
name: pets
in: query
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
default: [DOG, FISH]
schemas:
Pet:
type: string
enum:
- DOG
- CAT
- FISH
paths:
/test:
get:
description: Returns ad for a given ad ID.
operationId: getAd
parameters:
- $ref: '#/components/parameters/pets'
responses:
'200':
description: OK
content:
text/plain:
schema:
type: string
example: pong```
Here the pets default value is parsed to be [DOG, FISH].
Example 2
input2.yaml:
openapi: 3.0.3
info:
version: 1.0.0
title: Issue Demo
description: none
components:
parameters:
pets:
name: pets
in: query
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
default: [DOG, FISH]
schemas:
Pet:
type: string
enum:
- DOG
- CAT
- FISH
paths:
/test:
get:
description: Returns ad for a given ad ID.
operationId: getAd
parameters:
- $ref: '#/components/parameters/pets'
responses:
'200':
description: OK
content:
text/plain:
schema:
type: string
example: pong
Here the pets default value is parsed to be ["DOG","FISH"].
I used the latest swagger-parser version, 2.1.16, for these examples. And I created a minimal executable example at https://github.com/martin-mfg/swagger-parser-demo that demos the issue.
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 by running the minimal executable example linked in the issue and compare input1.yaml with input2.yaml, focusing on how the referenced input1Child.yaml is resolved. Trace the parser's reference-resolution and default-value handling, then verify that both examples produce the same default representation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100