Skip to content

default property does not make the property required when defining the property via reference #212

Open
@mitja-hofer

Description

@mitja-hofer

The functionality that a property with a set default value is treated as required or non-optional does not work when defining the set property via a reference.

For example,

Currently a schema defined like:

{
  type: "object",
  properties: {
    value: { type: "number", default: 5 },
  },
  additionalProperties: false,
}

results in this type:

{
  value: number
}

However, when defining via reference, this functionality does not work.

{
  type: "object",
  definitions: {
    Value: { type: "number", default: 5 },
  }
  properties: {
     value: { $ref: '#/definitions/Value' },
  },
  additionalProperties: false,
}

Resolves to type

{
  value?: number | undefined
}

I believe this is unwanted behaviour but please feel free to correct me with my usage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions