OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.84k stars 6.59k forks source link

[BUG] Headers not copied into Raw response headers array. #6527

Open monscamus opened 4 years ago

monscamus commented 4 years ago

Bug Report Checklist

Description

When calling this method I know from the documents that the response provides details of a document created in the header.location but I can't examine this with the typescript-fetch API? The following snippet from a React test app is where I see the response headers are empty. If I use the standard dap


var config = new Configuration({
    apiKey: "ApiKey mykeywashere:mysecret",
    basePath: 'https://<basepath>.amazonaws.com/v1_cors'
  });

  dapi = new DocumentApi(config);

  var d = new DocumentPostFromJSON({
    "group": "/api/v1/group/legalesigndev/",
    "name": "SDK Special Test Document",
    "text": "<h1>Automatic Unit Test Document</h1><p>terms as follows.. <span class=\"field\" data-optional=\"false\" data-name=\"Please add your ...\" data-idx=\"0\" data-signee=\"1\" data-type=\"signature\" data-options=\"\"> ....... </span></p>",
    "signers": [{ "firstname": "fname", "lastname": "lname", "email": "lex@test.com", "order": 0 }],
    "do_email": "false",
    "offset": "",
    "archived": "false",
    "limit": "",
    "filter": ""
  });
  var dpr = {
    "documentPost": d
  };
  console.log("Testing postDocument");
  const out = await dapi.postDocumentRaw(dpr);
  console.log(await out);
  console.log(await out.raw.headers)
openapi-generator version

4.3.1

OpenAPI declaration file content or url

https://raw.githubusercontent.com/legalesign/Legalesign-V1-OpenAPI3/master/legalesign-api-v1.yaml

Command line used for generation

openapi-generator generate -i https://raw.githubusercontent.com/legalesign/Legalesign-V1-OpenAPI3/master/legalesign-api-v1.yaml -g typescript-fetch --additional-properties supportsES6=true

Steps to reproduce

Execute generation, make any Raw Api call - check response.headers.

Related issues/PRs

https://github.com/swagger-api/swagger-codegen/issues/7828

Suggest a fix

Should the baseApi.fetchApi.response be mapping onto this?

auto-labeler[bot] commented 4 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

pmonty commented 4 years ago

Any progress on this or a timeline on when it might be added?

laubfall commented 3 years ago

I run into the same issue that a custom response header was not inside the header array. Investigating the server response with browser developer tools showed that the header exists. After some research i think it is not a bug of the typescript-fetch generator. It is more likely that custom response headers are not accessible due to the cors nature of the request https://developers.google.com/web/updates/2015/03/introduction-to-fetch#response_types

The relevant part:

If a request is made for a resource on another origin which returns the CORs headers, then the type is cors. cors and basic responses are almost identical except that a cors response restricts the headers you can view to Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, and Pragma.

If you don't provide a fetchApi per configuration the browser fetchApi implementation is used and this one takes care of copying headers to the array of the response object (and only the ones you are allowed to view): get fetchApi(): FetchAPI { return this.configuration.fetchApi || window.fetch.bind(window); }

Solution (worked for me): The server must provide the "Access-Control-Expose-Headers" Header field. As value define all the custom header names that are not part of the default cors header list: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers