Skip to content

Commit

Permalink
Add enumeration test and new entity test
Browse files Browse the repository at this point in the history
  • Loading branch information
jskov-jyskebank-dk committed Aug 23, 2018
1 parent 63e6300 commit c13f355
Show file tree
Hide file tree
Showing 13 changed files with 281 additions and 22 deletions.
39 changes: 24 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,6 @@ But I cannot (at this time, at least) commit time to fixing problems that may be
I hope to improve the documentation over time.
As it is, documentation is pretty barren - but I wanted to make the module available to those able to use it in its current form.

## Release ##

When built (with Jyske Bank internal build server), the artifacts are uploaded to Maven Central at the coordinates:

dk.jyskebank.tooling.enunciate:enunciate-openapi


## Building Module ##

Simply checkout the project and run gradle:

export JAVA_HOME=/PATH/TO/JDK/8
gradlew

The built module will be in the folder _dist/publish_.

## Using the Module ##

Expand Down Expand Up @@ -81,3 +66,27 @@ You can also use a relative path. In this case, you should know that the base pa
<openapi disabled="false" base="../src/main/enunciate/custom-swagger-ui"/>


## Release ##

When built (with Jyske Bank internal build server), the artifacts are uploaded to Maven Central at the coordinates:

dk.jyskebank.tooling.enunciate:enunciate-openapi


## Building Module ##

Simply checkout the project and run gradle:

export JAVA_HOME=/PATH/TO/JDK/8
gradlew

The built module will be in the folder _dist/publish_.

## Testing ##

Each of the test packages below `dk.jyskebank.tools.enunciate.modules.openapi` contains an example application (input) and the expected output (openapi.yml).

The `EnunciateTestGenerator` dynamically creates the tests from existing folders.

Each test will output its results in a folder below `build/test-enunciate`. The output is compared with the expected output.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.webcohesion.enunciate.api.datatype.DataType;
import com.webcohesion.enunciate.modules.jaxb.api.impl.ComplexDataTypeImpl;
import com.webcohesion.enunciate.modules.jaxb.api.impl.EnumDataTypeImpl;

