I'm just starting with reitit and the metosin ecosystem. How would I specify a response that would be a default for any unspecified return status code? Details in thread.
In an OpenAPI spec, (e.g., in section 4.8.16.3 of the 3.1 spec) I can say
{
"200": {
"description": "a pet to be returned",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
}
}
},
"default": {
"description": "Unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorModel"
}
}
}
}
}
where the ErrorModel schema is used if the return status code is something other than 200. What would the equivalent be in Reitit?
Additionally, is there a way to specify a range of status codes in Reitit? For example, I'd like to specify a schema for all 4xx status codes.
Ideally, the schema would use malli.
Thanks.Have you tried:
:responses {:default {:content ...}}Optionally the string :default might work. Seems from the source that it just takes whatever the key is and uses it. But I haven't tried it myself.
Thanks. I should have mentioned that I tried the string "default" (which did not work - gave me an error that it was expecting a number). However, it appears that the keyword :default works. I'll have to look more into it. Thanks for the hint.