Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
aef3b64
fix(java): x-discriminator-value should not produce @JsonTypeName
Dec 13, 2023
4199d11
fix(java): Remove unused getDiscriminatorValue()
Dec 13, 2023
77a34df
build at Fednot
Dec 18, 2023
53832b0
build at Fednot
Dec 18, 2023
ad9959e
build at Fednot: skip sonar
Dec 19, 2023
eff380a
scm for release at fednot
Dec 19, 2023
b3ea3d8
Merge remote-tracking branch 'origin/master'
Jan 26, 2024
8fb89ae
Merge remote-tracking branch 'origin/master'
jpfinne Mar 12, 2024
5a29795
build fednot not 7.5.0-FEDNOT-SNAPSHOT
jpfinne Mar 12, 2024
8e83bee
build fednot not 7.5.0-FEDNOT-SNAPSHOT
jpfinne Mar 12, 2024
e91cde1
Merge remote-tracking branch 'origin/master'
jpfinne Mar 22, 2024
ca5b2e6
test all vars
jpfinne Mar 22, 2024
9263f4c
rollback custom pom.xml
jpfinne Mar 25, 2024
47c61f3
Merge remote-tracking branch 'origin/master'
jpfinne Apr 5, 2024
33a68b2
commit master
jpfinne Apr 26, 2024
15064a4
commit test
jpfinne Apr 26, 2024
5a82c52
Merge remote-tracking branch 'origin/master'
jpfinne May 4, 2024
135b972
Merge branch 'master' of https://github.com/jpfinne/openapi-generator
jpfinne Jun 7, 2024
1c8c322
Samples for deduction
jpfinne Mar 18, 2025
e7b3c16
add files for deduction
jpfinne Mar 18, 2025
df46ce5
small improvements
martin-mfg Mar 22, 2025
3119eca
Merge pull request #2 from martin-mfg/pr_20919_improvements
jpfinne Mar 23, 2025
66a6693
Merge changes from martin-mfg
jpfinne Mar 23, 2025
168d3d1
Merge branch 'master' of https://github.com/jpfinne/openapi-generator…
jpfinne Mar 23, 2025
7634e4c
Merge changes from martin-mfg
jpfinne Mar 23, 2025
58f2588
Merge changes from martin-mfg
jpfinne Mar 23, 2025
59b18e9
Merge remote-tracking branch 'origin/master'
jpfinne Apr 29, 2025
e2a998f
Merge remote-tracking branch 'origin/master'
jpfinne Jul 8, 2025
3557514
Merge branch 'master' into useDeductionForOneOfInterfaces
jpfinne Jul 8, 2025
a478971
Merge master
jpfinne Jul 8, 2025
0397cc2
regenerate doc
jpfinne Jul 8, 2025
21f1f1c
regenerate client
jpfinne Jul 8, 2025
a20aad5
regenerate client
jpfinne Jul 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/samples-spring-jdk17.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- samples/server/petstore/springboot-file-delegate-optional
- samples/server/petstore/springboot-petstore-with-api-response-examples
- samples/server/petstore/spring-boot-oneof-sealed
- samples/openapi3/server/petstore/spring-boot-oneof-interface
pull_request:
paths:
- samples/openapi3/client/petstore/spring-cloud-3-with-optional
Expand All @@ -21,6 +22,7 @@ on:
- samples/server/petstore/springboot-file-delegate-optional
- samples/server/petstore/springboot-petstore-with-api-response-examples
- samples/server/petstore/spring-boot-oneof-sealed
- samples/openapi3/server/petstore/spring-boot-oneof-interface
jobs:
build:
name: Build Java Spring (JDK17)
Expand All @@ -39,6 +41,7 @@ jobs:
- samples/server/petstore/springboot-file-delegate-optional
- samples/server/petstore/springboot-petstore-with-api-response-examples
- samples/server/petstore/spring-boot-oneof-sealed
- samples/openapi3/server/petstore/spring-boot-oneof-interface
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/samples-spring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
- samples/server/petstore/springboot-spring-provide-args
- samples/server/petstore/springboot-useoptional
- samples/server/petstore/springboot-virtualan
- samples/openapi3/server/petstore/spring-boot-oneof-interface
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand Down
12 changes: 12 additions & 0 deletions bin/configs/spring-boot-oneof-interface.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
generatorName: spring
outputDir: samples/openapi3/server/petstore/spring-boot-oneof-interface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wing328 any chance that this PR get merged?

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
snapshotVersion: "true"
hideGenerationTimestamp: "true"
useOneOfInterfaces: "true"
useDeductionForOneOfInterfaces: "true"
1 change: 1 addition & 0 deletions docs/generators/java-camel.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|title|server title name or client service name| |OpenAPI Spring|
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|
|useBeanValidation|Use BeanValidation API annotations| |true|
|useDeductionForOneOfInterfaces|whether to use deduction for generated oneOf interfaces| |false|
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
|useFeignClientContextId|Whether to generate Feign client with contextId parameter.| |true|
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|title|server title name or client service name| |OpenAPI Spring|
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|
|useBeanValidation|Use BeanValidation API annotations| |true|
|useDeductionForOneOfInterfaces|whether to use deduction for generated oneOf interfaces| |false|
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
|useFeignClientContextId|Whether to generate Feign client with contextId parameter.| |true|
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public class SpringCodegen extends AbstractJavaCodegen
public static final String USE_SEALED = "useSealed";
public static final String OPTIONAL_ACCEPT_NULLABLE = "optionalAcceptNullable";
public static final String USE_SPRING_BUILT_IN_VALIDATION = "useSpringBuiltInValidation";
public static final String USE_DEDUCTION_FOR_ONE_OF_INTERFACES = "useDeductionForOneOfInterfaces";

@Getter
public enum RequestMappingMode {
Expand Down Expand Up @@ -159,6 +160,8 @@ public enum RequestMappingMode {
protected boolean optionalAcceptNullable = true;
@Getter @Setter
protected boolean useSpringBuiltInValidation = false;
@Getter @Setter
protected boolean useDeductionForOneOfInterfaces = false;

public SpringCodegen() {
super();
Expand Down Expand Up @@ -276,6 +279,7 @@ public SpringCodegen() {
"Use `ofNullable` instead of just `of` to accept null values when using Optional.",
optionalAcceptNullable));

cliOptions.add(CliOption.newBoolean(USE_DEDUCTION_FOR_ONE_OF_INTERFACES, "whether to use deduction for generated oneOf interfaces", useDeductionForOneOfInterfaces));
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application.");
supportedLibraries.put(SPRING_CLOUD_LIBRARY,
"Spring-Cloud-Feign client with Spring-Boot auto-configured settings.");
Expand Down Expand Up @@ -446,6 +450,7 @@ public void processOpts() {
}
convertPropertyToBooleanAndWriteBack(OPTIONAL_ACCEPT_NULLABLE, this::setOptionalAcceptNullable);
convertPropertyToBooleanAndWriteBack(USE_SPRING_BUILT_IN_VALIDATION, this::setUseSpringBuiltInValidation);
convertPropertyToBooleanAndWriteBack(USE_DEDUCTION_FOR_ONE_OF_INTERFACES, this::setUseDeductionForOneOfInterfaces);

additionalProperties.put("springHttpStatus", new SpringHttpStatusLambda());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
{{#discriminator}}
{{>typeInfoAnnotation}}

{{/discriminator}}{{^discriminator}}{{#useDeductionForOneOfInterfaces}}
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
@JsonSubTypes({
{{#interfaceModels}}
@JsonSubTypes.Type(value = {{classname}}.class){{^-last}}, {{/-last}}
{{/interfaceModels}}
})
{{/useDeductionForOneOfInterfaces}}
{{/discriminator}}
{{>generatedAnnotation}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1702,10 +1702,13 @@ public void testOneOfAndAllOf() throws IOException {
generator.setGeneratorPropertyDefault(CodegenConstants.LEGACY_DISCRIMINATOR_BEHAVIOR, "false");

codegen.setUseOneOfInterfaces(true);
codegen.setUseDeductionForOneOfInterfaces(true);
codegen.setLegacyDiscriminatorBehavior(false);

generator.opts(input).generate();

// test deduction
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/model/Animal.java"), "@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)", "@JsonSubTypes.Type(value = Dog.class),", "@JsonSubTypes.Type(value = Cat.class)");
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/model/Foo.java"), "public class Foo extends Entity implements FooRefOrValue");
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/model/FooRef.java"), "public class FooRef extends EntityRef implements FooRefOrValue");
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/model/FooRefOrValue.java"), "public interface FooRefOrValue");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ components:
properties:
length:
type: integer
Animal:
oneOf:
- $ref: '#/components/schemas/Dog'
- $ref: '#/components/schemas/Cat'
Cat:
type: object
properties:
declawed:
type: boolean
Dog:
type: object
properties:
bark:
type: boolean

requestBodies:
Foo:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# openapi-java-client

OpenAPI Petstore
- API version: 1.0.0
- Generator version: 7.6.0-SNAPSHOT

This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.


*Automatically generated by the [OpenAPI Generator](https://openapi-generator.tech)*


## Requirements

Building the API client library requires:
1. Java 1.8+
2. Maven (3.8.3+)/Gradle (7.2+)

## Installation

To install the API client library to your local Maven repository, simply execute:

```shell
mvn clean install
```

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

```shell
mvn clean deploy
```

Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information.

### Maven users

Add this dependency to your project's POM:

```xml
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>openapi-java-client</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
```

### Gradle users

Add this dependency to your project's build file:

```groovy
repositories {
mavenCentral() // Needed if the 'openapi-java-client' jar has been published to maven central.
mavenLocal() // Needed if the 'openapi-java-client' jar has been published to the local maven repo.
}

dependencies {
implementation "org.openapitools:openapi-java-client:1.0.0"
}
```

### Others

At first generate the JAR by executing:

```shell
mvn clean package
```

Then manually install the following JARs:

* `target/openapi-java-client-1.0.0.jar`
* `target/lib/*.jar`

## Getting Started

Please follow the [installation](#installation) instruction and execute the following Java code:

```java

// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.auth.*;
import org.openapitools.client.models.*;
import org.openapitools.client.api.PetApi;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://petstore.swagger.io/v2");

// Configure OAuth2 access token for authorization: petstore_auth
OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth");
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");

PetApi apiInstance = new PetApi(defaultClient);
Pet pet = new Pet(); // Pet | Pet object that needs to be added to the store
try {
Pet result = apiInstance.addPet(pet);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#addPet");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}

```

## Documentation for API Endpoints

All URIs are relative to *http://petstore.swagger.io/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*PetApi* | [**addPet**](docs/PetApi.md#addPet) | **POST** /pet | Add a new pet to the store
*PetApi* | [**deletePet**](docs/PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet
*PetApi* | [**findPetsByStatus**](docs/PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status
*PetApi* | [**findPetsByTags**](docs/PetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags
*PetApi* | [**getPetById**](docs/PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID
*PetApi* | [**updatePet**](docs/PetApi.md#updatePet) | **PUT** /pet | Update an existing pet
*PetApi* | [**updatePetWithForm**](docs/PetApi.md#updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data
*PetApi* | [**uploadFile**](docs/PetApi.md#uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image
*StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
*StoreApi* | [**getInventory**](docs/StoreApi.md#getInventory) | **GET** /store/inventory | Returns pet inventories by status
*StoreApi* | [**getOrderById**](docs/StoreApi.md#getOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID
*StoreApi* | [**placeOrder**](docs/StoreApi.md#placeOrder) | **POST** /store/order | Place an order for a pet
*UserApi* | [**createUser**](docs/UserApi.md#createUser) | **POST** /user | Create user
*UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#createUsersWithArrayInput) | **POST** /user/createWithArray | Creates list of users with given input array
*UserApi* | [**createUsersWithListInput**](docs/UserApi.md#createUsersWithListInput) | **POST** /user/createWithList | Creates list of users with given input array
*UserApi* | [**deleteUser**](docs/UserApi.md#deleteUser) | **DELETE** /user/{username} | Delete user
*UserApi* | [**getUserByName**](docs/UserApi.md#getUserByName) | **GET** /user/{username} | Get user by user name
*UserApi* | [**loginUser**](docs/UserApi.md#loginUser) | **GET** /user/login | Logs user into the system
*UserApi* | [**logoutUser**](docs/UserApi.md#logoutUser) | **GET** /user/logout | Logs out current logged in user session
*UserApi* | [**updateUser**](docs/UserApi.md#updateUser) | **PUT** /user/{username} | Updated user


## Documentation for Models

- [Category](docs/Category.md)
- [ModelApiResponse](docs/ModelApiResponse.md)
- [Order](docs/Order.md)
- [Pet](docs/Pet.md)
- [Tag](docs/Tag.md)
- [User](docs/User.md)


<a id="documentation-for-authorization"></a>
## Documentation for Authorization


Authentication schemes defined for the API:
<a id="petstore_auth"></a>
### petstore_auth

- **Type**: OAuth
- **Flow**: implicit
- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog
- **Scopes**:
- write:pets: modify pets in your account
- read:pets: read your pets

<a id="api_key"></a>
### api_key

- **Type**: API key
- **API key parameter name**: api_key
- **Location**: HTTP header


## Recommendation

It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.

## Author



Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
Cargo.toml
README.md
docs/Addressable.md
docs/Animal.md
docs/Apple.md
docs/Banana.md
docs/Bar.md
docs/BarApi.md
docs/BarCreate.md
docs/BarRef.md
docs/BarRefOrValue.md
docs/Cat.md
docs/Dog.md
docs/Entity.md
docs/EntityRef.md
docs/Extensible.md
Expand All @@ -31,12 +34,15 @@ src/apis/mod.rs
src/apis/request.rs
src/lib.rs
src/models/addressable.rs
src/models/animal.rs
src/models/apple.rs
src/models/banana.rs
src/models/bar.rs
src/models/bar_create.rs
src/models/bar_ref.rs
src/models/bar_ref_or_value.rs
src/models/cat.rs
src/models/dog.rs
src/models/entity.rs
src/models/entity_ref.rs
src/models/extensible.rs
Expand Down
3 changes: 3 additions & 0 deletions samples/client/others/rust/hyper/oneOf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ Class | Method | HTTP request | Description
## Documentation For Models

- [Addressable](docs/Addressable.md)
- [Animal](docs/Animal.md)
- [Apple](docs/Apple.md)
- [Banana](docs/Banana.md)
- [Bar](docs/Bar.md)
- [BarCreate](docs/BarCreate.md)
- [BarRef](docs/BarRef.md)
- [BarRefOrValue](docs/BarRefOrValue.md)
- [Cat](docs/Cat.md)
- [Dog](docs/Dog.md)
- [Entity](docs/Entity.md)
- [EntityRef](docs/EntityRef.md)
- [Extensible](docs/Extensible.md)
Expand Down
12 changes: 12 additions & 0 deletions samples/client/others/rust/hyper/oneOf/docs/Animal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Animal

## Enum Variants

| Name | Description |
|---- | -----|
| Cat | |
| Dog | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Loading
Loading