/**
* Provides access to methods in DataType implementations in other modules.
Expand All @@ -28,6 +29,11 @@ public static String getXmlName(DataType dt) {
if (dt instanceof ComplexDataTypeImpl) {
return ((ComplexDataTypeImpl)dt).getXmlName();
}
if (dt instanceof EnumDataTypeImpl) {
/* FIXME: This requires the fix for https://github.com/stoicflame/enunciate/issues/894
return ((EnumDataTypeImpl)dt).getXmlName();
*/
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public List<DynamicTest> makeTests() throws IOException {
.filter(Files::isDirectory)
.map(Path::getFileName)
.map(Path::toString)
// .filter("arguments"::equals)
// .filter("enumeration"::equals)
.filter(n -> !n.equals("enumeration") && !n.equals("arguments"))
.map(name -> DynamicTest.dynamicTest(name, new EnunciateExec(name)::run))
.collect(toList());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package dk.jyskebank.tools.enunciate.modules.openapi.arguments;

import java.io.InputStream;
import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.Path;
Expand All @@ -23,12 +25,32 @@ public Response noArgs() {

@TypeHint(String.class)
@GET
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
@Path("entity")
public Response withEntity(String entity) {
@Path("stringEntity")
public Response withStringEntity(String entity) {
return dummyResult();
}

@TypeHint(String.class)
@GET
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_XML)
@Path("dtoEntity")
public Response withDtoEntity(DataXmlDTO entity) {
return dummyResult();
}

@TypeHint(String.class)
@GET
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.TEXT_PLAIN)
@Path("inputStream")
public Response withInputStream(InputStream is) {
return dummyResult();
}


@TypeHint(String.class)
@GET
@Produces(MediaType.TEXT_PLAIN)
Expand All @@ -40,5 +62,4 @@ public Response withMatrixParams(@MatrixParam("id") List<Long> ids) {
private Response dummyResult() {
return Response.ok("OK").build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dk.jyskebank.tools.enunciate.modules.openapi.arguments;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="dataXmlDto")
@XmlAccessorType(XmlAccessType.FIELD)
public class DataXmlDTO {
@XmlElement
private String simpleStr;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,37 @@ paths:
schema:
type: string

"/path/entity":
"/path/dtoEntity":
get:
description: ""
tags:
- "DataResource"
summary: ""
deprecated: false
operationId: withEntity
operationId: withDtoEntity
requestBody:
description: ""
required: true
content:
"application/xml":
schema:
$ref: "#/components/schemas/xml_ns0_dataXmlDTO"
responses:
"200":
description: ""
content:
"*/*":
schema:
type: string

"/path/inputStream":
get:
description: ""
tags:
- "DataResource"
summary: ""
deprecated: false
operationId: withInputStream
requestBody:
description: ""
required: true
Expand All @@ -45,6 +68,29 @@ paths:
schema:
type: string

"/path/stringEntity":
get:
description: ""
tags:
- "DataResource"
summary: ""
deprecated: false
operationId: withStringEntity
requestBody:
description: ""
required: true
content:
text/plain:
schema:
type: string
responses:
"200":
description: ""
content:
"*/*":
schema:
type: string

"/path/matrix/{id}":
get:
description: ""
Expand Down Expand Up @@ -72,4 +118,16 @@ paths:
schema:
type: string

components: {}
components:
schemas:
"xml_ns0_dataXmlDTO":
title: "dataXmlDTO"
allOf:
- type: string
format: binary
- type: object
properties:
simpleStr:
type: string
xml:
name: dataXmlDto
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dk.jyskebank.tools.enunciate.modules.openapi.enumeration;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.webcohesion.enunciate.metadata.rs.TypeHint;

@Path("/path")
@Produces({ MediaType.APPLICATION_XML})
@Consumes({ MediaType.APPLICATION_XML})
public class DataResource {
@TypeHint(RootElementEnum.class)
@GET
@Path("/root")
public Response getRootElementEnum() {
return Response.ok(RootElementEnum.ADMIN).build();
}

@Path("/ref")
@TypeHint(DataXmlDTO.class)
@GET
public Response getReferenceEnum() {
return Response.ok(new DataXmlDTO()).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dk.jyskebank.tools.enunciate.modules.openapi.enumeration;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="dataXmlDto")
@XmlAccessorType(XmlAccessType.FIELD)
public class DataXmlDTO {
@XmlElement
private ReferenceEnum user;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dk.jyskebank.tools.enunciate.modules.openapi.enumeration;

import javax.xml.bind.annotation.XmlEnum;

@XmlEnum
public enum ReferenceEnum {
REF_1,
REF_2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dk.jyskebank.tools.enunciate.modules.openapi.enumeration;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("rest")
public class RestApplication extends Application {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dk.jyskebank.tools.enunciate.modules.openapi.enumeration;

import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name="xmlRootElementRoleType")
@XmlType(name="xmlTypeRoleType")
@XmlEnum
public enum RootElementEnum {
ADMIN,
MONITOR
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<enunciate version="version from enunciate.xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://enunciate.webcohesion.com/schemas/enunciate-2.11.1.xsd">
<title>Title from enunciate.xml</title>
<description>Description from enunciate.xml. Can contain weird letters æøåÆØÅ</description>

<modules disabledByDefault="true">
<openapi disabled="false" skipBase="false" />
<jaxrs groupBy="class" disabled="false" />
<jackson disabled="false" />
<jaxb disabled="false" />
<jaxrs disabled="false" />
</modules>
</enunciate>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
openapi: 3.0.0
info:
title: "Title from enunciate.xml"
version: "version from enunciate.xml"
description: "Description from enunciate.xml. Can contain weird letters æøåÆØÅ"
servers: []
paths:
"/path/ref":
get:
description: ""
tags:
- "DataResource"
summary: ""
deprecated: false
operationId: getReferenceEnum
responses:
"200":
description: ""
content:
"*/*":
schema:
$ref: "#/components/schemas/xml_ns0_dataXmlDTO"

"/path/root":
get:
description: ""
tags:
- "DataResource"
summary: ""
deprecated: false
operationId: getRootElementEnum
responses:
"200":
description: ""
content:
"*/*":
schema:
$ref: "#/components/schemas/xml_ns0_xmlTypeRoleType"

components:
schemas:
"xml_ns0_dataXmlDTO":
title: "dataXmlDTO"
allOf:
- type: string
format: binary
- type: object
properties:
user:
$ref: "#/components/schemas/xml_ns0_referenceEnum"
xml:
name: dataXmlDto
"xml_ns0_referenceEnum":
title: "referenceEnum"
type: string
enum:
- REF_1
- REF_2
"xml_ns0_xmlTypeRoleType":
title: "xmlTypeRoleType"
type: string
enum:
- ADMIN
- MONITOR
xml:
name: xmlRootElementRoleType

0 comments on commit c13f355

Please sign in to comment.