Skip to content

Order of required properties #4887

Open
@marceloverdijk

Description

@marceloverdijk

https://github.com/swagger-api/swagger-core/blame/f728c95fd8d6d9153cdcc18043a15bd6ae0612e3/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Schema.java#L1211

For documentation readability it would be very convenient if the required properties of schema are the same of the order of properties in the schema itself. Unfortunately this is not the case and the required properties are always ordered alphabetically.

    public void setRequired(List<String> required) {
        List<String> list = new ArrayList<>();
        if (required != null) {
            for (String req : required) {
                if (this.properties == null || this.properties.containsKey(req)) {
                    list.add(req);
                }
            }
        }
        Collections.sort(list); // <==================== HERE!
        if (list.isEmpty()) {
            list = null;
        }
        this.required = list;
    }

What is the rationale behind this?

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