Skip to content

Fix sorting of #/components/schemas/* #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/io/openapitools/swagger/OpenAPISorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static void sortComponents(Components components) {
return;
}

sortSchemas(components.getSchemas());
components.setSchemas(sortSchemas(components.getSchemas()));

components.setResponses(createSorted(components.getResponses()));
components.setParameters(createSorted(components.getParameters()));
Expand Down
21 changes: 15 additions & 6 deletions src/test/java/io/openapitools/swagger/OpenApiSorterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ public class OpenApiSorterTest {

@Test
public void testSort() {
ObjectSchema schema = new ObjectSchema();
schema.addProperties("s2", new StringSchema());
schema.addProperties("s1", new StringSchema());
ObjectSchema schema1 = new ObjectSchema();
schema1.addProperties("s1-2", new StringSchema());
schema1.addProperties("s1-1", new StringSchema());

ObjectSchema schema2 = new ObjectSchema();
schema2.addProperties("s2-2", new StringSchema());
schema2.addProperties("s2-1", new StringSchema());

Components components = new Components()
.addSchemas("s1", schema)
.addSchemas("s2", schema2)
.addSchemas("s1", schema1)
.addResponses("k2", new ApiResponse())
.addResponses("k1", new ApiResponse())
.addParameters("k2", new Parameter())
Expand Down Expand Up @@ -55,9 +60,13 @@ public void testSort() {

api = OpenAPISorter.sort(api);

assertEquals("s1", api.getComponents().getSchemas()
assertEquals("s1-1", api.getComponents().getSchemas()
.values().stream()
.findFirst().get().getProperties()
.keySet().stream().findFirst().get());
assertEquals("s2-1", api.getComponents().getSchemas()
.values().stream()
.findAny().get().getProperties()
.skip(1).findFirst().get().getProperties()
.keySet().stream().findFirst().get());
assertEquals("k1", api.getComponents().getResponses().keySet().stream().findFirst().get());
assertEquals("k1", api.getComponents().getParameters().keySet().stream().findFirst().get());
Expand Down