swagger-api / swagger-api/swagger-core

Order of `required` properties

Open
#4,887 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog
Dominant language
Java
Stars
7.5k
Forks
2.3k
Avg merge
18h 1m
Merged PRs (30d)
10

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Schema.java around lines 1202-1216, especially setRequired and its sorting step. Investigate the rationale for alphabetical ordering and the expected relationship between required properties and schema properties; done when the intended behavior or rationale is established.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.