[JavaScript] Generated code does not support setting 'Accept' even though claims to
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) {