-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Java] fix deserialization of readonly properties #11495
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,10 @@ | ||
generatorName: spring | ||
library: spring-boot | ||
outputDir: samples/server/petstore/spring-boot-nullable-set | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/spring/10167-nullable-set.yml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
artifactId: spring-boot-nullable-set | ||
interfaceOnly: "true" | ||
singleContentTypes: "true" | ||
hideGenerationTimestamp: "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
51 changes: 51 additions & 0 deletions
51
modules/openapi-generator/src/test/resources/3_0/spring/10167-nullable-set.yml
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,51 @@ | ||
openapi: 3.0.3 | ||
info: | ||
title: Api Documentation | ||
description: 'Demo Spring Mvc @DateTimeFormat across the different openapi parameter types' | ||
version: '1.0' | ||
paths: | ||
/nullable: | ||
post: | ||
description: nullable test | ||
operationId: nullableTest | ||
responses: | ||
204: | ||
description: processed | ||
405: | ||
description: Invalid input | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ObjectWithUniqueItems' | ||
|
||
components: | ||
schemas: | ||
ObjectWithUniqueItems: | ||
properties: | ||
nullSet: | ||
type: array | ||
uniqueItems: true | ||
items: | ||
type: string | ||
nullable: true | ||
notNullSet: | ||
type: array | ||
uniqueItems: true | ||
items: | ||
type: string | ||
nullList: | ||
type: array | ||
items: | ||
type: string | ||
nullable: true | ||
notNullList: | ||
type: array | ||
items: | ||
type: string | ||
notNullDateField: | ||
type: string | ||
format: date-time | ||
nullDateField: | ||
type: string | ||
format: date-time |
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-boot-nullable-set/.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 |
6 changes: 6 additions & 0 deletions
6
samples/server/petstore/spring-boot-nullable-set/.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,6 @@ | ||
.openapi-generator-ignore | ||
README.md | ||
pom.xml | ||
src/main/java/org/openapitools/api/ApiUtil.java | ||
src/main/java/org/openapitools/api/NullableApi.java | ||
src/main/java/org/openapitools/model/ObjectWithUniqueItems.java |
1 change: 1 addition & 0 deletions
1
samples/server/petstore/spring-boot-nullable-set/.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.0.0-SNAPSHOT |
27 changes: 27 additions & 0 deletions
27
samples/server/petstore/spring-boot-nullable-set/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 { | ||
|
||
} | ||
``` |
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,66 @@ | ||
<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</version> | ||
<properties> | ||
<java.version>1.8</java.version> | ||
<maven.compiler.source>${java.version}</maven.compiler.source> | ||
<maven.compiler.target>${java.version}</maven.compiler.target> | ||
<springdoc.version>1.6.4</springdoc.version> | ||
</properties> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.6.2</version> | ||
</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> | ||
</dependencies> | ||
</project> |
19 changes: 19 additions & 0 deletions
19
.../server/petstore/spring-boot-nullable-set/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); | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...ver/petstore/spring-boot-nullable-set/src/main/java/org/openapitools/api/NullableApi.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,68 @@ | ||
/** | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (6.0.0-SNAPSHOT). | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
package org.openapitools.api; | ||
|
||
import org.openapitools.model.ObjectWithUniqueItems; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.Parameters; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.context.request.NativeWebRequest; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.constraints.*; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import javax.annotation.Generated; | ||
|
||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") | ||
@Validated | ||
@Tag(name = "nullable", description = "the nullable API") | ||
public interface NullableApi { | ||
|
||
default Optional<NativeWebRequest> getRequest() { | ||
return Optional.empty(); | ||
} | ||
|
||
/** | ||
* POST /nullable | ||
* nullable test | ||
* | ||
* @param objectWithUniqueItems (optional) | ||
* @return processed (status code 204) | ||
* or Invalid input (status code 405) | ||
*/ | ||
@Operation( | ||
operationId = "nullableTest", | ||
responses = { | ||
@ApiResponse(responseCode = "204", description = "processed"), | ||
@ApiResponse(responseCode = "405", description = "Invalid input") | ||
} | ||
) | ||
@RequestMapping( | ||
method = RequestMethod.POST, | ||
value = "/nullable", | ||
consumes = "application/json" | ||
) | ||
default ResponseEntity<Void> nullableTest( | ||
@Parameter(name = "ObjectWithUniqueItems", description = "", schema = @Schema(description = "")) @Valid @RequestBody(required = false) ObjectWithUniqueItems objectWithUniqueItems | ||
) { | ||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI. Add the path to github workflow via 4c330f4