-
|
This library seems amazing, I already use it for a small API service and quite happy with the design decisions behind express-sod-api <3 Now that I am starting to implement additional more complex APIs I am hitting a few issues I do not know how to resolve. Is it possible to have separate schemas depending on the content-type of the request? Basically I want to implement an API that allow to POST either a JSON data or a file. Here is the OpenAPI that describes what I am trying to do: paths:
/foobar:
post:
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/FoobarFromJSONRequest"
multipart/form-data:
schema:
$ref: "#/components/schemas/FoobarFromDataRequest"
...
components:
schemas:
FoobarFromJSONRequest:
type: object
required:
- url
properties:
url:
type: string
FoobarFromDataRequest:
type: object
required:
- file
properties:
file:
type: string
format: binary
contentMediaType: application/octet-stream
some_additional_field:
type: string |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
well, it's not possible, @shadone |
Beta Was this translation helpful? Give feedback.
well, it's not possible, @shadone
And frankly I'm not sure it should be. I'd advocate for single purpose routes.
From what I see, you want that endpoint either to process the given
fileor to take that file from a givenurl.But you also want different response for those cases.
In this regard, I suggest you to make 2 routes for those requests (not to combine them), but to extract the actual data processing to a function that you could call from the handlers of both endpoints.
In the end, each would have its own input and output schema, but you won't repeat yourself in common parts.