Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .github/workflows/samples-java-client-jdk17.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on:
- samples/client/others/java/restclient-useAbstractionForFiles/**
- samples/client/petstore/java/jersey3-oneOf/**
- samples/client/petstore/java/jersey3-jackson3/**
- samples/client/petstore/java/microprofile-oneof-sealed/**
pull_request:
paths:
- samples/client/petstore/java/resttemplate-jakarta/**
Expand All @@ -37,6 +38,7 @@ on:
- samples/client/others/java/restclient-useAbstractionForFiles/**
- samples/client/petstore/java/jersey3-oneOf/**
- samples/client/petstore/java/jersey3-jackson3/**
- samples/client/petstore/java/microprofile-oneof-sealed/**
jobs:
build:
name: Build Java Client JDK17
Expand Down Expand Up @@ -70,6 +72,7 @@ jobs:
- samples/client/others/java/restclient-useAbstractionForFiles
- samples/client/petstore/java/jersey3-oneOf
- samples/client/petstore/java/jersey3-jackson3
- samples/client/petstore/java/microprofile-oneof-sealed
Comment thread
Ignacio-Vidal marked this conversation as resolved.
steps:
- uses: actions/checkout@v7
- uses: actions/setup-java@v5
Expand Down Expand Up @@ -108,4 +111,6 @@ jobs:

- name: Build
working-directory: ${{ matrix.sample }}
# the microprofile library does not generate a Gradle build; skip samples without a wrapper
if: ${{ hashFiles(format('{0}/gradlew', matrix.sample)) != '' }}
run: /bin/sh gradlew build -x test --no-daemon
12 changes: 12 additions & 0 deletions bin/configs/java-microprofile-oneof-sealed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
generatorName: java
outputDir: samples/client/petstore/java/microprofile-oneof-sealed
library: microprofile
inputSpec: modules/openapi-generator/src/test/resources/3_0/java/oneof_interface_petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/Java
additionalProperties:
serializationLibrary: jackson
artifactId: microprofile-oneof-sealed
useOneOfInterfaces: "true"
useSealedOneOfInterfaces: "true"
microprofileRestClientVersion: "3.0"
hideGenerationTimestamp: true
2 changes: 1 addition & 1 deletion docs/generators/java-microprofile.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useRuntimeException|Use RuntimeException instead of Exception. Only jersey2, jersey3, okhttp-gson, vertx, microprofile support this option.| |false|
|useRxJava2|Whether to use the RxJava2 adapter with the retrofit2 library. IMPORTANT: This option has been deprecated.| |false|
|useRxJava3|Whether to use the RxJava3 adapter with the retrofit2 library. IMPORTANT: This option has been deprecated.| |false|
|useSealedOneOfInterfaces|Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient and RestClient.| |false|
|useSealedOneOfInterfaces|Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient, RestClient and Microprofile (with Jackson).| |false|
|useSingleRequestParameter|Setting this property to "true" will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter. ONLY native, jersey2, jersey3, okhttp-gson, microprofile, Spring RestClient, Spring WebClient support this option. Setting this property to "static" does the same as "true", but also makes the generated arguments class static with single parameter instantiation.| |false|
|useSpringBoot4|Generate code and provide dependencies for use with Spring Boot 4.x.| |false|
|useUnaryInterceptor|If true it will generate ResponseInterceptors using a UnaryOperator. This can be usefull for manipulating the request before it gets passed, for example doing your own decryption| |false|
Expand Down
2 changes: 1 addition & 1 deletion docs/generators/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useRuntimeException|Use RuntimeException instead of Exception. Only jersey2, jersey3, okhttp-gson, vertx, microprofile support this option.| |false|
|useRxJava2|Whether to use the RxJava2 adapter with the retrofit2 library. IMPORTANT: This option has been deprecated.| |false|
|useRxJava3|Whether to use the RxJava3 adapter with the retrofit2 library. IMPORTANT: This option has been deprecated.| |false|
|useSealedOneOfInterfaces|Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient and RestClient.| |false|
|useSealedOneOfInterfaces|Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient, RestClient and Microprofile (with Jackson).| |false|
|useSingleRequestParameter|Setting this property to "true" will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter. ONLY native, jersey2, jersey3, okhttp-gson, microprofile, Spring RestClient, Spring WebClient support this option. Setting this property to "static" does the same as "true", but also makes the generated arguments class static with single parameter instantiation.| |false|
|useSpringBoot4|Generate code and provide dependencies for use with Spring Boot 4.x.| |false|
|useUnaryInterceptor|If true it will generate ResponseInterceptors using a UnaryOperator. This can be usefull for manipulating the request before it gets passed, for example doing your own decryption| |false|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public JavaClientCodegen() {
cliOptions.add(CliOption.newBoolean(FAIL_ON_UNKNOWN_PROPERTIES, "Fail Jackson de-serialization on unknown properties", this.failOnUnknownProperties));
cliOptions.add(CliOption.newBoolean(USE_JACKSON_3, "Use Jackson 3 instead of Jackson 2. Supported for 'native', 'apache-httpclient', and 'jersey3' libraries (requires Java 17+) and for Spring 'resttemplate', 'webclient', and 'restclient' libraries (require useSpringBoot4=true).", this.useJackson3));
cliOptions.add(CliOption.newBoolean(SUPPORT_VERTX_FUTURE, "Also generate api methods that return a vertx Future instead of taking a callback. Only `vertx` supports this option. Requires vertx 4 or greater.", this.supportVertxFuture));
cliOptions.add(CliOption.newBoolean(USE_SEALED_ONE_OF_INTERFACES, "Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient and RestClient.", this.useSealedOneOfInterfaces));
cliOptions.add(CliOption.newBoolean(USE_SEALED_ONE_OF_INTERFACES, "Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient, RestClient and Microprofile (with Jackson).", this.useSealedOneOfInterfaces));
cliOptions.add(CliOption.newBoolean(USE_UNARY_INTERCEPTOR, "If true it will generate ResponseInterceptors using a UnaryOperator. This can be usefull for manipulating the request before it gets passed, for example doing your own decryption", this.useUnaryInterceptor));
cliOptions.add(CliOption.newBoolean(USE_JSPECIFY, "Use Jspecify for null checks. Only supported for " + JSPECIFY_SUPPORTED_LIBRARIES, useJspecify));
cliOptions.add(CliOption.newBoolean(USE_DEDUCTION_FOR_ONE_OF_INTERFACES, USE_DEDUCTION_FOR_ONE_OF_INTERFACES_DESC, useDeductionForOneOfInterfaces));
Expand Down Expand Up @@ -442,6 +442,10 @@ public void processOpts() {
writePropertyBack(JAVA_17, true);
}

if (libMicroprofile && useSealedOneOfInterfaces) {
writePropertyBack(JAVA_17, true);
}

if (!useRxJava && !useRxJava2 && !useRxJava3) {
additionalProperties.put(DO_NOT_USE_RX, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{{#vendorExtensions.x-class-extra-annotation}}
{{{.}}}
{{/vendorExtensions.x-class-extra-annotation}}
public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#vendorExtensions.x-implements}}{{#-first}} implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#vendorExtensions.x-implements}}{{#-first}} implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {{>permits}}{
{{#vars}}{{#isEnum}}{{^isContainer}}
{{>enumClass}}{{/isContainer}}{{#isContainer}}{{#mostInnerItems}}
{{>enumClass}}{{/mostInnerItems}}{{/isContainer}}{{/isEnum}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
</repository>
</repositories>
<properties>
<java.version>11</java.version>
<java.version>{{#java17}}17{{/java17}}{{^java17}}11{{/java17}}</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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4219,6 +4219,33 @@ public void oneOfInterfaceMicroprofileJackson() {
assertFileNotContains(model.resolve("CatRequest.java"), "public final class");
}

@Test
public void sealedOneOfInterfaceMicroprofileJackson() {
final Path output = newTempFolder();
final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName(JAVA_GENERATOR)
.setLibrary(MICROPROFILE)
.setAdditionalProperties(Map.of(
USE_ONE_OF_INTERFACES, "true",
USE_SEALED_ONE_OF_INTERFACES, "true",
CodegenConstants.SERIALIZATION_LIBRARY, SERIALIZATION_LIBRARY_JACKSON,
JavaClientCodegen.MICROPROFILE_REST_CLIENT_VERSION, "3.0"
))
.setInputSpec("src/test/resources/3_0/java/oneof_interface_petstore.yaml")
.setOutputDir(output.toString().replace("\\", "/"));

new DefaultGenerator().opts(configurator.toClientOptInput()).generate();

final Path model = output.resolve("src/main/java/org/openapitools/client/model");
assertFileContains(model.resolve("PetRequest.java"), "public sealed interface PetRequest permits CatRequest, DogRequest {");
assertFileContains(model.resolve("CatRequest.java"), "public final class CatRequest");
assertFileContains(model.resolve("CatRequest.java"), "implements PetRequest");
assertFileContains(model.resolve("DogRequest.java"), "public final class DogRequest");
// sealed requires Java 17 in the generated pom
assertFileContains(output.resolve("pom.xml"), "<java.version>17</java.version>");
assertFileNotContains(output.resolve("pom.xml"), "<java.version>11</java.version>");
}

@DataProvider(name = "sealedInterfaceScenarios")
public static Object[][] sealedInterfaceScenarios() {
return new Object[][]{
Expand Down
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
README.md
docs/CatRequest.md
docs/DefaultApi.md
docs/DogRequest.md
docs/PetBase.md
docs/PetRequest.md
docs/PetType.md
pom.xml
src/main/java/org/openapitools/client/RFC3339DateFormat.java
src/main/java/org/openapitools/client/RFC3339InstantDeserializer.java
src/main/java/org/openapitools/client/RFC3339JavaTimeModule.java
src/main/java/org/openapitools/client/api/ApiException.java
src/main/java/org/openapitools/client/api/ApiExceptionMapper.java
src/main/java/org/openapitools/client/api/DefaultApi.java
src/main/java/org/openapitools/client/model/CatRequest.java
src/main/java/org/openapitools/client/model/DogRequest.java
src/main/java/org/openapitools/client/model/PetBase.java
src/main/java/org/openapitools/client/model/PetRequest.java
src/main/java/org/openapitools/client/model/PetType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.24.0-SNAPSHOT
10 changes: 10 additions & 0 deletions samples/client/petstore/java/microprofile-oneof-sealed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# oneOf interface petstore - MicroProfile Rest Client & MicroProfile Server

A minimal, self-consistent oneOf-interface spec for the Java (microprofile) client generator. The oneOf container and the shared base both declare the discriminator property so the interface getter resolves to the enum type. Children inherit the base via allOf and only implement the generated interface.


## Overview
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
[MicroProfile Rest Client](https://github.com/eclipse/microprofile-rest-client) is a type-safe way of calling
REST services. The generated client contains an interface which acts as the client, you can inject it into dependent classes.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


# CatRequest


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**petType** | **PetType** | | |
|**name** | **String** | | |
|**indoor** | **Boolean** | | |


## Implemented Interfaces

* PetRequest


Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# DefaultApi

All URIs are relative to *http://localhost*

| Method | HTTP request | Description |
|------------- | ------------- | -------------|
| [**createPet**](DefaultApi.md#createPet) | **POST** /pets | |



## createPet

> PetRequest createPet(petRequest)



### Example

```java
// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.DefaultApi;

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

DefaultApi apiInstance = new DefaultApi(defaultClient);
Comment thread
Ignacio-Vidal marked this conversation as resolved.
PetRequest petRequest = new PetRequest(); // PetRequest |
try {
PetRequest result = apiInstance.createPet(petRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling DefaultApi#createPet");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
```

### Parameters


| Name | Type | Description | Notes |
|------------- | ------------- | ------------- | -------------|
| **petRequest** | [**PetRequest**](PetRequest.md)| | |

### Return type

[**PetRequest**](PetRequest.md)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: application/json
- **Accept**: application/json


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | created | - |

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


# DogRequest


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**petType** | **PetType** | | |
|**name** | **String** | | |
|**trained** | **Boolean** | | |


## Implemented Interfaces

* PetRequest


Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


# PetBase


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**petType** | **PetType** | | |
|**name** | **String** | | |



Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


# Interface PetRequest

## Implementing Classes

* CatRequest
* DogRequest


Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


# PetType

## Enum


* `CAT` (value: `"CAT"`)

* `DOG` (value: `"DOG"`)



Loading
Loading