swagger-api / swagger-api/swagger-codegen
[JavaScript] Generated code does not support setting 'Accept' even though claims to
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Unable to set accept header
Swagger-codegen version
3.0.46
Swagger declaration file content or url
https://digital.nhs.uk/restapi/oas/357490
Command line used for generation
java -jar /tmp/swagger-codegen-cli-3.0.46.jar generate -i /tmp/357490.json -l javascript -o mesh-client -DuseES6=true -DusePromises=true
Steps to reproduce
Download the OAS file
Run the above command
Attempt to use the client, setting accept header, as in
const api = new mesh.OutboxApi( client );
res = await api.sendMessageWithHttpInfo(nums,MAILBOX_ID, auth, nhs_mail_box, 'SPINE_NTT_UPHOLDING', {
mexFilename:`${local_id}.dat`,
mexLocalid: local_id,
accept:'application/vnd.mesh.v2+json'
});
This will send a request with an accept header of application/json instead of the intended
This is because the sendMessageXxxx method does let accepts = ['application/vnd.mesh.v2+json', 'application/json']; before calling callApi()
In there, at https://github.com/swagger-api/swagger-codegen/blame/master/modules/swagger-codegen/src/main/resources/Javascript/es6/ApiClient.mustache#L440, the existing accept header from headerParams (exposed outside the generated code as opts) is replaced.
Suggest a fix/enhancement
Probably it should only happen if not already set so if (accept) { should be if ( !request.header.accept && accept) {
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 modules/swagger-codegen/src/main/resources/Javascript/es6/ApiClient.mustache around line 440, then regenerate the JavaScript client from the linked OAS using the command in the issue. Reproduce the request with an opts accept header and verify that the generated client preserves that value instead of replacing it with application/json.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100