swagger-api / swagger-api/swagger-codegen
[Typescript-Angular] Generated client code for "Cookie Authentication" is incorrect.
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I want to use the "Cookie Authentication" as described HERE with the cookies transferred within the headers.
Everything looks well in the Swagger-Editor/-UI but the generated code does not create any header nor does it put a cookie in it for any request.
Instead the generated code sets the cookie to the "queryParameters" if the appropriate ApiKey is available.
If the request does not define any query parameters, the generated source code assigns the cookie to the uninitialized variable "queryParameters".
Thus, there are two issues:
- No HTML header will be generated with the cookie in it.
- The generated code tries to transfer the ApiKey within uninitialized "queryParameters" variable.
Swagger-codegen version
Swagger-Editor Version: 3.6.25
Swagger declaration file content or url
The YAML code:
openapi: 3.0.0
paths:
'/entity/{uuid}/program':
post:
operationId: program
parameters:
- in: path
name: uuid
schema:
type: string
required: true
responses:
'202':
description: Accepted
content:
text/plain:
schema:
$ref: '#/components/schemas/UUID'
'401':
$ref: '#/components/responses/UnauthorizedError'
default:
description: Unexpected error.
components:
securitySchemes:
cookieAuth:
type: apiKey
in: cookie
name: SESSIONID
schemas:
UUID:
type: string
description: Unique ID of the targeted blast group.
example: 936DA01F-9ABD-4D9D-80C7-02AF85C822A8
responses:
UnauthorizedError:
description: API key (SESSIONID) is missing or invalid
headers:
WWW_Authenticate:
schema:
type: string
security:
- cookieAuth: []
The generated code:
public program(uuid : string, observe?: 'body', reportProgress?: boolean): Observable<string>;
public program(uuid : string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<string>>;
public program(uuid : string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<string>>;
public program(uuid : string, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {
if (uuid === null || uuid === undefined) {
throw new Error('Required parameter uuid was null or undefined when calling program.');
}
let headers = this.defaultHeaders;
// authentication (cookieAuth) required
if (this.configuration.apiKeys["SESSIONID"]) {
queryParameters = queryParameters.set('SESSIONID', this.configuration.apiKeys["SESSIONID"]);
}
// to determine the Accept header
let httpHeaderAccepts: string[] = [
'text/plain'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
headers = headers.set('Accept', httpHeaderAcceptSelected);
}
// to determine the Content-Type header
const consumes: string[] = [
];
return this.httpClient.post<string>(`${this.basePath}/entity/${encodeURIComponent(String(uuid))}/program`,
{
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
);
}
Command line used for generation
Steps to reproduce
Generating the code from the YAML-code above and generate a client for typescript-angular.
Related issues/PRs
Suggest a fix/enhancement
The code generator should not generate the cookie to the "queryParameters" assignment but should instead create the HTTP header and assigning the cookie to it.
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
Reproduce the issue with the provided OpenAPI YAML and the typescript-angular generator, then trace how the generated client handles the cookieAuth security scheme. Done means the generated request places SESSIONID in the HTTP cookie/header handling and does not reference an uninitialized queryParameters variable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100