Closed felikf closed 3 years ago
Same needs here 🤔
my thought is to specify mapping logic in corresponding config.json
customizedResponseType: {
api: 'a/b/c/d', {
toUse: arraybuffer
}
}
how do you think or are there any maintaincer here to give some comments?
@luisfpg if the idea is ok then I am willing to provide implementation.
@felikf, it is not currently possible. @pillsilly We could discuss it. There are options:
blob
to arraybuffer
Would 1 be enough for you? It would be way simpler.
Usage:
If configuration json is used then it could be defined like::
customizedResponseType: {
'/api/path/you/would/like/to/customize/responseType', {
toUse: 'arraybuffer'
}
}
if cli is used then it needs to be specified like:
--customizedResponseType "{\"/api/path/you/would/like/to/customize/responseType\":{\"toUse\":\"arraybuffer\"}}"
json escape tool can be used to simplify the json escape work if you have to use cli instead of configuration file.
thanks.
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>;
})
);
}
As i know json
should be a default responseType, but for some reason i got responseType: 'text'
.
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
I have a question if it is possible to generate a request with
responseType:'arraybuffer'
?Something like this:
Source code says this, but I may overlook something: (
operation-variant.ts
)So I guess not :)