ng-openapi-gen
ng-openapi-gen copied to clipboard
is it possible to define customizedResponseType per http method/status code ?
Hi,
is it possible to define customizedResponseType
per http method/status code ?
"paths": {
"/api/account": {
"post": {
"tags": [
"Account"
],
"operationId": "postAccountControllerInvite",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AccountInviteRequest"
}
}
}
},
"responses": {
"204": {
"description": "When new account invitation sending was successful"
},
"400": {
"description": "Returns 400 in case of an error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
}
}
}
},
Let's say in case of 204 i return empty response body and after ng-openapi-gen i get this code with responseType: 'text'
instead of responseType: 'json'
postAccountControllerInvite$Response(params?: {
context?: HttpContext;
body?: AccountInviteRequest;
}): Observable<StrictHttpResponse<void>> {
const rb = new RequestBuilder(this.rootUrl, AccountService.PostAccountControllerInvitePath, 'post');
if (params) {
rb.body(params.body, 'application/json');
}
return this.http
.request(
rb.build({
responseType: 'text',
accept: '*/*',
context: params?.context,
})
)
.pipe(
filter((r: any) => r instanceof HttpResponse),
map((r: HttpResponse<any>) => {
return (r as HttpResponse<any>).clone({ body: undefined }) as StrictHttpResponse<void>;
})
);
}
Is there any other option to achieve this then adding @OA\MediaType
annotation to the response ?
* @OA\Response(
* response="204",
* content={
* @OA\MediaType(
* mediaType="application/json"
* )
* },
* description="Update successful, no response data",
* ),
@luisfpg @pillsilly
This isn't possible because of Angular's HTTP Client's restrictions.
See #166 for an explanation