swagger-api / swagger-api/swagger-codegen
[HTML] Using $ref of the same component in multiple properties of the same object causes only first property to appear
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Swagger-codegen version
Docker image of swagger codegen cli version 3
Setup
Using powershell and docker by typing command
docker run -v path to swagger:/swagger.yaml -v path to output folder:/out swaggerapi/swagger-codegen-cli-v3 generate -l html -i /swagger.yaml -o /out
ISSUE
Lets take components:
StringZeroOrOne:
type: string
enum: ["0", "1"]
example: "1"
TxHash:
type: string
minLength: 85
maxLength: 85
example: "0x28b2aa205726766fb5ffe79ca2d1d498c7dd2f579b2164db2017e5019713df61"
PositiveStringFloatOrInt:
type: string
pattern: '^([0-9]*[.])?\d+$'
example: "0.1241"
DailyTradeSummary:
type: object
properties:
id:
$ref: '#/components/schemas/TxHash'
last:
$ref: "#/components/schemas/PositiveStringFloatOrInt"
percentChange:
$ref: "#/components/schemas/PositiveStringFloatOrInt"
high24hr:
$ref: "#/components/schemas/PositiveStringFloatOrInt"
low24hr:
$ref: "#/components/schemas/PositiveStringFloatOrInt"
highestBid:
$ref: "#/components/schemas/PositiveStringFloatOrInt"
lowestAsk:
$ref: "#/components/schemas/PositiveStringFloatOrInt"
baseVolume:
$ref: "#/components/schemas/PositiveStringFloatOrInt"
quoteVolume:
$ref: "#/components/schemas/PositiveStringFloatOrInt"
isFrozen:
$ref: "#/components/schemas/StringZeroOrOne"
I use ref of PositiveStringFloatOrInt multiple times for the properties of one object
the UI response presents itself like this (after generating, in editor everything shows up fine):
"last" : "0.1241",
"id" : "0x28b2aa205726766fb5ffe79ca2d1d498c7dd2f579b2164db2017e5019713df61",
"isFrozen" : "1"
From all the properties that had PositiveStringFloatOrInt referenced only the first one shows up which is the last property
Solution
Now if i replace the refs and repeat the code like this
DailyTradeSummary:
type: object
properties:
id:
$ref: '#/components/schemas/TxHash'
last:
type: string
pattern: '^([0-9]*[.])?\d+$'
example: "0.5241"
percentChange:
type: string
pattern: '^([0-9]*[.])?\d+$'
example: "0.3241"
high24hr:
type: string
pattern: '^([0-9]*[.])?\d+$'
example: "0.8241"
low24hr:
type: string
pattern: '^([0-9]*[.])?\d+$'
example: "0.1111241"
highestBid:
type: string
pattern: '^([0-9]*[.])?\d+$'
example: "0.11"
lowestAsk:
type: string
pattern: '^([0-9]*[.])?\d+$'
example: "0.8241"
baseVolume:
type: string
pattern: '^([0-9]*[.])?\d+$'
example: "0.6241"
quoteVolume:
type: string
pattern: '^([0-9]*[.])?\d+$'
example: "0.1241"
isFrozen:
$ref: "#/components/schemas/StringZeroOrOne"
The UI response shows up correctly
"percentChange" : "0.3241",
"high24hr" : "0.8241",
"last" : "0.5241",
"highestBid" : "0.11",
"id" : "0x28b2aa205726766fb5ffe79ca2d1d498c7dd2f579b2164db2017e5019713df61",
"quoteVolume" : "0.1241",
"baseVolume" : "0.6241",
"isFrozen" : "1",
"lowestAsk" : "0.8241",
"low24hr" : "0.1111241"
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 HTML generator invoked by the -l html command and reproduce the example using repeated $ref properties in DailyTradeSummary. Compare the generated output with the inline-schema version; the work is done when every property referencing PositiveStringFloatOrInt appears in the generated response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, html
- Domain
- documentation, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100