Description
- When I defined get parameter with
required: false, generated typescript code handle the parameter as a required parameter.
Swagger-codegen version
2.2.0-SNAPSHOT
Swagger declaration file content or url
Example is here:
/books:
get:
tags: [Books]
operationId: getBooksList
parameters:
- name: BookTypeId
in: path
required: false
type: integer
format: int64
responses:
200:
description: Success
schema:
type: array
items:
$ref: "#/definitions/Book"
Generated code is here:
public getBooksList (bookTypeId: number, extraHttpRequestParams?: any ) : Observable<Array<models.Book>> {
const path = this.basePath + '/books'
.replace('{' + 'BookTypeId' + '}', String(bookTypeId));
let queryParameters = new URLSearchParams();
let headerParams = this.defaultHeaders;
// verify required parameter 'bookTypeId' is set
if (!bookTypeId) {
throw new Error('Missing required parameter bookTypeId when calling getBooksList');
}
let requestOptions: RequestOptionsArgs = {
method: 'GET',
headers: headerParams,
search: queryParameters
};
return this.http.request(path, requestOptions)
.map((response: Response) => {
if (response.status === 204) {
return undefined;
} else {
return response.json();
}
});
}
Following parts do not allow skip bookTypeId:
const path = this.basePath + '/books'
.replace('{' + 'BookTypeId' + '}', String(bookTypeId));
...
if (!bookTypeId) {
throw new Error('Missing required parameter bookTypeId when calling getBooksList');
}
Suggest a Fix
Handle required: false GET parameter correctly.
Description
required: false, generated typescript code handle the parameter as a required parameter.Swagger-codegen version
2.2.0-SNAPSHOT
Swagger declaration file content or url
Example is here:
Generated code is here:
Following parts do not allow skip
bookTypeId:Suggest a Fix
Handle
required: falseGET parameter correctly.