Created by: denyo
PR checklist
-
Read the contribution guidelines. -
Ran the shell script under ./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first. -
Filed the PR against the correct branch: master
,4.1.x
,5.0.x
. Default:master
. -
Copied the technical committee to review the pull request if your PR is targeting a particular programming language.
Description of the PR
The goal is to generate the correct responseType
which is passed to rxjs/ajax
.
By default this is json
as visible here: https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/dom/AjaxObservable.ts#L167) but it can be overriden.
I am not too sure about all the possible types but I found json
, text
, blob
and arraybuffer
to be supported by rxjs/ajax
based on https://github.com/Reactive-Extensions/RxJS-DOM/pull/121/files#diff-d3b897234759c07ed79441f35e56b67fR22. Perhaps it's also possible to pass document
and ms-stream
as described there for completeness: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType.
The one that I personally need for a project is blob
in order to download an excel file.
The relevant lines for this in the api.json
are:
"/api/export": {
"get": {
"produces": ["*/*"],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string",
"format": "byte" // <–– here
}
}
}
}
}
However AbstractTypeScriptClientCodegen
maps this to a string because of typeMapping.put("ByteArray", "string");
.
I tried removing this via this.typeMapping.remove("ByteArray");
in TypeScriptRxjsClientCodegen
but then I end up with another import being generated for a model ByteArray
which does not exist.
Here are the changes on the call:
- exportUsingGET = (): Observable<object> => {
- return this.request<object>({
+ exportUsingGET = (): Observable<ByteArray> => {
+ return this.request<ByteArray>({
path: '/api/export',
method: 'GET',
responseType: 'blob' // <–– that's the one I need
});
}
In order to solve this I need some input on how to get there.
Or asked differently what's the reason for the mapping of ByteArray
to string
?
Or any how to figure out the appropriate responseType
?
@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @nicokoenig (2018/09) @topce (2018/10) @akehir (2019/07)