swagger-api / swagger-api/swagger-codegen
[Typescript/angular2] List<string> header parameter
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I've this endpoint:
@DELETE
@Path("cards")
@ApiOperation(value = "Delete cards from customer", response = String.class, responseContainer = "List")
public abstract Response deleteCards(
@HeaderParam("user")
@ApiParam(value = "user", required = true)
@NotNull(message = "user.id.notnull")
String username,
@HeaderParam("tokens")
@ApiParam(value = "tokens", required = true)
List<String> tokens
) throws RepositorySystemException;
As you can see I'm setting tokens as a header parameter and it's a List.
Codegen generates well the method signature:
deleteCards(user: string, tokens: Array<string>, extraHttpRequestParams?: any): Observable<Array<string>>;
Nevertheless, it seems the code implementation there's something wrong since I receive values as a single value. So tokens parameter only has one element:
tokens => ["card_1A7ionLt2kpw3BYUiWtB7VyT,card_1A7k72Lt2kpw3BYU66JI8yat"]
instead of:
tokens => ["card_1A7ionLt2kpw3BYUiWtB7VyT", "card_1A7k72Lt2kpw3BYU66JI8yat"]
The method implementation is:
public deleteCardsWithHttpInfo(user: string, tokens: Array<string>, extraHttpRequestParams?: any): Observable<Response> {
const path = this.basePath + `/users/cards`;
let queryParameters = new URLSearchParams();
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// verify required parameter 'user' is not null or undefined
if (user === null || user === undefined) {
throw new Error('Required parameter user was null or undefined when calling deleteCards.');
}
// verify required parameter 'tokens' is not null or undefined
if (tokens === null || tokens === undefined) {
throw new Error('Required parameter tokens was null or undefined when calling deleteCards.');
}
headers.set('user', String(user));
headers.set('tokens', String(tokens));
// to determine the Accept header
let produces: string[] = [
'application/json'
];
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Delete,
headers: headers,
search: queryParameters
});
// https://github.com/swagger-api/swagger-codegen/issues/4037
if (extraHttpRequestParams) {
requestOptions = this.extendObj(requestOptions, extraHttpRequestParams);
}
return this.http.request(path, requestOptions);
}
I think the problem is related with this line of code:
headers.set('tokens', String(tokens));
Swagger-codegen version
2.3.0-SNAPSHOT
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
Start with the generated deleteCardsWithHttpInfo method shown in the issue, especially the headers.set calls for the List tokens parameter. Trace the TypeScript/Angular client template that produces this code and check how list header values are represented. Done means generated requests preserve the individual token values instead of collapsing them into one comma-joined value.
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
- 42/100