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 have searched existing issues to ensure the issue has not already been raised
Issue
I am using Fastify with Typescript through heavy use of Typebox for automatic creation of JSON schema.
For one of my route, I am using "multipart/form-data" as the content type, and I have an array field. In order for Swagger's "Try it out" feature to work with JSON Schema's array validation, I need to specify the "explode: true" option, or else Swagger is just going to send the field as a comma separated string of value, not an actual array (by duplication the field names but with different values in the multipart form data request body)
Typebox allows me to add arbitrary fields to a schema's properties. However, with the new OpenAPI v3 specification, I need the add the "encoding" option in the same depth with the "schema" field, and I don't know how to do it.
Produce this JSON schema. This has the problem of Swagger UI's "Try it out" trying to send the color field as color=red,blue and not as color=red&color=blue. Only color=red&color=blue will satisfy Fastify AJV; color=red,blue will error out that body/color is not an array
What option do I have here to implement this feature? I have thought about using the transform option in @fastify/swagger, but transform only affect the scheme, so it is still not a way to add encoding as a sibling of the schema. Are there any options?
The text was updated successfully, but these errors were encountered:
bhuynhdev
changed the title
What is the tecommended way to add "encoding - explode: true" to Swagger when using Typebox
Question: What is the recommended way to add "encoding - explode: true" to Swagger when using Typebox
Jun 20, 2023
From some more experimentations and explore, it seems like there is currently zero way to add the encoding object even without Typebox.
Fastify itself only exposes the schema object for modification, and there is no other way to add an extra object as the sibling of the schema field. Since encoding is not standard JSON schema, I kinda understand this situation. Maybe for Swagger/OpenAPI-specific stuff like this, there needs to be some extra option from Fastify-swagger to allow this transformation, like maybe with a decorator, or detecting certain special custom keyword in the schema, and then silently adding an encoding object before finalizing the OpenAPI spec
Prerequisites
Issue
I am using Fastify with Typescript through heavy use of Typebox for automatic creation of JSON schema.
For one of my route, I am using "multipart/form-data" as the content type, and I have an array field. In order for Swagger's "Try it out" feature to work with JSON Schema's array validation, I need to specify the "explode: true" option, or else Swagger is just going to send the field as a comma separated string of value, not an actual array (by duplication the field names but with different values in the multipart form data request body)
Typebox allows me to add arbitrary fields to a schema's properties. However, with the new OpenAPI v3 specification, I need the add the "encoding" option in the same depth with the "schema" field, and I don't know how to do it.
Here are examples to illustrate my points:
Produce this JSON schema. This has the problem of Swagger UI's "Try it out" trying to send the
color
field ascolor=red,blue
and not ascolor=red&color=blue
. Onlycolor=red&color=blue
will satisfy Fastify AJV;color=red,blue
will error out thatbody/color
is not an arrayProduce this JSON schema. However, it doesn't work because "encoding" becomes a subfield of "schema", not its sibling
What option do I have here to implement this feature? I have thought about using the
transform
option in@fastify/swagger
, buttransform
only affect the scheme, so it is still not a way to addencoding
as a sibling of the schema. Are there any options?The text was updated successfully, but these errors were encountered: