Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task
monscamus opened this issue Jun 3, 2020 · 3 comments
Open
1 task

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

monscamus opened this issue Jun 3, 2020 · 3 comments

Comments

@monscamus
Copy link

monscamus commented Jun 3, 2020

Bug Report Checklist

  • [ y] Have you provided a full/minimal spec to reproduce the issue?
  • [ y] Have you validated the input using an OpenAPI validator (example)?
  • [ y] What's the version of OpenAPI Generator used?
  • [ y] Have you search for related issues/PRs?
  • [ y] What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
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

swagger-api/swagger-codegen#7828

Suggest a fix

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

@auto-labeler
Copy link

auto-labeler bot commented Jun 3, 2020

👍 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.

@monscamus monscamus changed the title [BUG] Headers copied into Raw response headers array. [BUG] Headers not copied into Raw response headers array. Jun 3, 2020
@pmonty
Copy link

pmonty commented Aug 4, 2020

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

@laubfall
Copy link
Contributor

laubfall commented May 25, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants