Skip to content

Clarify how to handle default value on non-nullable optional properties when "default" keyword is not specified #2805

@ahmednfwela

Description

@ahmednfwela

Related OpenAPITools/openapi-generator#10972

Spec version: 3.0.3
the spec doesn't indicate how to handle model properties in the following case:

required: false
nullable: false
type: xxxxx
  • required: false means that the property might not exist in the json
  • nullable: false means that the property doesn't accept null as a value

so what to do when the spec document doesn't specify the default keyword ?

  1. assume default is null (works only for properties where nullable: true, otherwise it will break the spec)

  2. assume default to be of same type as type, so for non-nullable types that would be
    "boolean" => false
    "object" => { }
    "array" => [ ]
    "number"/"integer" => 0
    "string" => ""

  3. make it required to specify the default keyword when required: false and nullable: false

  4. ignore the provided required: false and assume instead required: true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions