diff --git a/bin/utils/test-fake-petstore-for-all.sh b/bin/utils/test-fake-petstore-for-all.sh new file mode 100755 index 00000000000..b9e1cc47f1e --- /dev/null +++ b/bin/utils/test-fake-petstore-for-all.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# +# A script to test all generators to ensure there's no Java exception when running it with OAS 2.0, 3.0 fake petstore spec +# + +SCRIPT="$0" +echo "# START SCRIPT: ${SCRIPT}" + +executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" + +for GENERATOR in $(java -jar ${executable} list --short | sed -e 's/,/\'$'\n''/g') +do + if eval java -jar ${executable} generate -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g ${GENERATOR} -o /tmp/openapi-generator-test-fake-petstore/2.0/${GENERATOR} > /dev/null 2>&1; then + echo "[OAS 2.0] Executed ${GENERATOR} successfully!" + else + echo "ERROR: Failed to run ${GENERATOR}" + echo "java -jar ${executable} generate -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g ${GENERATOR} -o /tmp/openapi-generator-test-fake-petstore/2.0/${GENERATOR}" + exit 1 + fi + + if eval java -jar ${executable} generate -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g ${GENERATOR} -o /tmp/openapi-generator-test-fake-petstore/3.0/${GENERATOR} > /dev/null 2>&1; then + echo "[OAS 3.0] Executed ${GENERATOR} successfully!" + else + echo "ERROR: Failed to run ${GENERATOR}" + echo "java -jar ${executable} generate -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g ${GENERATOR} -o /tmp/openapi-generator-test-fake-petstore/3.0/${GENERATOR}" + exit 1 + fi +done diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java index 07d06a03b04..1fcc2c77edb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java @@ -261,7 +261,13 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String toEnumVarName(String value, String datatype) { - final String camelized = org.openapitools.codegen.utils.StringUtils.camelize(value.replace(" ", "_").replace("(", "_").replace(")", "")); // TODO FIXME escape properly + String camelized = org.openapitools.codegen.utils.StringUtils.camelize(value.replace(" ", "_").replace("(", "_").replace(")", "")); // TODO FIXME escape properly + + if (camelized.length() == 0) { + LOGGER.error("Unable to determine enum variable name (name: {}, datatype: {}) from empty string. Default to UnknownEnumVariableName", value, datatype); + camelized = "UnknownEnumVariableName"; + } + if (!Character.isUpperCase(camelized.charAt(0))) { return "N" + camelized; } @@ -495,9 +501,8 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { } else if (ModelUtils.isDateTimeSchema(p)) { return toOptionalValue(null); } else if (ModelUtils.isNumberSchema(p)) { - NumberSchema dp = (NumberSchema) p; - if (dp.getDefault() != null) { - return toOptionalValue(dp.getDefault().toString()); + if (p.getDefault() != null) { + return toOptionalValue(p.getDefault().toString()); } return toOptionalValue(null); } else if (ModelUtils.isIntegerSchema(p)) { diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/eap/allowableValues.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/eap/allowableValues.mustache new file mode 100644 index 00000000000..a48256d027a --- /dev/null +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/eap/allowableValues.mustache @@ -0,0 +1 @@ +{{#allowableValues}}allowableValues="{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}{{^values}}range=[{{#min}}{{.}}{{/min}}{{^min}}-infinity{{/min}}, {{#max}}{{.}}{{/max}}{{^max}}infinity{{/max}}]{{/values}}"{{/allowableValues}} \ No newline at end of file diff --git a/shippable.yml b/shippable.yml index 85621905a47..0e463b9827e 100644 --- a/shippable.yml +++ b/shippable.yml @@ -44,3 +44,5 @@ build: - ./bin/openapi3/run-all-petstore # generate test scripts - ./bin/tests/run-all-test + # test all generators with fake petstore spec (2.0, 3.0) + - ./bin/utils/test-fake-petstore-for-all.sh