forked from loafle/openapi-generator-original
Add "docExtension" option to customize generated file extension for docs (#591)
This commit is contained in:
committed by
Jérémie Bresson
parent
ab9be95442
commit
c70ed678f6
@@ -230,6 +230,10 @@ public interface CodegenConfig {
|
||||
|
||||
String getHttpUserAgent();
|
||||
|
||||
void setDocExtension(String docExtension);
|
||||
|
||||
String getDocExtension();
|
||||
|
||||
String getCommonTemplateDir();
|
||||
|
||||
void setIgnoreFilePathOverride(String ignoreFileOverride);
|
||||
|
||||
@@ -254,4 +254,7 @@ public class CodegenConstants {
|
||||
|
||||
public static final String STRIP_PACKAGE_NAME = "stripPackageName";
|
||||
public static final String STRIP_PACKAGE_NAME_DESC = "Whether to strip leading dot-separated packages from generated model classes";
|
||||
|
||||
public static final String DOCEXTENSION = "docExtension";
|
||||
public static final String DOCEXTENSION_DESC = "The extension of the generated documentation files, defaults to markdown, .md";
|
||||
}
|
||||
|
||||
@@ -114,6 +114,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
// When a model is an alias for a simple type
|
||||
protected Map<String, String> typeAliases = null;
|
||||
protected Boolean prependFormOrBodyParameters = false;
|
||||
// The extension of the generated documentation files (defaults to markdown .md)
|
||||
protected String docExtension;
|
||||
|
||||
protected String ignoreFilePathOverride;
|
||||
|
||||
@@ -172,6 +174,11 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
this.setRemoveOperationIdPrefix(Boolean.valueOf(additionalProperties
|
||||
.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.DOCEXTENSION)){
|
||||
this.setDocExtension(String.valueOf(additionalProperties
|
||||
.get(CodegenConstants.DOCEXTENSION).toString()));
|
||||
}
|
||||
}
|
||||
|
||||
// override with any special post-processing for all models
|
||||
@@ -3415,7 +3422,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @return the API documentation file name with full path
|
||||
*/
|
||||
public String apiDocFilename(String templateName, String tag) {
|
||||
String suffix = apiDocTemplateFiles().get(templateName);
|
||||
String docExtension = getDocExtension();
|
||||
String suffix = docExtension != null ? docExtension: apiDocTemplateFiles().get(templateName);
|
||||
return apiDocFileFolder() + File.separator + toApiDocFilename(tag) + suffix;
|
||||
}
|
||||
|
||||
@@ -3552,6 +3560,25 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return releaseNote;
|
||||
}
|
||||
|
||||
/**
|
||||
* Documentation files extension
|
||||
*
|
||||
* @return Documentation files extension
|
||||
*/
|
||||
public String getDocExtension() {
|
||||
return docExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Documentation files extension
|
||||
*
|
||||
* @param userDocExtension documentation files extension
|
||||
*/
|
||||
public void setDocExtension(String userDocExtension) {
|
||||
this.docExtension = userDocExtension;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set HTTP user agent.
|
||||
*
|
||||
|
||||
@@ -278,7 +278,8 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
|
||||
private void generateModelDocumentation(List<File> files, Map<String, Object> models, String modelName) throws IOException {
|
||||
for (String templateName : config.modelDocTemplateFiles().keySet()) {
|
||||
String suffix = config.modelDocTemplateFiles().get(templateName);
|
||||
String docExtension = config.getDocExtension();
|
||||
String suffix = docExtension!=null ? docExtension : config.modelDocTemplateFiles().get(templateName);
|
||||
String filename = config.modelDocFileFolder() + File.separator + config.toModelDocFilename(modelName) + suffix;
|
||||
if (!config.shouldOverwrite(filename)) {
|
||||
LOGGER.info("Skipped overwriting " + filename);
|
||||
|
||||
Reference in New Issue
Block a user