Last active
May 9, 2016 17:14
-
-
Save bowmanb/3bee5561a8218508dec8f97123f423f6 to your computer and use it in GitHub Desktop.
Swagger property sorter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
Swagger swagger = new SwaggerParser().read("swagger.json"); | |
sortDefinitionProperties(swagger); | |
try { | |
FileUtils.writeStringToFile(new File("swagger-output.json"), Json.pretty(swagger), Charset.defaultCharset()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
private static void sortDefinitionProperties(Swagger swagger) { | |
for (Model model : swagger.getDefinitions().values()) { | |
TreeMap<String, Property> sorted = new TreeMap<String, Property>(model.getProperties()); | |
model.getProperties().clear(); | |
model.setProperties(sorted); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.mycompany.app</groupId> | |
<artifactId>my-app</artifactId> | |
<version>1</version> | |
<dependencies> | |
<dependency> | |
<groupId>io.swagger</groupId> | |
<artifactId>swagger-parser</artifactId> | |
<version>1.0.19</version> | |
</dependency> | |
<dependency> | |
<groupId>commons-io</groupId> | |
<artifactId>commons-io</artifactId> | |
<version>2.5</version> | |
</dependency> | |
</dependencies> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment