Skip to content

Default field in schema object with type object #2948

Closed Answered by flaksp
mtovt asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, it is possible.

OpenAPI 3.0 uses JSON Schema (draft 5) spec to define schemas.

The default keyword is defined in JSON Schema Validation spec, section 6.2:

There are no restrictions placed on the value of this keyword.

This keyword can be used to supply a default JSON value associated with a particular schema. It is RECOMMENDED that a default value be valid against the associated schema.

OpenAPI 3.0 clarifies semantics of the keyword in section 4.7.25.1 of the spec:

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 def…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@mtovt
Comment options

Answer selected by mtovt
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants