Skip to content

Commit

Permalink
fix java8 datetime jaxrs-resteasy
Browse files Browse the repository at this point in the history
  • Loading branch information
autodidacticon committed Jul 25, 2021
1 parent fe9636e commit 1d4a343
Show file tree
Hide file tree
Showing 43 changed files with 2,135 additions and 20 deletions.
8 changes: 8 additions & 0 deletions bin/configs/jaxrs-resteasy-java8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
generatorName: jaxrs-resteasy
outputDir: samples/server/petstore/jaxrs-resteasy/java8
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy
additionalProperties:
artifactId: jaxrs-resteasy-java8-server
hideGenerationTimestamp: "true"
dateLibrary: java8
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package {{invokerPackage}};

import com.fasterxml.jackson.databind.ObjectMapper;
{{#java8}}
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
{{/java8}}
{{^java8}}
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.format.ISODateTimeFormat;
{{/java8}}

import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
Expand All @@ -21,7 +26,10 @@ public class JacksonConfig implements ContextResolver<ObjectMapper> {
public JacksonConfig() throws Exception {
objectMapper = new ObjectMapper()
.setDateFormat(new RFC3339DateFormat())
{{#java8}}
.registerModule(new JavaTimeModule())
{{/java8}}
{{^java8}}
.registerModule(new JodaModule() {
{
addSerializer(DateTime.class, new StdSerializer<DateTime>(DateTime.class) {
Expand All @@ -38,10 +46,12 @@ public class JacksonConfig implements ContextResolver<ObjectMapper> {
});

}
});
})
{{/java8}}
.setDateFormat(new RFC3339DateFormat());
}

public ObjectMapper getContext(Class<?> arg0) {
return objectMapper;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,25 @@
<scope>provided</scope>
</dependency>

{{#java8}}
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson-version}</version>
</dependency>
{{/java8}}
{{^java8}}
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.11.2</version>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.7</version>
</dependency>
{{/java8}}
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
Expand Down Expand Up @@ -189,6 +198,7 @@
</repositories>
<properties>
<swagger-core-version>1.5.22</swagger-core-version>
<jackson-version>2.11.2</jackson-version>
<jetty-version>9.2.9.v20150224</jetty-version>
<resteasy-version>3.13.0.Final</resteasy-version>
<slf4j-version>1.6.3</slf4j-version>
Expand Down
3 changes: 2 additions & 1 deletion samples/server/petstore/jaxrs-resteasy/default-value/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.11.2</version>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
Expand Down Expand Up @@ -187,6 +187,7 @@
</repositories>
<properties>
<swagger-core-version>1.5.22</swagger-core-version>
<jackson-version>2.11.2</jackson-version>
<jetty-version>9.2.9.v20150224</jetty-version>
<resteasy-version>3.13.0.Final</resteasy-version>
<slf4j-version>1.6.3</slf4j-version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.openapitools.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.fasterxml.jackson.datatype.joda.JodaModule;
Expand All @@ -21,7 +21,6 @@ public class JacksonConfig implements ContextResolver<ObjectMapper> {
public JacksonConfig() throws Exception {

objectMapper = new ObjectMapper()
.setDateFormat(new RFC3339DateFormat())
.registerModule(new JodaModule() {
{
addSerializer(DateTime.class, new StdSerializer<DateTime>(DateTime.class) {
Expand All @@ -38,10 +37,11 @@ public void serialize(LocalDate value, JsonGenerator jgen, SerializerProvider pr
});

}
});
})
.setDateFormat(new RFC3339DateFormat());
}

public ObjectMapper getContext(Class<?> arg0) {
return objectMapper;
}
}
}
3 changes: 2 additions & 1 deletion samples/server/petstore/jaxrs-resteasy/default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.11.2</version>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
Expand Down Expand Up @@ -187,6 +187,7 @@
</repositories>
<properties>
<swagger-core-version>1.5.22</swagger-core-version>
<jackson-version>2.11.2</jackson-version>
<jetty-version>9.2.9.v20150224</jetty-version>
<resteasy-version>3.13.0.Final</resteasy-version>
<slf4j-version>1.6.3</slf4j-version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.openapitools.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.fasterxml.jackson.datatype.joda.JodaModule;
Expand All @@ -21,7 +21,6 @@ public class JacksonConfig implements ContextResolver<ObjectMapper> {
public JacksonConfig() throws Exception {

objectMapper = new ObjectMapper()
.setDateFormat(new RFC3339DateFormat())
.registerModule(new JodaModule() {
{
addSerializer(DateTime.class, new StdSerializer<DateTime>(DateTime.class) {
Expand All @@ -38,10 +37,11 @@ public void serialize(LocalDate value, JsonGenerator jgen, SerializerProvider pr
});

}
});
})
.setDateFormat(new RFC3339DateFormat());
}

public ObjectMapper getContext(Class<?> arg0) {
return objectMapper;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.openapi-generator-ignore
README.md
build.gradle
pom.xml
settings.gradle
src/gen/java/org/openapitools/api/ApiException.java
src/gen/java/org/openapitools/api/ApiOriginFilter.java
src/gen/java/org/openapitools/api/ApiResponseMessage.java
src/gen/java/org/openapitools/api/JacksonConfig.java
src/gen/java/org/openapitools/api/LocalDateProvider.java
src/gen/java/org/openapitools/api/NotFoundException.java
src/gen/java/org/openapitools/api/OffsetDateTimeProvider.java
src/gen/java/org/openapitools/api/PetApi.java
src/gen/java/org/openapitools/api/PetApiService.java
src/gen/java/org/openapitools/api/RFC3339DateFormat.java
src/gen/java/org/openapitools/api/RestApplication.java
src/gen/java/org/openapitools/api/StoreApi.java
src/gen/java/org/openapitools/api/StoreApiService.java
src/gen/java/org/openapitools/api/StringUtil.java
src/gen/java/org/openapitools/api/UserApi.java
src/gen/java/org/openapitools/api/UserApiService.java
src/gen/java/org/openapitools/model/Category.java
src/gen/java/org/openapitools/model/ModelApiResponse.java
src/gen/java/org/openapitools/model/Order.java
src/gen/java/org/openapitools/model/Pet.java
src/gen/java/org/openapitools/model/Tag.java
src/gen/java/org/openapitools/model/User.java
src/main/java/org/openapitools/api/impl/PetApiServiceImpl.java
src/main/java/org/openapitools/api/impl/StoreApiServiceImpl.java
src/main/java/org/openapitools/api/impl/UserApiServiceImpl.java
src/main/webapp/WEB-INF/jboss-web.xml
src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.2.1-SNAPSHOT
24 changes: 24 additions & 0 deletions samples/server/petstore/jaxrs-resteasy/java8/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# JAX-RS/RESTEasy server with OpenAPI

## Overview
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using an
[OpenAPI-Spec](https://openapis.org), you can easily generate a server stub.

This is an example of building a OpenAPI-enabled JAX-RS server.
This example uses the [JAX-RS](https://jax-rs-spec.java.net/) framework.
RESTEasy is used as JAX-RS implementation library and is defined as dependency.

To run the server, please execute the following:

```
mvn -Djetty.http.port=8080 package org.eclipse.jetty:jetty-maven-plugin:run
```

You can then view the OpenAPI v2 specification here:

```
http://localhost:8080/v2/swagger.json
```

Note that if you have configured the `host` to be something other than localhost, the calls through
swagger-ui will be directed to that host and not localhost!
36 changes: 36 additions & 0 deletions samples/server/petstore/jaxrs-resteasy/java8/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apply plugin: 'war'

project.version = "1.0.0"
project.group = "org.openapitools"

repositories {
maven { url "https://repo1.maven.org/maven2" }
}

dependencies {
providedCompile 'org.jboss.resteasy:resteasy-jaxrs:3.0.11.Final'
providedCompile 'org.jboss.resteasy:jaxrs-api:3.0.11.Final'
providedCompile 'org.jboss.resteasy:resteasy-validator-provider-11:3.0.11.Final'
providedCompile 'org.jboss.resteasy:resteasy-multipart-provider:3.0.11.Final'
providedCompile 'javax.annotation:javax.annotation-api:1.2'
providedCompile 'javax:javaee-api:7.0'
providedCompile 'org.jboss.spec.javax.servlet:jboss-servlet-api_3.0_spec:1.0.0.Final'
compile 'io.swagger:swagger-annotations:1.5.22'
compile 'org.jboss.resteasy:resteasy-jackson2-provider:3.0.11.Final'
providedCompile 'javax.validation:validation-api:1.1.0.Final'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.9.9'
compile 'joda-time:joda-time:2.7'
//TODO: swaggerFeature
compile 'io.swagger:swagger-jaxrs:1.5.12'

testCompile 'junit:junit:4.13',
'org.hamcrest:hamcrest-core:1.3'
}

sourceSets {
main {
java {
srcDir 'src/gen/java'
}
}
}
Loading

0 comments on commit 1d4a343

Please sign in to comment.