You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's an example struct-issue.yaml that recreates this:
openapi: 3.0.0info:
title: Sample Struct Servicedescription: 'Model definitions for struct inheritance issue'version: 0.0.1components:
schemas:
User:
description: a member profiletype: objectproperties:
user-id:
description: The member's unique IDtype: stringformat: uuidexample: 123e4567-e89b-12d3-a456-emailname:
description: The member's nametype: stringexample: 'Jane Doe'AdminUser:
description: A user profile including information only returned by admin endpointsallOf:
- $ref: '#/components/schemas/User'
- type: objectproperties:
latestLoggedInAt:
description: Last login from the usertype: stringformat: datetime
In the generated files you can see struct-issue/Sources/Models/AdminUser.swift
import Foundation
/** A user profile including information only returned by admin endpoints */
publicstructAdminUser:User{
/** Last login from the user */
publicvarlatestLoggedInAt:String?publicinit(name:String?=nil, userId:ID?=nil, latestLoggedInAt:String?=nil){self.latestLoggedInAt = latestLoggedInAt
super.init(name: name, userId: userId)}
which looks like a compilation error to me.
Possible workarounds for now
This is a list of possible workarounds for people who might also encounter this issue.
Don't use $refs in openapi to generate structs
Use classes (default behaviour of Swaggen)
Possible fix
A possible fix would be to read any references in models that occur and hard-code schemas that are inherited in structs. I don't know how hard would such fix look like, but I believe you would have some ideas for that.
Thanks otherwise for a very helpful tool!
The text was updated successfully, but these errors were encountered:
Holek
changed the title
modelType:struct creates struct with inheritance
modelType:struct creates structs with inheritance
Jul 1, 2021
First, I want to preface that I am not a Swift developer, but I've noticed an odd behaviour in model template generation.
Using
--option "modelType:struct"
the generator creates models as structs, but allows them to inherit from each other. As far as I understand, a struct cannot inherit from another kind of struct.Example
Here's an example
struct-issue.yaml
that recreates this:I've recreated this problem by running:
$ swaggen generate --option "modelType:struct" --destination struct-issue struct-issue.yaml
In the generated files you can see
struct-issue/Sources/Models/AdminUser.swift
which looks like a compilation error to me.
Possible workarounds for now
This is a list of possible workarounds for people who might also encounter this issue.
$ref
s in openapi to generate structsPossible fix
A possible fix would be to read any references in models that occur and hard-code schemas that are inherited in structs. I don't know how hard would such fix look like, but I believe you would have some ideas for that.
Thanks otherwise for a very helpful tool!
The text was updated successfully, but these errors were encountered: