Closed Kastet closed 5 years ago
Thanks for the report @Kastet. I've fixed the unresolved component here https://github.com/yonaskolb/SwagGen/pull/132
That spec still won't generate properly though, as an object schema can't be used as a path parameter. Would does the api expect to send? Just a simple string, or the whole user object encoded in some form?
Hi @yonaskolb ,
Thanks for looking into this. Agree that passing a complex object as a path param doesn't make sense.
However, $ref
isn't necessarily an object schema, it can be just a type alias, for example
"UUID": {
"type": "string"
}
Would it make sense to allow $ref
as path param provided its type is a primitive?
Yeah that should work fine. The reference isn’t the problem (anymore) it’s that the schema type is an object
Awesome!
Just tested and found one minor problem. The UUID
schema resolves into a type alias public typealias UUID = String
which exactly what I'd expect, but it collides with Foundation's UUID extension in Coding.swift
extension UUID {
func encode() -> Any {
return uuidString
}
}
A simple fix would be changing the template to
extension Foundation.UUID {
func encode() -> Any {
return uuidString
}
}
Thoughts @yonaskolb ?
Hmm, I'm not seeing this. There is a template option to map what ID
is generated as (typeAliases.ID). It defaults to UUID
In Coding.swift
this is then generated as public typealias ID = UUID
.
Are you using the latest release, and the included template?
Yep, using 4.0.0.
And where are you getting the public typealias UUID = String
from?
It's a model that gets generated from a schema, to illustrate
"components": {
"schemas": {
"UUID": {
"type": "string"
},
"User": {
"type": "object",
"properties": {
"id": {
"$ref": "#/components/schemas/UUID"
},
.....
}
}
Oh I see, you have a custom schema that conflicts with Foundation. I would suggest either:
format: uuid
instead of a custom UUID
schema (SwagGen will generate this as an ID
typealias, which you can change what that resolves to in the template options).Either way happy for you to create a PR to add the Foundation.UUID
Hi,
I was wondering if OAS3 was supported and gave it a go.
I used code from master, passed this spec as a launch argument. Getting
Thread 1: Fatal error: Reference #/components/schemas/User is unresolved
Not sure if it's a bug or something isn't supported yet.