Closed Geksanit closed 2 years ago
@Geksanit looks like this change does not 100% cover our need; for example, I tried generating the code using the spec below
/file:
get:
tags:
- files
operationId: getFile
responses:
200:
description: succesfull operation
content:
application/json:
schema:
$ref: '#/components/schemas/SomeJsonObject'
text/csv:
schema:
type: string
The generated code adds the Accept: application/json
header to the request and uses the SomeJsonObject
to decode the response. That is, it is still impossible to download a CSV file.
Let's discuss what interface should be generated for the spec above. As I see it, the consumer should be able to choose the desired response type. Looks like there are two ways:
readonly getFileAsApplicationJson: () => Kind2<F, Error, SomeJsonObject>;
readonly getFileAsTextCsv: () => Kind2<F, Error, string>;
readonly getFile: (params: {accept: 'application/json'}) => Kind2<F, Error, SomeJsonObject>;
readonly getFile: (params: {accept: 'text/csv'}) => Kind2<F, Error, string>;
What do you think?
@kokovtsev see how the code is generated now:
type MapToResponsegetFile = { 'application/json': SomeJsonObject; 'text/csv': string };
...
readonly getFile: <A extends keyof MapToResponsegetFile = 'application/json'>(parameters?: {
accept?: A;
}) => HKT<F, MapToResponsegetFile[A]>;
Thanks @Geksanit, looks great except for some minor things! I'm adding some comments in the code
part of https://github.com/devexperts/swagger-codegen-ts/issues/73