swagger-api / swagger-api/swagger-codegen

[JavaScript] Generated code doesn't set default value for header params per swagger spec

Open
#9,842 1 comment 0 reactions 0 assignees View on GitHub

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

https://github.com/LD4P/sinopia_server/blob/e3283b3e87e020a3f29793f4076ddb8c73cf46d5/swagger.yaml#L68-L73

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.