mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-06 02:25:20 +00:00
[Java] Generated API class has wrong dataType and does not compile Issue (#5331)
* add unit test assertion * add check for composed schema * add support for x-allOf-name * change x-allOf-name to x-all-of-name * Add more troubleshooting information * Add more troubleshooting information * Add more troubleshooting information * Add more troubleshooting information
This commit is contained in:
parent
b40257f53a
commit
a16079ce7b
@ -7,22 +7,27 @@ SCRIPT="$0"
|
||||
echo "# START SCRIPT: ${SCRIPT}"
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
logfile="/tmp/generator-fake-petstore-output.log"
|
||||
|
||||
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
|
||||
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} > ${logfile} 2>&1; then
|
||||
echo "[OAS 2.0] Executed ${GENERATOR} successfully!"
|
||||
else
|
||||
echo "ERROR: Failed to run ${GENERATOR}"
|
||||
echo "ERROR: Failed to run '${GENERATOR}' generator. The command was:"
|
||||
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}"
|
||||
echo "ERROR: The output of the command was:"
|
||||
cat ${logfile}
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if eval java -jar ${executable} generate -i modules/openapi-generator/src/test/resources/3_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
|
||||
if eval java -jar ${executable} generate -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g ${GENERATOR} -o /tmp/openapi-generator-test-fake-petstore/3.0/${GENERATOR} > ${logfile} 2>&1; then
|
||||
echo "[OAS 3.0] Executed ${GENERATOR} successfully!"
|
||||
else
|
||||
echo "ERROR: Failed to run ${GENERATOR}"
|
||||
echo "ERROR: Failed to run '${GENERATOR}' generator. The command was:"
|
||||
echo "java -jar ${executable} generate -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g ${GENERATOR} -o /tmp/openapi-generator-test-fake-petstore/3.0/${GENERATOR}"
|
||||
echo "ERROR: The output of the command was:"
|
||||
cat ${logfile}
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
@ -1788,6 +1788,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String toAllOfName(List<String> names, ComposedSchema composedSchema) {
|
||||
Map<String, Object> exts = composedSchema.getExtensions();
|
||||
if (exts != null && exts.containsKey("x-all-of-name")) {
|
||||
return (String) exts.get("x-all-of-name");
|
||||
}
|
||||
if (names.size() == 0) {
|
||||
LOGGER.error("allOf has no member defined: {}. Default to ERROR_ALLOF_SCHEMA", composedSchema);
|
||||
return "ERROR_ALLOF_SCHEMA";
|
||||
@ -5272,6 +5276,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
ModelUtils.syncValidationProperties(schema, codegenParameter);
|
||||
|
||||
if (ModelUtils.isMapSchema(schema)) {
|
||||
// Schema with additionalproperties: true (including composed schemas with additionalproperties: true)
|
||||
Schema inner = ModelUtils.getAdditionalProperties(schema);
|
||||
if (inner == null) {
|
||||
LOGGER.error("No inner type supplied for map parameter `{}`. Default to type:string", schema.getName());
|
||||
|
@ -739,7 +739,9 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
Schema<?> items = getSchemaItems((ArraySchema) p);
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, items)) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
} else if (ModelUtils.isMapSchema(p) && !ModelUtils.isComposedSchema(p)) {
|
||||
// Note: ModelUtils.isMapSchema(p) returns true when p is a composed schema that also defines
|
||||
// additionalproperties: true
|
||||
Schema<?> inner = getSchemaAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<String, " + getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, inner)) + ">";
|
||||
}
|
||||
|
@ -172,6 +172,7 @@ public class JavaModelEnumTest {
|
||||
codegen.setOpenAPI(openAPI);
|
||||
|
||||
Schema enumTest = openAPI.getComponents().getSchemas().get("Enum_Test");
|
||||
Assert.assertNotNull(enumTest);
|
||||
CodegenModel cm = codegen.fromModel("Enum_Test", enumTest);
|
||||
|
||||
Assert.assertEquals(cm.getVars().size(), 8);
|
||||
|
Loading…
Reference in New Issue
Block a user