diff --git a/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin-model/pom.xml b/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin-model/pom.xml index cf08999cd2..e4a2d20ed3 100644 --- a/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin-model/pom.xml +++ b/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin-model/pom.xml @@ -1,7 +1,7 @@ 4.0.0 openapiplugin-model - 7.0.0 + 7.1.0 CobiGen Openapiplugin Model jar CobiGen - OpenAPI Plug-in Model diff --git a/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/pom.xml b/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/pom.xml index 688ed34951..33c6289569 100644 --- a/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/pom.xml +++ b/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/pom.xml @@ -2,7 +2,7 @@ 4.0.0 openapiplugin CobiGen - Open API Plug-in - 7.0.0 + 7.1.0 jar CobiGen - OpenAPI Plug-in diff --git a/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/src/main/java/com/devonfw/cobigen/openapiplugin/inputreader/OpenAPIInputReader.java b/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/src/main/java/com/devonfw/cobigen/openapiplugin/inputreader/OpenAPIInputReader.java index c9f3922f21..ce29c8a2e8 100644 --- a/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/src/main/java/com/devonfw/cobigen/openapiplugin/inputreader/OpenAPIInputReader.java +++ b/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/src/main/java/com/devonfw/cobigen/openapiplugin/inputreader/OpenAPIInputReader.java @@ -401,7 +401,11 @@ private List extractProperties(OpenApi3 openApi, String componentNa List enumElements = new ArrayList<>(); for (Object element : enums) { - enumElements.add(element.toString()); + if (element != null) { + enumElements.add(element.toString()); + } else { + enumElements.add("null"); + } } propModel.setEnumElements(enumElements); } diff --git a/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/src/test/java/com/devonfw/cobigen/openapiplugin/unittest/inputreader/OpenAPIInputReaderTest.java b/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/src/test/java/com/devonfw/cobigen/openapiplugin/unittest/inputreader/OpenAPIInputReaderTest.java index e6bd24c18c..532a21e8d2 100644 --- a/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/src/test/java/com/devonfw/cobigen/openapiplugin/unittest/inputreader/OpenAPIInputReaderTest.java +++ b/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/src/test/java/com/devonfw/cobigen/openapiplugin/unittest/inputreader/OpenAPIInputReaderTest.java @@ -279,6 +279,29 @@ public void testInvalidPath() throws Exception { List inputObjects = getInputs("invalidPath.yaml"); } + /** + * Tests if the input reader can handle nullable enums. See: + * https://github.com/devonfw/cobigen/issues/1244 + * + * @throws Exception + */ + @Test + public void testNullableEnum() throws Exception { + List inputObjects = getInputs("nullableEnum.yaml"); + + for (Object o : inputObjects) { + if (isEntityDef(o)) { + EntityDef entity = (EntityDef) o; + List properties = entity.getProperties(); + for (PropertyDef p : properties) { + List enums = p.getEnumElements(); + assertThat(enums.get(0)).isEqualTo("enum1"); + assertThat(enums.get(1)).isEqualTo("null"); + } + } + } + } + @Test(expected = InvalidConfigurationException.class) public void testInvalidXComponent() throws Exception { List inputObjects = getInputs("invalidXComponent.yaml"); @@ -414,4 +437,14 @@ private boolean isComponentDef(Object o) { return o.getClass() == ComponentDef.class; } + /** + * Checks whether the object is an {@link EntityDef} + * @param o + * object to check whether it is an EntityDef + * @return true if it is an EntityDef + */ + private boolean isPropertyDef(Object o) { + return o.getClass() == PropertyDef.class; + } + } diff --git a/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/src/test/resources/testdata/unittest/OpenAPIInputReaderTest/nullableEnum.yaml b/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/src/test/resources/testdata/unittest/OpenAPIInputReaderTest/nullableEnum.yaml new file mode 100644 index 0000000000..2df91b9b91 --- /dev/null +++ b/cobigen/cobigen-openapiplugin-parent/cobigen-openapiplugin/src/test/resources/testdata/unittest/OpenAPIInputReaderTest/nullableEnum.yaml @@ -0,0 +1,36 @@ +openapi: 3.0.0 +servers: + - url: 'https://localhost:8081/server/services/rest' +info: + title: Devon Example + description: Example of a API definition + version: 1.0.0 +paths: + /tablemanagement/v1/table/{id}: + get: + operationId: findTable + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + minimum: 0 + maximum: 50 + responses: + '200': + description: Any +components: + schemas: + Table: + x-component: tablemanagament + description: Entity definiton of Table + type: object + properties: + myenum: + type: string + nullable: true + enum: + - enum1 + - null \ No newline at end of file diff --git a/documentation/master-cobigen.asciidoc b/documentation/master-cobigen.asciidoc index b956a5b625..1c394b26d1 100644 --- a/documentation/master-cobigen.asciidoc +++ b/documentation/master-cobigen.asciidoc @@ -25,7 +25,7 @@ DISCLAIMER: All Cobigen plugins are compatible with the latest release of Devonf * CobiGen - Text Merger v7.1.0 * CobiGen - JSON Plug-in v7.0.0 * CobiGen - HTML Plug-in v7.0.0 -* CobiGen - Open API Plug-in v7.0.0 +* CobiGen - Open API Plug-in v7.1.0 * CobiGen - FreeMaker Template Engine v7.0.0 * CobiGen - Velocity Template Engine v7.0.0