-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Add samples for when using the useSealed setting for Spring #21515
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
Merged
wing328
merged 4 commits into
OpenAPITools:master
from
Mattias-Sehlstedt:spring-sealed-samples
Jul 8, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
839c00b
Add samples for when using the useSealed setting for Spring
Mattias-Sehlstedt 2b4be7b
Add the new sample generation to the workflow
Mattias-Sehlstedt 1890e4a
Merge branch 'OpenAPITools:master' into spring-sealed-samples
Mattias-Sehlstedt eab7ff5
Merge branch 'OpenAPITools:master' into spring-sealed-samples
Mattias-Sehlstedt 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 hidden or 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 hidden or 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,13 @@ | ||
| generatorName: spring | ||
| outputDir: samples/openapi3/server/petstore/spring-boot-oneof-sealed | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/oneof_polymorphism_and_inheritance.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
| additionalProperties: | ||
| groupId: org.openapitools.openapi3 | ||
| documentationProvider: springdoc | ||
| artifactId: springboot-oneof-sealed | ||
| snapshotVersion: "true" | ||
| hideGenerationTimestamp: "true" | ||
| generateBuilders: true | ||
| useOneOfInterfaces: true | ||
| useSealed: true | ||
2 changes: 1 addition & 1 deletion
2
modules/openapi-generator/src/main/resources/JavaSpring/permits.mustache
This file contains hidden or 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 @@ | ||
| {{#useSealed}}{{#permits}}{{#-first}}permits {{/-first}}{{{.}}}{{^-last}}, {{/-last}}{{/permits}} {{/useSealed}} | ||
| {{#useSealed}}{{#permits}}{{#-first}}permits {{/-first}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}} {{/-last}}{{/permits}}{{/useSealed}} |
This file contains hidden or 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/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator-ignore
This file contains hidden or 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 |
31 changes: 31 additions & 0 deletions
31
samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator/FILES
This file contains hidden or 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,31 @@ | ||
| README.md | ||
| pom.xml | ||
| src/main/java/org/openapitools/OpenApiGeneratorApplication.java | ||
| src/main/java/org/openapitools/RFC3339DateFormat.java | ||
| src/main/java/org/openapitools/api/ApiUtil.java | ||
| src/main/java/org/openapitools/api/BarApi.java | ||
| src/main/java/org/openapitools/api/FooApi.java | ||
| src/main/java/org/openapitools/configuration/EnumConverterConfiguration.java | ||
| src/main/java/org/openapitools/configuration/HomeController.java | ||
| src/main/java/org/openapitools/configuration/SpringDocConfiguration.java | ||
| src/main/java/org/openapitools/model/Addressable.java | ||
| src/main/java/org/openapitools/model/Apple.java | ||
| src/main/java/org/openapitools/model/Banana.java | ||
| src/main/java/org/openapitools/model/Bar.java | ||
| src/main/java/org/openapitools/model/BarCreate.java | ||
| src/main/java/org/openapitools/model/BarRef.java | ||
| src/main/java/org/openapitools/model/BarRefOrValue.java | ||
| src/main/java/org/openapitools/model/Entity.java | ||
| src/main/java/org/openapitools/model/EntityRef.java | ||
| src/main/java/org/openapitools/model/Extensible.java | ||
| src/main/java/org/openapitools/model/Foo.java | ||
| src/main/java/org/openapitools/model/FooRef.java | ||
| src/main/java/org/openapitools/model/FooRefOrValue.java | ||
| src/main/java/org/openapitools/model/Fruit.java | ||
| src/main/java/org/openapitools/model/FruitType.java | ||
| src/main/java/org/openapitools/model/Pasta.java | ||
| src/main/java/org/openapitools/model/Pizza.java | ||
| src/main/java/org/openapitools/model/PizzaSpeziale.java | ||
| src/main/resources/application.properties | ||
| src/main/resources/openapi.yaml | ||
| src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java |
1 change: 1 addition & 0 deletions
1
samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator/VERSION
This file contains hidden or 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 @@ | ||
| 7.15.0-SNAPSHOT |
21 changes: 21 additions & 0 deletions
21
samples/openapi3/server/petstore/spring-boot-oneof-sealed/README.md
This file contains hidden or 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,21 @@ | ||
| # OpenAPI generated server | ||
|
|
||
| Spring Boot Server | ||
|
|
||
| ## Overview | ||
| This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. | ||
| By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub. | ||
| This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework. | ||
|
|
||
|
|
||
| The underlying library integrating OpenAPI to Spring Boot is [springdoc](https://springdoc.org). | ||
| Springdoc will generate an OpenAPI v3 specification based on the generated Controller and Model classes. | ||
| The specification is available to download using the following url: | ||
| http://localhost:8080/v3/api-docs/ | ||
|
|
||
| Start your server as a simple java application | ||
|
|
||
| You can view the api documentation in swagger-ui by pointing to | ||
| http://localhost:8080/swagger-ui.html | ||
|
|
||
| Change default port value in application.properties |
82 changes: 82 additions & 0 deletions
82
samples/openapi3/server/petstore/spring-boot-oneof-sealed/pom.xml
This file contains hidden or 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,82 @@ | ||
| <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.openapi3</groupId> | ||
| <artifactId>springboot-oneof-sealed</artifactId> | ||
| <packaging>jar</packaging> | ||
| <name>springboot-oneof-sealed</name> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
| <properties> | ||
| <java.version>17</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>5.3.1</swagger-ui.version> | ||
| </properties> | ||
| <parent> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-parent</artifactId> | ||
| <version>2.7.15</version> | ||
| <relativePath/> <!-- lookup parent from repository --> | ||
| </parent> | ||
| <build> | ||
| <sourceDirectory>src/main/java</sourceDirectory> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| <configuration> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </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.6</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> |
30 changes: 30 additions & 0 deletions
30
.../spring-boot-oneof-sealed/src/main/java/org/openapitools/OpenApiGeneratorApplication.java
This file contains hidden or 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,30 @@ | ||
| package org.openapitools; | ||
|
|
||
| import com.fasterxml.jackson.databind.Module; | ||
| import org.openapitools.jackson.nullable.JsonNullableModule; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.ComponentScan; | ||
| import org.springframework.context.annotation.FilterType; | ||
| import org.springframework.context.annotation.FullyQualifiedAnnotationBeanNameGenerator; | ||
|
|
||
| @SpringBootApplication( | ||
| nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class | ||
| ) | ||
| @ComponentScan( | ||
| basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"}, | ||
| nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class | ||
| ) | ||
| public class OpenApiGeneratorApplication { | ||
|
|
||
| public static void main(String[] args) { | ||
| SpringApplication.run(OpenApiGeneratorApplication.class, args); | ||
| } | ||
|
|
||
| @Bean(name = "org.openapitools.OpenApiGeneratorApplication.jsonNullableModule") | ||
| public Module jsonNullableModule() { | ||
| return new JsonNullableModule(); | ||
| } | ||
|
|
||
| } |
38 changes: 38 additions & 0 deletions
38
...r/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/RFC3339DateFormat.java
This file contains hidden or 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,38 @@ | ||
| package org.openapitools; | ||
|
|
||
| import com.fasterxml.jackson.databind.util.StdDateFormat; | ||
|
|
||
| import java.text.DateFormat; | ||
| import java.text.FieldPosition; | ||
| import java.text.ParsePosition; | ||
| import java.util.Date; | ||
| import java.util.GregorianCalendar; | ||
| import java.util.TimeZone; | ||
|
|
||
| public class RFC3339DateFormat extends DateFormat { | ||
| private static final long serialVersionUID = 1L; | ||
| private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC"); | ||
|
|
||
| private final StdDateFormat fmt = new StdDateFormat() | ||
| .withTimeZone(TIMEZONE_Z) | ||
| .withColonInTimeZone(true); | ||
|
|
||
| public RFC3339DateFormat() { | ||
| this.calendar = new GregorianCalendar(); | ||
| } | ||
|
|
||
| @Override | ||
| public Date parse(String source, ParsePosition pos) { | ||
| return fmt.parse(source, pos); | ||
| } | ||
|
|
||
| @Override | ||
| public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { | ||
| return fmt.format(date, toAppendTo, fieldPosition); | ||
| } | ||
|
|
||
| @Override | ||
| public Object clone() { | ||
| return this; | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
.../server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/ApiUtil.java
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.