reitit

dorab 2024-08-14T23:26:16.471959Z

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.

dorab 2024-08-14T23:32:15.041439Z

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.

Sardtok 2024-08-15T08:01:36.192879Z

Have you tried:

:responses {:default {:content ...}}

Sardtok 2024-08-15T08:02:17.103019Z

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.

dorab 2024-08-15T22:57:47.247249Z

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.