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
I had a functional work-around for version 0.8.0, but 0.8.1 replaced the SwaggerUI with Scalar, which does not accept this work-around. I have tried many things, but been unable to find a working solution for referencing schema components that exist within the same OpenAPI file.
I specify the schemas with new Elysia().model({ User: UserModel })
This puts the UserModel into #/components/schemas/User in the OpenAPI file.
I would like to reference this model (or several) in a response or body, by wrapping it in an object, like so:
newElysia().model({User: UserModel}).get("/users",()=>{return{users: []}},{response: t.Object({users: t.Array(// Some reference to '#/components/schemas/User')})})
Currently, the only way I've found to somewhat get this effect is to put the UserModel into the array, but this breaks the link to the existing schema. The end result is that the OpenAPI file duplicates the schema, inflating it exponentionally depending on how many times you wish to use it.
With SwaggerUI, I was able to get this to work with t.Array(t.Ref(UserModel)), however Scalar does not like this approach, instead attempting to fetch GET /User as it seems to think the schema is external to the file. I'm not sure I can fault Scalar for this though, as it seems the format was incorrect originally despite working in SwaggerUI.
To get it to work with SwaggerUI, the UserModel was required to specify the $id field. It seems by setting it to "User", the file ended up with "$ref": "User", and the local schema included the "$id": "User" field. I think the issue is that the $ref should be #/components/schemas/User, not just User. There may be other issues aside from this, but this is the most prominent issue I can spot. I've been reading the OpenAPI v3.1 spec, and I don't think it allows referring to local schemas simply by name, despite them having an $id, but I could be wrong. Either way, Scalar breaks with how it currently is.
If you put it into https://docs.scalar.com/swagger-editor you can see that it fails to locate the schema, falling back to null.
Modify the $ref to be #/components/schemas/User and it will work.
The text was updated successfully, but these errors were encountered:
I had a functional work-around for version 0.8.0, but 0.8.1 replaced the SwaggerUI with Scalar, which does not accept this work-around. I have tried many things, but been unable to find a working solution for referencing schema components that exist within the same OpenAPI file.
I specify the schemas with
new Elysia().model({ User: UserModel })
This puts the UserModel into
#/components/schemas/User
in the OpenAPI file.I would like to reference this model (or several) in a response or body, by wrapping it in an object, like so:
Currently, the only way I've found to somewhat get this effect is to put the
UserModel
into the array, but this breaks the link to the existing schema. The end result is that the OpenAPI file duplicates the schema, inflating it exponentionally depending on how many times you wish to use it.I want the file to appear like this
Instead it appears like this
Some things I have tried
With SwaggerUI, I was able to get this to work with
t.Array(t.Ref(UserModel))
, however Scalar does not like this approach, instead attempting to fetchGET /User
as it seems to think the schema is external to the file. I'm not sure I can fault Scalar for this though, as it seems the format was incorrect originally despite working in SwaggerUI.To get it to work with SwaggerUI, the UserModel was required to specify the
$id
field. It seems by setting it to "User", the file ended up with"$ref": "User"
, and the local schema included the"$id": "User"
field. I think the issue is that the$ref
should be#/components/schemas/User
, not justUser
. There may be other issues aside from this, but this is the most prominent issue I can spot. I've been reading the OpenAPI v3.1 spec, and I don't think it allows referring to local schemas simply by name, despite them having an$id
, but I could be wrong. Either way, Scalar breaks with how it currently is.Using:
Reproduction
Open to see
Go to
/swagger/json
to get the resulting file (Scalar at/swagger
just generates a blank page)The file looks like this:
If you put it into https://editor-next.swagger.io/ it renders more or less correctly
If you put it into https://docs.scalar.com/swagger-editor you can see that it fails to locate the schema, falling back to null.
Modify the
$ref
to be#/components/schemas/User
and it will work.The text was updated successfully, but these errors were encountered: