forked from loafle/openapi-generator-original
[Java][jaxrs-spec] enumUnknownDefaultCase true now returns correctly in fromValue (#18910)
* enumUnknownDefaultCase true added for Jaxrs-spec * Updated tests --------- Co-authored-by: Dean <dean.kane@opencastsoftware.com>
This commit is contained in:
parent
ef7654958e
commit
fc0105e214
@ -43,6 +43,6 @@
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}return {{{name}}};{{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/enumUnknownDefaultCase}}{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,6 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}return {{{name}}};{{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/enumUnknownDefaultCase}}{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1033,4 +1033,51 @@ public class JavaJAXRSSpecServerCodegenTest extends JavaJaxrsBaseTest {
|
|||||||
" info = @org.eclipse.microprofile.openapi.annotations.info.Info(\n" +
|
" info = @org.eclipse.microprofile.openapi.annotations.info.Info(\n" +
|
||||||
" title = \"user\", version=\"1.0.0\", description=\"Operations about user\",");
|
" title = \"user\", version=\"1.0.0\", description=\"Operations about user\",");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnumUnknownDefaultCaseDeserializationTrue_issue13444() throws Exception {
|
||||||
|
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||||
|
output.deleteOnExit();
|
||||||
|
|
||||||
|
OpenAPI openAPI = new OpenAPIParser()
|
||||||
|
.readLocation("src/test/resources/bugs/issue_13444.yaml", null, new ParseOptions()).getOpenAPI();
|
||||||
|
|
||||||
|
codegen.setOutputDir(output.getAbsolutePath());
|
||||||
|
codegen.additionalProperties().put(CodegenConstants.ENUM_UNKNOWN_DEFAULT_CASE, "true");
|
||||||
|
|
||||||
|
ClientOptInput input = new ClientOptInput()
|
||||||
|
.openAPI(openAPI)
|
||||||
|
.config(codegen);
|
||||||
|
|
||||||
|
DefaultGenerator generator = new DefaultGenerator();
|
||||||
|
Map<String, File> files = generator.opts(input).generate().stream()
|
||||||
|
.collect(Collectors.toMap(File::getName, Function.identity()));
|
||||||
|
|
||||||
|
JavaFileAssert.assertThat(files.get("Color.java"))
|
||||||
|
.assertMethod("fromValue").bodyContainsLines("return UNKNOWN_DEFAULT_OPEN_API");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnumUnknownDefaultCaseDeserializationNotSet_issue13444() throws Exception {
|
||||||
|
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||||
|
output.deleteOnExit();
|
||||||
|
|
||||||
|
OpenAPI openAPI = new OpenAPIParser()
|
||||||
|
.readLocation("src/test/resources/bugs/issue_13444.yaml", null, new ParseOptions()).getOpenAPI();
|
||||||
|
|
||||||
|
codegen.setOutputDir(output.getAbsolutePath());
|
||||||
|
|
||||||
|
ClientOptInput input = new ClientOptInput()
|
||||||
|
.openAPI(openAPI)
|
||||||
|
.config(codegen);
|
||||||
|
|
||||||
|
DefaultGenerator generator = new DefaultGenerator();
|
||||||
|
Map<String, File> files = generator.opts(input).generate().stream()
|
||||||
|
.collect(Collectors.toMap(File::getName, Function.identity()));
|
||||||
|
|
||||||
|
JavaFileAssert.assertThat(files.get("Color.java"))
|
||||||
|
.assertMethod("fromValue").bodyContainsLines("throw new IllegalArgumentException(\"Unexpected value '\" + value + \"'\");");
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
openapi: "3.0.0"
|
||||||
|
info:
|
||||||
|
version: 2.0.0
|
||||||
|
title: test
|
||||||
|
paths:
|
||||||
|
/pets:
|
||||||
|
get:
|
||||||
|
summary: List all pets
|
||||||
|
operationId: listPets
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: OK
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
Color:
|
||||||
|
type: string
|
||||||
|
enum: [RED, BLUE, GREEN]
|
Loading…
x
Reference in New Issue
Block a user