redoc
redoc copied to clipboard
default is missing when combined with allOf
When I generate API docs for the following property, ReDoc does not render the default:
allOf:
- type: string
enum:
- grow
- hold
- default: grow
- description: allOf is working
The description is rendered, so I know that it's processing the allOf.

I realize that the declaration seems contrived. I'd like to declare the enum in a separate file, reference it for GET and POST, but only specify a default value for POST.
It may be related to this: https://json-schema.org/understanding-json-schema/reference/combining.html#id5
allOf is typically thought of like inheritance/extends in OOP, but it is not like inheritance. We try to do our best to make it act as if it was so in the docs, but we don't handle all of the cases.
I think it may be more correct for us to not show a default value in a response rather than your desire to change your schema for the GET and POST operations. If I understand default (from OpenAPI 3.0.3 spec):
default - The default value represents what would be assumed by the consumer of the input as the value of the schema if one is not provided. Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level. For example, if type is string, then default can be "foo" but cannot be 1.
The "consumer of the input" phrase implies that the default is relevant to the request and not the response (in my opinion).
Interesting. Looks like I misunderstood allOf. I thought that the validator would union all of the subschemas under allOf, as opposed to treating them independently. Thanks for taking the time to respond. Go ahead and close this issue if you believe that it's pilot error.
I ran into this surprising behavior today as well.
I think it'd be acceptable to just show the default only on the request, as the assumption should be that if the user doesn't provide a value in POST then the default value will be persisted as part of the object as if it was provided by the user. Then there isn't really a need to show default on the response.
Any chance of this happening? :)