Skip to content

setting all required fields as optional should not serialize "required" as an empty array #2943

Open
@ben-lc

Description

@ben-lc

Expected Behavior

When fields are set as required on a schema and then set back as optional so that "required" field is empty, "required" should no be serialized in json or yaml, cause empty array is invalid for some openapi versions (cf: https://community.smartbear.com/discussions/swaggerostools/empty-array-in-required-field-in-schema-object/193184)

Actual Behavior

Required field is serialized as an empty array.

Steps to Reproduce the Problem

  1. Create a new openapi spec
  2. Create a new data type
  3. Create an required property on the data type
  4. Set previous property as not required

Specifications

  • apicurio studio: 0.2.62.Final
  • apicurio data models: 1.1.28

Cause

In apicurio-data-models, the ChangePropertyTypeCommand which is called when required field is changed on a property will create a new array to store required properties and will keep an empty array when all required properties are removed.

Proposed solution

Call parent.setRequiredProperties(null); to replace empty array by null so that "required" is not serialized when empty.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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