test all generators with fake petstore spec 2.0, 3.0 (#1439)

This commit is contained in:
William Cheng 2018-11-14 15:55:09 +08:00 committed by GitHub
parent df1819daa9
commit 0165b0fb33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 4 deletions

View File

@ -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

View File

@ -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)) {

View File

@ -0,0 +1 @@
{{#allowableValues}}allowableValues="{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}{{^values}}range=[{{#min}}{{.}}{{/min}}{{^min}}-infinity{{/min}}, {{#max}}{{.}}{{/max}}{{^max}}infinity{{/max}}]{{/values}}"{{/allowableValues}}

View File

@ -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