SwagGen
SwagGen copied to clipboard
Make UploadFile type codable.
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.

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 :)
@yonaskolb Hi, is it possible to review this PR?