forked from loafle/openapi-generator-original
[kotlin] api/model docs
This commit adds Api/Model/Auth documentation to the generated README.md. Because auth support is not yet fully implemented (users can manually set default headers globally), there aren't examples for helper auth methods. Models with inline enums document allowed values rather than pointing to a generated enum class. Two global additionalProperties were added (generateApiDocs, generateModelDocs) to allow templates to conditionally display documentatoin depending on these mutually exclusive settings. All current generators supporting docs will attempt to link to generated models when only api docs are specified. This also moves the $@ bash parameter in bin/kotlin-client-petstore.sh to the end of the args variable. This is because $@ can only be used to pass System properties like -DdebugModels, can can already be passed as: JAVA_OPTS="$JAVA_OPTS -DdebugModels" ./bin/kotlin-client-petstore.sh By moving the $@ to the end of the args, it allows us to pass additional properties and other switches directly to the script.
This commit is contained in:
@@ -173,9 +173,15 @@ public class CodegenConstants {
|
||||
public static final String EXCLUDE_TESTS = "excludeTests";
|
||||
public static final String EXCLUDE_TESTS_DESC = "Specifies that no tests are to be generated.";
|
||||
|
||||
// Not user-configurable. System provided for use in templates.
|
||||
public static final String GENERATE_API_DOCS = "generateApiDocs";
|
||||
|
||||
public static final String GENERATE_API_TESTS = "generateApiTests";
|
||||
public static final String GENERATE_API_TESTS_DESC = "Specifies that api tests are to be generated.";
|
||||
|
||||
// Not user-configurable. System provided for use in templates.
|
||||
public static final String GENERATE_MODEL_DOCS = "generateModelDocs";
|
||||
|
||||
public static final String GENERATE_MODEL_TESTS = "generateModelTests";
|
||||
public static final String GENERATE_MODEL_TESTS_DESC = "Specifies that model tests are to be generated.";
|
||||
|
||||
|
||||
@@ -120,6 +120,10 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
// Additional properties added for tests to exclude references in project related files
|
||||
config.additionalProperties().put(CodegenConstants.GENERATE_API_TESTS, generateApiTests);
|
||||
config.additionalProperties().put(CodegenConstants.GENERATE_MODEL_TESTS, generateModelTests);
|
||||
|
||||
config.additionalProperties().put(CodegenConstants.GENERATE_API_DOCS, generateApiDocumentation);
|
||||
config.additionalProperties().put(CodegenConstants.GENERATE_MODEL_DOCS, generateModelDocumentation);
|
||||
|
||||
if(!generateApiTests && !generateModelTests) {
|
||||
config.additionalProperties().put(CodegenConstants.EXCLUDE_TESTS, true);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ public class KotlinClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src/main/kotlin";
|
||||
protected String packageName = "io.swagger.client";
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
|
||||
/**
|
||||
* Constructs an instance of `KotlinClientCodegen`.
|
||||
@@ -30,7 +32,8 @@ public class KotlinClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
outputFolder = "generated-code" + File.separator + "kotlin-client";
|
||||
modelTemplateFiles.put("model.mustache", ".kt");
|
||||
apiTemplateFiles.put("api.mustache", ".kt");
|
||||
// TODO: Documentation generation
|
||||
modelDocTemplateFiles.put("model_doc.mustache", ".md");
|
||||
apiDocTemplateFiles.put("api_doc.mustache", ".md");
|
||||
embeddedTemplateDir = templateDir = "kotlin-client";
|
||||
apiPackage = packageName + ".apis";
|
||||
modelPackage = packageName + ".models";
|
||||
@@ -227,7 +230,10 @@ public class KotlinClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage());
|
||||
additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage());
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle"));
|
||||
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
|
||||
@@ -255,11 +261,22 @@ public class KotlinClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return input.replace("\"", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiDocFileFolder() {
|
||||
return (outputFolder + "/" + apiDocPath).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelDocFileFolder() {
|
||||
return (outputFolder + "/" + modelDocPath).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar);
|
||||
|
||||
Reference in New Issue
Block a user