Skip to content

Commit

Permalink
Merge branch 'dev_openapiplugin'
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSchumacherCapgemini committed Dec 4, 2020
2 parents e0a0b0f + 7d789c6 commit 65419ae
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>openapiplugin-model</artifactId>
<version>7.0.0</version>
<version>7.1.0</version>
<name>CobiGen Openapiplugin Model</name>
<packaging>jar</packaging>
<description>CobiGen - OpenAPI Plug-in Model</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>openapiplugin</artifactId>
<name>CobiGen - Open API Plug-in</name>
<version>7.0.0</version>
<version>7.1.0</version>
<packaging>jar</packaging>
<description>CobiGen - OpenAPI Plug-in</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ private List<PropertyDef> extractProperties(OpenApi3 openApi, String componentNa

List<String> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,29 @@ public void testInvalidPath() throws Exception {
List<Object> 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<Object> inputObjects = getInputs("nullableEnum.yaml");

for (Object o : inputObjects) {
if (isEntityDef(o)) {
EntityDef entity = (EntityDef) o;
List<PropertyDef> properties = entity.getProperties();
for (PropertyDef p : properties) {
List<String> 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<Object> inputObjects = getInputs("invalidXComponent.yaml");
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion documentation/master-cobigen.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 65419ae

Please sign in to comment.