mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-11 13:52:46 +00:00
Update html, dynamic-html petstore, fix example value for form parameters (#122)
* update dynamic-html samples with oas2 * update dynamic-html oas3 (no change) * update html petstore (oas2) * update html petstore with oas3 * fix example value for form parameters * fix javadoc string
This commit is contained in:
@@ -1022,9 +1022,40 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
/**
|
||||
* Return the example value of the parameter.
|
||||
*
|
||||
* @param p Codegen parameter
|
||||
* @param codegenParameter Codegen parameter
|
||||
*/
|
||||
public void setParameterExampleValue(CodegenParameter p) {
|
||||
public void setParameterExampleValue(CodegenParameter codegenParameter) {
|
||||
|
||||
// set the example value
|
||||
// if not specified in x-example, generate a default value
|
||||
// TODO need to revise how to obtain the example value
|
||||
if (codegenParameter.vendorExtensions != null && codegenParameter.vendorExtensions.containsKey("x-example")) {
|
||||
codegenParameter.example = Json.pretty(codegenParameter.vendorExtensions.get("x-example"));
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isBoolean)) {
|
||||
codegenParameter.example = "true";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isLong)) {
|
||||
codegenParameter.example = "789";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isInteger)) {
|
||||
codegenParameter.example = "56";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isFloat)) {
|
||||
codegenParameter.example = "3.4";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isDouble)) {
|
||||
codegenParameter.example = "1.2";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isBinary)) {
|
||||
codegenParameter.example = "BINARY_DATA_HERE";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isByteArray)) {
|
||||
codegenParameter.example = "BYTE_ARRAY_DATA_HERE";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isFile)) {
|
||||
codegenParameter.example = "/path/to/file.txt";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isDate)) {
|
||||
codegenParameter.example = "2013-10-20";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isDateTime)) {
|
||||
codegenParameter.example = "2013-10-20T19:20:30+01:00";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isUuid)) {
|
||||
codegenParameter.example = "38400000-8cf0-11bd-b23e-10b96e4ef00d";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isString)) {
|
||||
codegenParameter.example = codegenParameter.paramName + "_example";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1360,7 +1391,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
allProperties = new LinkedHashMap<String, Schema>();
|
||||
allRequired = new ArrayList<String>();
|
||||
m.allVars = new ArrayList<CodegenProperty>();
|
||||
if(composed.getAllOf() != null) {
|
||||
if (composed.getAllOf() != null) {
|
||||
int modelImplCnt = 0; // only one inline object allowed in a ComposedModel
|
||||
for (Schema innerModel : composed.getAllOf()) {
|
||||
if (m.discriminator == null) {
|
||||
@@ -2345,7 +2376,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
ArraySchema as = (ArraySchema) responseSchema;
|
||||
CodegenProperty innerProperty = fromProperty("response", as.getItems());
|
||||
CodegenProperty innerCp = innerProperty;
|
||||
while(innerCp != null) {
|
||||
while (innerCp != null) {
|
||||
r.baseType = innerCp.baseType;
|
||||
innerCp = innerCp.items;
|
||||
}
|
||||
@@ -2683,39 +2714,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
LOGGER.warn("Unknown parameter type: " + parameter.getName());
|
||||
}
|
||||
|
||||
// set the example value
|
||||
// if not specified in x-example, generate a default value
|
||||
// TODO need to revise how to obtain the example value
|
||||
if (codegenParameter.vendorExtensions != null && codegenParameter.vendorExtensions.containsKey("x-example")) {
|
||||
codegenParameter.example = Json.pretty(codegenParameter.vendorExtensions.get("x-example"));
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isString)) {
|
||||
codegenParameter.example = codegenParameter.paramName + "_example";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isBoolean)) {
|
||||
codegenParameter.example = "true";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isLong)) {
|
||||
codegenParameter.example = "789";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isInteger)) {
|
||||
codegenParameter.example = "56";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isFloat)) {
|
||||
codegenParameter.example = "3.4";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isDouble)) {
|
||||
codegenParameter.example = "1.2";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isBinary)) {
|
||||
codegenParameter.example = "BINARY_DATA_HERE";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isByteArray)) {
|
||||
codegenParameter.example = "B";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isFile)) {
|
||||
codegenParameter.example = "/path/to/file.txt";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isDate)) {
|
||||
codegenParameter.example = "2013-10-20";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isDateTime)) {
|
||||
codegenParameter.example = "2013-10-20T19:20:30+01:00";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isUuid)) {
|
||||
codegenParameter.example = "38400000-8cf0-11bd-b23e-10b96e4ef00d";
|
||||
} else if (Boolean.TRUE.equals(codegenParameter.isFile)) {
|
||||
codegenParameter.example = "/path/to/file.txt";
|
||||
}
|
||||
|
||||
// set the parameter excample value
|
||||
// should be overridden by lang codegen
|
||||
setParameterExampleValue(codegenParameter);
|
||||
|
||||
@@ -60,7 +60,7 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi
|
||||
cliOptions.add(new CliOption(CodegenConstants.GROUP_ID, CodegenConstants.GROUP_ID_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_ID, CodegenConstants.ARTIFACT_ID_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, CodegenConstants.ARTIFACT_VERSION_DESC));
|
||||
|
||||
|
||||
additionalProperties.put("appName", "Swagger Sample");
|
||||
additionalProperties.put("appDescription", "A sample swagger server");
|
||||
additionalProperties.put("infoUrl", "https://helloreverb.com");
|
||||
@@ -123,8 +123,8 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi
|
||||
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||
for (CodegenOperation op : operationList) {
|
||||
op.httpMethod = op.httpMethod.toLowerCase();
|
||||
for (CodegenResponse response : op.responses){
|
||||
if ("0".equals(response.code)){
|
||||
for (CodegenResponse response : op.responses) {
|
||||
if ("0".equals(response.code)) {
|
||||
response.code = "default";
|
||||
}
|
||||
}
|
||||
@@ -202,7 +202,7 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi
|
||||
/**
|
||||
* Parse Markdown to HTML for the main "Description" attribute
|
||||
*
|
||||
* @param swagger The base object containing the global description through "Info" class
|
||||
* @param openAPI The base object containing the global description through "Info" class
|
||||
* @return Void
|
||||
*/
|
||||
private void preparHtmlForGlobalDescription(OpenAPI openAPI) {
|
||||
@@ -213,7 +213,7 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi
|
||||
String currentDescription = openAPI.getInfo().getDescription();
|
||||
if (currentDescription != null && !currentDescription.isEmpty()) {
|
||||
Markdown markInstance = new Markdown();
|
||||
openAPI.getInfo().setDescription( markInstance.toHtml(currentDescription) );
|
||||
openAPI.getInfo().setDescription(markInstance.toHtml(currentDescription));
|
||||
} else {
|
||||
LOGGER.error("OpenAPI object description is empty [" + openAPI.getInfo().getTitle() + "]");
|
||||
}
|
||||
@@ -227,7 +227,7 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi
|
||||
*/
|
||||
public List<CodegenParameter> postProcessParameterEnum(List<CodegenParameter> parameterList) {
|
||||
String enumFormatted = "";
|
||||
for(CodegenParameter parameter : parameterList) {
|
||||
for (CodegenParameter parameter : parameterList) {
|
||||
if (parameter.isEnum) {
|
||||
for (int i = 0; i < parameter._enum.size(); i++) {
|
||||
String spacer = (i == (parameter._enum.size() - 1)) ? " " : ", ";
|
||||
@@ -268,5 +268,5 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
// just return the original string
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user