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

Make UploadFile type codable. #289

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

0x0c
Copy link
Contributor

@0x0c 0x0c commented Nov 27, 2021

Motivation

I fixed UploadFile type to confirm Codable to upload binary data either a reference of model or binary data as string a.k.a a primitive type.
This changes allows to upload following model that could not be uploaded because of UploadFile can't be encode or decode when UploadFile is contained in user defined models.

I uploaded a minimal, reproducible example here.

paths:
  /withModel:
    post:
      summary: ''
      operationId: post-withModel
      responses:
        '200':
          description: OK
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                uploadData:
                  $ref: '#/components/schemas/UploadModel'
    parameters: []
...
components:
  schemas:
    UploadModel:
      title: UploadModel
      type: object
      properties:
        binary:
          type: string
          format: binary

This model is converted to this code and swift complier could not build as following error.

Screen Shot 2021-11-27 at 16 53 05

Trade-off

When generating specs with --option typeAliases.File:UploadFile, TestSpec could not be build because of the error below.

SwagGen/Specs/TestSpec/generated/Swift/Sources/Requests/GetFile.swift:52:49: error: cannot convert value of type 'Data' to expected argument type 'File' (aka 'UploadFile')
                case 200: self = try .status200(data)
                                                ^

To overcome this issue, we have to define public typealias File that responds to request body or response.

If there any concerns, please let me know freely :)

@0x0c
Copy link
Contributor Author

0x0c commented Dec 20, 2021

@yonaskolb Hi, is it possible to review this PR?

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.

1 participant