-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Description
When a schema contains an empty 20x response in addition to one with a body, the function defined in the API interface does not match the signature of the implementing function.
This regression was introduced as a side-effect of a bugfix for this issue: #20248
openapi-generator version
7.10.0
This is a regression introduced in 7.3.0 by #17635; while the signature was correctly changed in the implementing function, it was not changed in the API interface.
OpenAPI declaration file content or url
Example schema leading to bug:
/pets/events/:
post:
summary: A webhook for pet-related events
operationId: publishPetEvent
requestBody:
$ref: '#/components/requestBodies/PetEvent'
responses:
'200':
description: The response for the handshake event
content:
application/json:
schema:
$ref: '#/components/schemas/HandshakeResponse'
'204':
description: The event has been handled
default:
$ref: '#/components/responses/APIError'
tags:
- PetsThis produces output like
export interface PetsApiInterface {
...
publishPetEvent(
requestParameters: PublishPetEventRequest,
initOverrides?: RequestInit | runtime.InitOverrideFunction
): Promise<HandshakeResponse>;
}
export class PetsApi extends runtime.BaseAPI implements PetsApiInterface {
async publishPetEvent(
requestParameters: PublishPetEventRequest,
initOverrides?: RequestInit | runtime.InitOverrideFunction
): Promise<HandshakeResponse | null | undefined> {
const response = await this.publishPetEventRaw(requestParameters, initOverrides);
switch (response.raw.status) {
case 200:
return await response.value();
case 204:
return null;
default:
return await response.value();
}
}
}As can be seen, the return signature of the implementing function (Promise<HandshakeResponse | null | undefined>) does not match the signature as defined in the interface (Promise<HandshakeResponse>).
Expected would be that both include null and undefined as the promise type.
Generation Details
-g typescript-fetch \
--type-mappings=DateTime=string,Date=string \
--additional-properties=withInterfaces=true,stringEnums=true
Steps to reproduce
- Create an endpoint with a 200 response, including a JSON body, and a 204 response with no body.
- Run generation with
typescript-fetch - Observe error caused by mismatched signature
Suggest a fix
The fix would be to make the same change to the response signature in the interface as to its implementation. I will submit and link a pull request to do this.