Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/arbitrary file downloads for oas 3 #144

Conversation

Geksanit
Copy link
Contributor

@Geksanit Geksanit commented Jun 7, 2021

part of #73

  • embedded files (type: string + format: byte)
  • other types such as application/pdf or text/xml
  • single file uploads

@dxCLA
Copy link

dxCLA commented Jun 7, 2021

CLA assistant check
All committers have signed the CLA.

@kokovtsev kokovtsev self-requested a review June 8, 2021 08:30
@kokovtsev
Copy link
Contributor

@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:

  1. Generate two separate methods:
     readonly getFileAsApplicationJson: () => Kind2<F, Error, SomeJsonObject>;
     readonly getFileAsTextCsv: () => Kind2<F, Error, string>;
    
  2. Accept an additional parameter:
     readonly getFile: (params: {accept: 'application/json'}) => Kind2<F, Error, SomeJsonObject>;
     readonly getFile: (params: {accept: 'text/csv'}) => Kind2<F, Error, string>;
    

What do you think?

@Geksanit Geksanit force-pushed the feature/arbitrary-file-downloads-for-oas-3 branch from f4d907e to 73ebe10 Compare June 21, 2021 07:37
@Geksanit
Copy link
Contributor Author

@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]>;

@kokovtsev
Copy link
Contributor

Thanks @Geksanit, looks great except for some minor things! I'm adding some comments in the code

kokovtsev
kokovtsev previously approved these changes Sep 8, 2021
@kokovtsev kokovtsev merged commit 411a4a3 into devexperts:master Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants