Reputation: 26316
I am using AutoRest to generate Typescript client for RESTful API based on OpenAPI spec file like this:
autorest --typescript --use-internal-constructors --override-client-name=MyApiClient --input-file=API.Swagger.json --namespace=MyApi.Client --typescript.output-folder=C:\One\ts --add-credentials=true
When I make a call using generated API client over CORS it doesn't include any of the Cookies.
JavaScript fetch
provides this construct to include cookies:
fetch(uri, { credentials: 'include' })
But I could not figure a way to make it happen with the AutoRest generated API client. I did look through msRest.ts
to see if I can use any of the available Credentials types.
[Update]:
After digging further I figured options parameter to the client has a property withCredentials
which can be set to true. Eventually, node_modules\@azure\ms-rest-js\es\lib\xhrHttpClient.js
makes the API call. Specifically, this line makes the call:
xhr.send(request.body === undefined ? null : request.body);
I debugged thorough and made sure that withCredentials
is set to true
but for some reason it doesn't send the cookies! If I make a call using javascript fetch
it sends cookies and autorest generated client doesn't send cookies!
Upvotes: 0
Views: 1792
Reputation: 10817
You may want to try OpenAPI Generator, which supports both OpenAPI/Swagger v2 and v3. (Only OpenAPI specification v3 supports the cookie parameter).
I remember we've added cookie parameters support to the TypeScript generators. Please open a ticket/issue if you need help from the OpenAPI Generator community.
Upvotes: 0