Skip to content

Commit

Permalink
[Java][jersey2] fix cast error for default value in DateTimeOffset ob…
Browse files Browse the repository at this point in the history
…ject (#6547)

* fix cast error for datetimeoff in java

* add back files

* fix datetime initialize

* comment out ensure uptodate
  • Loading branch information
wing328 authored Jun 5, 2020
1 parent 8da06b0 commit 734d6d9
Show file tree
Hide file tree
Showing 121 changed files with 19,553 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/utils/ensure-up-to-date
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ declare -a samples=(
"${root}/bin/python-server-all.sh"
"${root}/bin/openapi3/python-petstore.sh"
"${root}/bin/openapi3/python-experimental-petstore.sh"
"${root}/bin/openapi3/java-petstore-jersey2-java8.sh"
#"${root}/bin/openapi3/java-petstore-jersey2-java8.sh"
"${root}/bin/php-petstore.sh"
"${root}/bin/php-silex-petstore-server.sh"
"${root}/bin/php-symfony-petstore.sh"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.openapitools.codegen.languages;

import com.google.common.base.Strings;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
Expand All @@ -42,7 +41,6 @@
import java.util.*;
import java.util.regex.Pattern;

import static org.openapitools.codegen.utils.OnceLogger.once;
import static org.openapitools.codegen.utils.StringUtils.*;

public abstract class AbstractJavaCodegen extends DefaultCodegen implements CodegenConfig {
Expand Down Expand Up @@ -863,9 +861,12 @@ public String toDefaultValue(Schema schema) {
Date date = (Date) schema.getDefault();
LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
return String.format(Locale.ROOT, localDate.toString(), "");
} else if (schema.getDefault() instanceof java.time.OffsetDateTime) {
return "OffsetDateTime.parse(\"" + String.format(Locale.ROOT, ((java.time.OffsetDateTime) schema.getDefault()).atZoneSameInstant(ZoneId.systemDefault()).toString(), "") + "\", java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME.withZone(java.time.ZoneId.systemDefault()))";
} else {
_default = (String) schema.getDefault();
}

if (schema.getEnum() == null) {
return "\"" + escapeText(_default) + "\"";
} else {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@
<module>samples/client/petstore/java/feign10x</module>
<module>samples/client/petstore/java/jersey1</module>
<module>samples/client/petstore/java/jersey2-java8</module>
<!--<module>samples/openapi3/client/petstore/java/jersey2-java8</module>-->
<module>samples/openapi3/client/petstore/java/jersey2-java8</module>
<module>samples/client/petstore/java/okhttp-gson</module>
<module>samples/client/petstore/java/retrofit2</module>
<module>samples/client/petstore/java/retrofit2rx</module>
Expand Down
21 changes: 21 additions & 0 deletions samples/openapi3/client/petstore/java/jersey2-java8/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# exclude jar for gradle wrapper
!gradle/wrapper/*.jar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# build files
**/target
target
.gradle
build
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
22 changes: 22 additions & 0 deletions samples/openapi3/client/petstore/java/jersey2-java8/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Generated by OpenAPI Generator: https://openapi-generator.tech
#
# Ref: https://docs.travis-ci.com/user/languages/java/
#
language: java
jdk:
- openjdk12
- openjdk11
- openjdk10
- openjdk9
- openjdk8
before_install:
# ensure gradlew has proper permission
- chmod a+x ./gradlew
script:
# test using maven
#- mvn test
# test using gradle
- gradle test
# test using sbt
# - sbt test
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Class | Method | HTTP request | Description
*FakeApi* | [**fakeOuterCompositeSerialize**](docs/FakeApi.md#fakeOuterCompositeSerialize) | **POST** /fake/outer/composite |
*FakeApi* | [**fakeOuterNumberSerialize**](docs/FakeApi.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number |
*FakeApi* | [**fakeOuterStringSerialize**](docs/FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string |
*FakeApi* | [**getArrayOfEnums**](docs/FakeApi.md#getArrayOfEnums) | **GET** /fake/array-of-enums | Array of Enums
*FakeApi* | [**testBodyWithFileSchema**](docs/FakeApi.md#testBodyWithFileSchema) | **PUT** /fake/body-with-file-schema |
*FakeApi* | [**testBodyWithQueryParams**](docs/FakeApi.md#testBodyWithQueryParams) | **PUT** /fake/body-with-query-params |
*FakeApi* | [**testClientModel**](docs/FakeApi.md#testClientModel) | **PATCH** /fake | To test \&quot;client\&quot; model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,9 @@ paths:
format: date
type: string
dateTime:
default: 2010-02-01T10:20:10.11111+01:00
description: None
example: 2020-02-02T20:20:20.22222Z
format: date-time
type: string
password:
Expand Down Expand Up @@ -1234,6 +1236,20 @@ paths:
tags:
- fake
x-accepts: application/json
/fake/array-of-enums:
get:
operationId: getArrayOfEnums
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/ArrayOfEnums'
description: Got named array of enums
summary: Array of Enums
tags:
- fake
x-accepts: application/json
components:
requestBodies:
UserArray:
Expand Down Expand Up @@ -1309,7 +1325,7 @@ components:
petId: 6
quantity: 1
id: 0
shipDate: 2000-01-23T04:56:07.000+00:00
shipDate: 2020-02-02T20:20:20.000222Z
complete: false
status: placed
properties:
Expand All @@ -1323,6 +1339,7 @@ components:
format: int32
type: integer
shipDate:
example: 2020-02-02T20:20:20.000222Z
format: date-time
type: string
status:
Expand Down Expand Up @@ -1602,9 +1619,11 @@ components:
format: binary
type: string
date:
example: 2020-02-02
format: date
type: string
dateTime:
example: 2007-12-03T10:15:30+01:00
format: date-time
type: string
uuid:
Expand Down Expand Up @@ -2214,6 +2233,15 @@ components:
allOf:
- $ref: '#/components/schemas/ParentPet'
- $ref: '#/components/schemas/ChildCat_allOf'
ArrayOfEnums:
items:
$ref: '#/components/schemas/OuterEnum'
type: array
DateTimeTest:
default: 2010-01-01T10:10:10.000111+01:00
example: 2010-01-01T10:10:10.000111+01:00
format: date-time
type: string
inline_response_default:
example:
string:
Expand Down Expand Up @@ -2314,7 +2342,9 @@ components:
format: date
type: string
dateTime:
default: 2010-02-01T10:20:10.11111+01:00
description: None
example: 2020-02-02T20:20:20.22222Z
format: date-time
type: string
password:
Expand Down
125 changes: 125 additions & 0 deletions samples/openapi3/client/petstore/java/jersey2-java8/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
apply plugin: 'idea'
apply plugin: 'eclipse'

group = 'org.openapitools'
version = '1.0.0'

buildscript {
repositories {
maven { url "https://repo1.maven.org/maven2" }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.+'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}

repositories {
jcenter()
}


if(hasProperty('target') && target == 'android') {

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

// Rename the aar correctly
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}

dependencies {
provided 'javax.annotation:jsr250-api:1.0'
}
}

afterEvaluate {
android.libraryVariants.all { variant ->
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
task.description = "Create jar artifact for ${variant.name}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
artifacts.add('archives', task);
}
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}

artifacts {
archives sourcesJar
}

} else {

apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

install {
repositories.mavenInstaller {
pom.artifactId = 'petstore-openapi3-jersey2-java8'
}
}

task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}

ext {
swagger_annotations_version = "1.5.22"
jackson_version = "2.10.3"
jackson_databind_version = "2.10.4"
jackson_databind_nullable_version = "0.2.1"
jersey_version = "2.27"
junit_version = "4.13"
scribejava_apis_version = "6.9.0"
tomitribe_http_signatures_version = "1.3"
}

dependencies {
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
compile "com.google.code.findbugs:jsr305:3.0.2"
compile "org.glassfish.jersey.core:jersey-client:$jersey_version"
compile "org.glassfish.jersey.media:jersey-media-multipart:$jersey_version"
compile "org.glassfish.jersey.media:jersey-media-json-jackson:$jersey_version"
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version"
compile "org.openapitools:jackson-databind-nullable:$jackson_databind_nullable_version"
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version"
compile "com.github.scribejava:scribejava-apis:$scribejava_apis_version"
compile "org.tomitribe:tomitribe-http-signatures:$tomitribe_http_signatures_version"
testCompile "junit:junit:$junit_version"
}

javadoc {
options.tags = [ "http.response.details:a:Http Response Details" ]
}
25 changes: 25 additions & 0 deletions samples/openapi3/client/petstore/java/jersey2-java8/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
lazy val root = (project in file(".")).
settings(
organization := "org.openapitools",
name := "petstore-openapi3-jersey2-java8",
version := "1.0.0",
scalaVersion := "2.11.4",
scalacOptions ++= Seq("-feature"),
javacOptions in compile ++= Seq("-Xlint:deprecation"),
publishArtifact in (Compile, packageDoc) := false,
resolvers += Resolver.mavenLocal,
libraryDependencies ++= Seq(
"io.swagger" % "swagger-annotations" % "1.5.22",
"org.glassfish.jersey.core" % "jersey-client" % "2.25.1",
"org.glassfish.jersey.media" % "jersey-media-multipart" % "2.25.1",
"org.glassfish.jersey.media" % "jersey-media-json-jackson" % "2.25.1",
"com.fasterxml.jackson.core" % "jackson-core" % "2.10.4" % "compile",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.10.4" % "compile",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.10.4" % "compile",
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % "2.9.10" % "compile",
"com.github.scribejava" % "scribejava-apis" % "6.9.0" % "compile",
"org.tomitribe" % "tomitribe-http-signatures" % "1.3" % "compile",
"junit" % "junit" % "4.13" % "test",
"com.novocode" % "junit-interface" % "0.10" % "test"
)
)
Loading

0 comments on commit 734d6d9

Please sign in to comment.