-
Notifications
You must be signed in to change notification settings - Fork 0
Code quality tooling added #2
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
fdb8046
cad7691
67b1e63
445bdbc
496cb0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,6 @@ | |
| import io.swagger.models.Path; | ||
| import io.swagger.models.Swagger; | ||
| import io.swagger.parser.SwaggerParser; | ||
|
|
||
| import org.apache.maven.plugin.AbstractMojo; | ||
| import org.apache.maven.plugin.MojoExecutionException; | ||
| import org.apache.maven.plugin.MojoFailureException; | ||
|
|
@@ -87,24 +86,18 @@ public class APIPostProcessorMojo extends AbstractMojo { | |
| @Component | ||
| private MavenProjectHelper projectHelper; | ||
|
|
||
| String[] minimum = {"200", "202", "204", "301", "400", "404", "415", "500"}; | ||
| String[] standard = {"200", "201", "202", "203", "204", "301", "304", "307", | ||
| private final String[] minimum = {"200", "202", "204", "301", "400", "404", "415", "500"}; | ||
| private final String[] standard = {"200", "201", "202", "203", "204", "301", "304", "307", | ||
| "400", "401", "403", "404", "406", "409", "410", "412", "415", "422", "429", | ||
| "500", "501", "503", "505"}; | ||
| "500", "501", "503", "505"}; | ||
|
|
||
|
|
||
| @Override | ||
| public void execute() throws MojoExecutionException, MojoFailureException { | ||
|
|
||
| SwaggerParser swaggerParser = new SwaggerParser(); | ||
| String fileAndPathName = inputDirectory + "/" + inputFilename; | ||
| if (Files.exists(Paths.get(fileAndPathName + ".json"))) { | ||
| fileAndPathName = fileAndPathName + ".json"; | ||
| } else if (Files.exists(Paths.get(fileAndPathName + ".yaml"))) { | ||
| fileAndPathName = fileAndPathName + ".yaml"; | ||
| } else if (Files.exists(Paths.get(fileAndPathName + ".yml"))) { | ||
| fileAndPathName = fileAndPathName + ".yml"; | ||
| } | ||
| fileAndPathName = findFileFormat(fileAndPathName); | ||
| Swagger api = swaggerParser.read(fileAndPathName); | ||
|
|
||
| if (api == null) { | ||
|
|
@@ -113,14 +106,14 @@ public void execute() throws MojoExecutionException, MojoFailureException { | |
| } | ||
|
|
||
| if (null == packages && null == codes) { | ||
| ApplySpecificHeadersAndResponses(api, new HashSet(Arrays.asList(standard))); | ||
| applySpecificHeadersAndResponses(api, new HashSet<>(Arrays.asList(standard))); | ||
| } else { | ||
| if (packages.contains("standard")) { | ||
| ApplySpecificHeadersAndResponses(api, new HashSet(Arrays.asList(standard))); | ||
| } else if (packages.contains("minimal")) { | ||
| ApplySpecificHeadersAndResponses(api, new HashSet(Arrays.asList(minimum))); | ||
| } else if (codes.size() > 0) { | ||
| ApplySpecificHeadersAndResponses(api, codes); | ||
| if (null != packages && packages.contains("standard")) { | ||
| applySpecificHeadersAndResponses(api, new HashSet<>(Arrays.asList(standard))); | ||
| } else if (null != packages && packages.contains("minimal")) { | ||
| applySpecificHeadersAndResponses(api, new HashSet<>(Arrays.asList(minimum))); | ||
| } else if (null != codes && codes.size() > 0) { | ||
| applySpecificHeadersAndResponses(api, codes); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -143,7 +136,18 @@ public void execute() throws MojoExecutionException, MojoFailureException { | |
| ); | ||
| } | ||
|
|
||
| private void ApplySpecificHeadersAndResponses(Swagger api, Set<String> codes) { | ||
| private String findFileFormat(String fileAndPathName) { | ||
|
||
| if (Files.exists(Paths.get(fileAndPathName + ".json"))) { | ||
| fileAndPathName = fileAndPathName + ".json"; | ||
| } else if (Files.exists(Paths.get(fileAndPathName + ".yaml"))) { | ||
| fileAndPathName = fileAndPathName + ".yaml"; | ||
| } else if (Files.exists(Paths.get(fileAndPathName + ".yml"))) { | ||
| fileAndPathName = fileAndPathName + ".yml"; | ||
| } | ||
| return fileAndPathName; | ||
| } | ||
|
|
||
| private void applySpecificHeadersAndResponses(Swagger api, Set<String> codes) { | ||
| Map<String, Path> paths = api.getPaths(); | ||
| paths.forEach((k, p) -> { | ||
| List<Operation> operations = p.getOperations(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not
private static final String[] MINIMUM = {...}andprivate static final String[] STANDARD = {...}?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Youre right, why not - it is a part fo the latest commit, thank you for pointing to that.