Skip to content

Commit

Permalink
removed system properties for api/model on test and docs generations …
Browse files Browse the repository at this point in the history
…and use default custom options instead.
  • Loading branch information
HugoMario committed Mar 6, 2018
1 parent 3f3d552 commit dac94a7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.swagger.codegen.languages.java;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.codegen.CodegenArgument;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenOperation;
Expand Down Expand Up @@ -45,13 +46,6 @@ public JavaInflectorServerCodegen() {
modelDocTemplateFiles.remove("model_doc.mustache");
apiDocTemplateFiles.remove("api_doc.mustache");

// todo: remove when system properties are removed
System.setProperty(CodegenConstants.MODEL_DOCS, Boolean.FALSE.toString());
System.setProperty(CodegenConstants.API_DOCS, Boolean.FALSE.toString());
System.setProperty(CodegenConstants.MODEL_TESTS, Boolean.FALSE.toString());
System.setProperty(CodegenConstants.API_TESTS, Boolean.FALSE.toString());


apiPackage = System.getProperty("swagger.codegen.inflector.apipackage", "io.swagger.controllers");
modelPackage = System.getProperty("swagger.codegen.inflector.modelpackage", "io.swagger.model");

Expand Down Expand Up @@ -203,6 +197,42 @@ protected String getOrGenerateOperationId(Operation operation, String path, Stri
return super.getOrGenerateOperationId(operation, path, httpMethod.toUpperCase());
}

@Override
public void setLanguageArguments(List<CodegenArgument> languageArguments) {
if (languageArguments == null) {
languageArguments = new ArrayList<>();
}
if (!languageArguments.stream()
.anyMatch(codegenArgument -> CodegenConstants.MODEL_DOCS_OPTION.equalsIgnoreCase(codegenArgument.getOption()) && StringUtils.isNotBlank(codegenArgument.getValue()))) {
languageArguments.add(new CodegenArgument()
.option(CodegenConstants.MODEL_DOCS_OPTION)
.type("boolean")
.value(Boolean.FALSE.toString()));
}
if (!languageArguments.stream()
.anyMatch(codegenArgument -> CodegenConstants.API_DOCS_OPTION.equalsIgnoreCase(codegenArgument.getOption()) && StringUtils.isNotBlank(codegenArgument.getValue()))) {
languageArguments.add(new CodegenArgument()
.option(CodegenConstants.API_DOCS_OPTION)
.type("boolean")
.value(Boolean.FALSE.toString()));
}
if (!languageArguments.stream()
.anyMatch(codegenArgument -> CodegenConstants.MODEL_TESTS_OPTION.equalsIgnoreCase(codegenArgument.getOption()) && StringUtils.isNotBlank(codegenArgument.getValue()))) {
languageArguments.add(new CodegenArgument()
.option(CodegenConstants.MODEL_TESTS_OPTION)
.type("boolean")
.value(Boolean.FALSE.toString()));
}
if (!languageArguments.stream()
.anyMatch(codegenArgument -> CodegenConstants.API_TESTS_OPTION.equalsIgnoreCase(codegenArgument.getOption()) && StringUtils.isNotBlank(codegenArgument.getValue()))) {
languageArguments.add(new CodegenArgument()
.option(CodegenConstants.API_TESTS_OPTION)
.type("boolean")
.value(Boolean.FALSE.toString()));
}
super.setLanguageArguments(languageArguments);
}

public String apiFilename(String templateName, String tag) {
String result = super.apiFilename(templateName, tag);

Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/arguments/inflector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
arguments:
- option: "--model-docs"
description: "generate models documentation."
type: "boolean"
- option: "--api-docs"
description: "generate apis documentation."
type: "boolean"
- option: "--model-tests"
description: "generate model tests."
type: "boolean"
- option: "--api-tests"
description: "generate apis tests."
type: "boolean"

0 comments on commit dac94a7

Please sign in to comment.