forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Java][Spring] Implement JsonNullable in openapiNullable correctly - f…
…ixes OpenAPITools#14765 JsonNullable was implemented incorrectly, checking for nullable property instead of required property as originally defined by OpenAPI Spec
- Loading branch information
Showing
20 changed files
with
2,275 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
generatorName: spring | ||
library: spring-boot | ||
outputDir: samples/server/petstore/spring-openapi-nullable-required | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-nullable-required.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
artifactId: spring-boot-nullable-set | ||
interfaceOnly: "true" | ||
singleContentTypes: "true" | ||
hideGenerationTimestamp: "true" | ||
openapiNullable: "true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
modules/openapi-generator/src/main/resources/JavaSpring/nullableDataType.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{{#openApiNullable}}{{#isNullable}}JsonNullable<{{{datatypeWithEnum}}}>{{/isNullable}}{{^isNullable}}{{{datatypeWithEnum}}}{{/isNullable}}{{/openApiNullable}}{{^openApiNullable}}{{{datatypeWithEnum}}}{{/openApiNullable}} | ||
{{#openApiNullable}}{{^required}}JsonNullable<{{{datatypeWithEnum}}}>{{/required}}{{#required}}{{{datatypeWithEnum}}}{{/required}}{{/openApiNullable}}{{^openApiNullable}}{{{datatypeWithEnum}}}{{/openApiNullable}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
samples/server/petstore/spring-openapi-nullable-required/.openapi-generator-ignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
12 changes: 12 additions & 0 deletions
12
samples/server/petstore/spring-openapi-nullable-required/.openapi-generator/FILES
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
README.md | ||
pom.xml | ||
src/main/java/org/openapitools/api/ApiUtil.java | ||
src/main/java/org/openapitools/api/PetApi.java | ||
src/main/java/org/openapitools/api/StoreApi.java | ||
src/main/java/org/openapitools/api/UserApi.java | ||
src/main/java/org/openapitools/model/Category.java | ||
src/main/java/org/openapitools/model/ModelApiResponse.java | ||
src/main/java/org/openapitools/model/Order.java | ||
src/main/java/org/openapitools/model/Pet.java | ||
src/main/java/org/openapitools/model/Tag.java | ||
src/main/java/org/openapitools/model/User.java |
1 change: 1 addition & 0 deletions
1
samples/server/petstore/spring-openapi-nullable-required/.openapi-generator/VERSION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
6.5.0-SNAPSHOT |
27 changes: 27 additions & 0 deletions
27
samples/server/petstore/spring-openapi-nullable-required/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
# OpenAPI generated API stub | ||
|
||
Spring Framework stub | ||
|
||
|
||
## Overview | ||
This code was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. | ||
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate an API stub. | ||
This is an example of building API stub interfaces in Java using the Spring framework. | ||
|
||
The stubs generated can be used in your existing Spring-MVC or Spring-Boot application to create controller endpoints | ||
by adding ```@Controller``` classes that implement the interface. Eg: | ||
```java | ||
@Controller | ||
public class PetController implements PetApi { | ||
// implement all PetApi methods | ||
} | ||
``` | ||
|
||
You can also use the interface to create [Spring-Cloud Feign clients](http://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-feign-inheritance).Eg: | ||
```java | ||
@FeignClient(name="pet", url="http://petstore.swagger.io/v2") | ||
public interface PetClient extends PetApi { | ||
|
||
} | ||
``` |
74 changes: 74 additions & 0 deletions
74
samples/server/petstore/spring-openapi-nullable-required/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.openapitools</groupId> | ||
<artifactId>spring-boot-nullable-set</artifactId> | ||
<packaging>jar</packaging> | ||
<name>spring-boot-nullable-set</name> | ||
<version>1.0.0</version> | ||
<properties> | ||
<java.version>1.8</java.version> | ||
<maven.compiler.source>${java.version}</maven.compiler.source> | ||
<maven.compiler.target>${java.version}</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<springdoc.version>1.6.14</springdoc.version> | ||
<swagger-ui.version>4.15.5</swagger-ui.version> | ||
</properties> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.7.6</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<build> | ||
<sourceDirectory>src/main/java</sourceDirectory> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.data</groupId> | ||
<artifactId>spring-data-commons</artifactId> | ||
</dependency> | ||
<!--SpringDoc dependencies --> | ||
<dependency> | ||
<groupId>org.springdoc</groupId> | ||
<artifactId>springdoc-openapi-ui</artifactId> | ||
<version>${springdoc.version}</version> | ||
</dependency> | ||
<!-- @Nullable annotation --> | ||
<dependency> | ||
<groupId>com.google.code.findbugs</groupId> | ||
<artifactId>jsr305</artifactId> | ||
<version>3.0.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.dataformat</groupId> | ||
<artifactId>jackson-dataformat-yaml</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-jsr310</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openapitools</groupId> | ||
<artifactId>jackson-databind-nullable</artifactId> | ||
<version>0.2.2</version> | ||
</dependency> | ||
<!-- Bean Validation API support --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-validation</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
19 changes: 19 additions & 0 deletions
19
...petstore/spring-openapi-nullable-required/src/main/java/org/openapitools/api/ApiUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.openapitools.api; | ||
|
||
import org.springframework.web.context.request.NativeWebRequest; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
public class ApiUtil { | ||
public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { | ||
try { | ||
HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); | ||
res.setCharacterEncoding("UTF-8"); | ||
res.addHeader("Content-Type", contentType); | ||
res.getWriter().print(example); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.