forked from loafle/openapi-generator-original
issue #1347
This is a fix to support enums in query parameters. Enum-related information was not being stored on `CodegenParameter` previously; it is now. Test cases have been added to make sure that the enum information is being properly processed from the model.
This commit is contained in:
@@ -81,6 +81,40 @@ public class CodegenTest {
|
||||
Assert.assertNull(statusParam.hasMore);
|
||||
}
|
||||
|
||||
@Test(description = "handle enum array in query parameter test")
|
||||
public void enumArrayQueryParameterTest() {
|
||||
final Swagger model = parseAndPrepareSwagger("src/test/resources/2_0/petstore.json");
|
||||
final DefaultCodegen codegen = new DefaultCodegen();
|
||||
final String path = "/pet/findByStatus";
|
||||
final Operation p = model.getPaths().get(path).getGet();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "get", p, model.getDefinitions());
|
||||
|
||||
Assert.assertEquals(op.queryParams.size(), 1);
|
||||
|
||||
final CodegenParameter statusParam = op.queryParams.get(0);
|
||||
Assert.assertEquals(statusParam.items.datatypeWithEnum, "StatusEnum");
|
||||
Assert.assertNotNull(statusParam.items);
|
||||
Assert.assertTrue(statusParam.items.isEnum);
|
||||
Assert.assertEquals(statusParam.items._enum.size(), 3);
|
||||
}
|
||||
|
||||
@Test(description = "handle enum in query parameter test")
|
||||
public void enumQueryParameterTest() {
|
||||
final Swagger model = parseAndPrepareSwagger("src/test/resources/2_0/petstore.json");
|
||||
final DefaultCodegen codegen = new DefaultCodegen();
|
||||
final String path = "/store/findByStatus";
|
||||
final Operation p = model.getPaths().get(path).getGet();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "get", p, model.getDefinitions());
|
||||
|
||||
Assert.assertEquals(op.queryParams.size(), 1);
|
||||
|
||||
final CodegenParameter statusParam = op.queryParams.get(0);
|
||||
Assert.assertEquals(statusParam.datatypeWithEnum, "StatusEnum");
|
||||
Assert.assertTrue(statusParam.isEnum);
|
||||
Assert.assertEquals(statusParam._enum.size(), 3);
|
||||
}
|
||||
|
||||
|
||||
@Test(description = "handle required parameters from a 2.0 spec as required when figuring out Swagger types")
|
||||
public void requiredParametersTest() {
|
||||
final Swagger model = parseAndPrepareSwagger("src/test/resources/2_0/requiredTest.json");
|
||||
|
||||
Reference in New Issue
Block a user