swagger-api / swagger-api/swagger-codegen
[JavaScript] Generated code doesn't set default value for header params per swagger spec
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When a default value is specified for a header parameter (e.g. a Link header), the generated JavaScript code allows the user to specify a value (correct), but does not provide a default value if an explicit value is not given (seemingly incorrect).
Swagger-codegen version
2.4.x (tried on 2.4.0, 2.4.2, 2.4.8, 2.4.9)
Swagger declaration file content or url
Command line used for generation
java -jar swagger-codegen-cli-2.4.8.jar generate -i swagger.yaml -l javascript --additional-properties usePromises=true -o sinopia_client/
Steps to reproduce
run the aforementioned command on the above linked swagger spec.
get generated JS code that results in having to manually implement the default, e.g.:
https://github.com/LD4P/sinopia_server/blob/e3283b3e87e020a3f29793f4076ddb8c73cf46d5/sinopia_client/src/api/LDPApi.js#L84
Related issues/PRs
Suggest a fix/enhancement
it would be great if the generated code would allow the user to specify header param values as it does, while also providing a default value if the swagger spec lists one and the user provides no explicit value.
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 linked swagger.yaml header parameter definition and the generated sinopia_client/src/api/LDPApi.js example, then reproduce generation with the documented swagger-codegen-cli command. Trace the JavaScript generator output for header parameters and verify that an omitted explicit value uses the Swagger default while still allowing overrides.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100