Skip to content
Open
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
3 changes: 3 additions & 0 deletions .github/workflows/samples-java-client-jdk11.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on:
- samples/client/others/java/jersey2-oneOf-duplicates/**
- samples/client/others/java/jersey2-oneOf-Mixed/**
- samples/client/others/java/native-oneOf-array/**
- samples/client/others/java/native-oneof-interface/**
- samples/client/others/java/okhttp-gson-streaming/**
- samples/client/others/java/resttemplate-list-schema-validation/**
- samples/client/petstore/java/okhttp-gson-3.1-duplicated-operationid/**
Expand All @@ -41,6 +42,7 @@ on:
- samples/client/others/java/jersey2-oneOf-duplicates/**
- samples/client/others/java/jersey2-oneOf-Mixed/**
- samples/client/others/java/native-oneOf-array/**
- samples/client/others/java/native-oneof-interface/**
- samples/client/others/java/okhttp-gson-streaming/**
- samples/client/others/java/resttemplate-list-schema-validation/**
- samples/client/petstore/java/okhttp-gson-3.1-duplicated-operationid/**
Expand Down Expand Up @@ -110,6 +112,7 @@ jobs:
- samples/client/others/java/jersey2-oneOf-duplicates/
- samples/client/others/java/jersey2-oneOf-Mixed/
- samples/client/others/java/native-oneOf-array/
- samples/client/others/java/native-oneof-interface/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: This matrix entry never exercises the sample's Gradle build because the workflow checks for ./gradlew at repository root. Gate the step with hashFiles(format('{0}/gradlew', matrix.sample)) instead.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At .github/workflows/samples-java-client-jdk11.yaml, line 115:

<comment>This matrix entry never exercises the sample's Gradle build because the workflow checks for `./gradlew` at repository root. Gate the step with `hashFiles(format('{0}/gradlew', matrix.sample))` instead.</comment>

<file context>
@@ -110,6 +112,7 @@ jobs:
           - samples/client/others/java/jersey2-oneOf-duplicates/
           - samples/client/others/java/jersey2-oneOf-Mixed/
           - samples/client/others/java/native-oneOf-array/
+          - samples/client/others/java/native-oneof-interface/
           - samples/client/others/java/resttemplate-list-schema-validation/
           - samples/client/petstore/java/okhttp-gson-3.1-duplicated-operationid/
</file context>

- samples/client/others/java/resttemplate-list-schema-validation/
- samples/client/petstore/java/okhttp-gson-3.1-duplicated-operationid/
- samples/client/others/java/okhttp-gson-streaming/
Expand Down
9 changes: 9 additions & 0 deletions bin/configs/java-native-oneof-interface.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
generatorName: java
outputDir: samples/client/others/java/native-oneof-interface
library: native
inputSpec: modules/openapi-generator/src/test/resources/3_0/java/native/oneof-interface-deduction.yaml
templateDir: modules/openapi-generator/src/main/resources/Java
additionalProperties:
hideGenerationTimestamp: "true"
useOneOfInterfaces: "true"
useDeductionForOneOfInterfaces: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ import org.hibernate.validator.constraints.*;

{{#models}}
{{#model}}
{{^vendorExtensions.x-is-one-of-interface}}
{{#oneOf}}
{{#-first}}
import {{jacksonPackage}}.core.type.TypeReference;
{{/-first}}
{{/oneOf}}
{{/vendorExtensions.x-is-one-of-interface}}

{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{#oneOf}}{{#-first}}{{>oneof_model}}{{/-first}}{{/oneOf}}{{^oneOf}}{{#anyOf}}{{#-first}}{{>anyof_model}}{{/-first}}{{/anyOf}}{{^anyOf}}{{>pojo}}{{/anyOf}}{{/oneOf}}{{/isEnum}}
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{#vendorExtensions.x-is-one-of-interface}}{{>oneof_interface}}{{/vendorExtensions.x-is-one-of-interface}}{{^vendorExtensions.x-is-one-of-interface}}{{#oneOf}}{{#-first}}{{>oneof_model}}{{/-first}}{{/oneOf}}{{^oneOf}}{{#anyOf}}{{#-first}}{{>anyof_model}}{{/-first}}{{/anyOf}}{{^anyOf}}{{>pojo}}{{/anyOf}}{{/oneOf}}{{/vendorExtensions.x-is-one-of-interface}}{{/isEnum}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: With useSealedOneOfInterfaces=true, native now emits sealed interface ... permits ... through the new oneof_interface branch. The PR says sealed is unsupported for native, and the code has no guard for it. Add a native guard that rejects or ignores the option, or confirm the generated Java 11 build compiles.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/main/resources/Java/libraries/native/model.mustache, line 67:

<comment>With `useSealedOneOfInterfaces=true`, native now emits `sealed interface ... permits ...` through the new `oneof_interface` branch. The PR says sealed is unsupported for native, and the code has no guard for it. Add a native guard that rejects or ignores the option, or confirm the generated Java 11 build compiles.</comment>

<file context>
@@ -56,12 +56,14 @@ import org.hibernate.validator.constraints.*;
+{{/vendorExtensions.x-is-one-of-interface}}
 
-{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{#oneOf}}{{#-first}}{{>oneof_model}}{{/-first}}{{/oneOf}}{{^oneOf}}{{#anyOf}}{{#-first}}{{>anyof_model}}{{/-first}}{{/anyOf}}{{^anyOf}}{{>pojo}}{{/anyOf}}{{/oneOf}}{{/isEnum}}
+{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{#vendorExtensions.x-is-one-of-interface}}{{>oneof_interface}}{{/vendorExtensions.x-is-one-of-interface}}{{^vendorExtensions.x-is-one-of-interface}}{{#oneOf}}{{#-first}}{{>oneof_model}}{{/-first}}{{/oneOf}}{{^oneOf}}{{#anyOf}}{{#-first}}{{>anyof_model}}{{/-first}}{{/anyOf}}{{^anyOf}}{{>pojo}}{{/anyOf}}{{/oneOf}}{{/vendorExtensions.x-is-one-of-interface}}{{/isEnum}}
 {{/model}}
 {{/models}}
</file context>

{{/model}}
{{/models}}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

{{/isEnum}}
{{^isEnum}}
{{#vendorExtensions.x-is-one-of-interface}}
{{>pojo_doc}}

{{/vendorExtensions.x-is-one-of-interface}}
{{^vendorExtensions.x-is-one-of-interface}}
{{^oneOf.isEmpty}}
{{>model_oneof_doc}}

Expand All @@ -19,5 +24,6 @@

{{/oneOf}}
{{/anyOf}}
{{/vendorExtensions.x-is-one-of-interface}}
{{/isEnum}}
{{/model}}{{/models}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{#supportUrlQuery}}
/**
* Convert the instance into URL query string.
*
* @param prefix prefix of the query string
* @return URL query string
*/
public String toUrlQueryString(String prefix);

/**
* Convert the instance into URL query string.
*
* @return URL query string
*/
default String toUrlQueryString() {
return toUrlQueryString(null);
}
{{/supportUrlQuery}}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public {{>sealed}}interface {{classname}} {{#vendorExtensions.x-implements}}{{#-
{{#discriminator}}
public {{propertyType}} {{propertyGetter}}();
{{/discriminator}}
{{>oneof_interface_members}}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{! Hook for libraries that need extra members on the generated oneOf interface; see libraries/native. }}
Original file line number Diff line number Diff line change
Expand Up @@ -6146,6 +6146,74 @@ public void testUseDeductionForOneInterfaces() {

}

@Test
public void testNativeUseOneOfInterfacesWithDiscriminator() {
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/oneof_interface_petstore.yaml",
JavaClientCodegen.NATIVE, Map.of(USE_ONE_OF_INTERFACES, "true"));
validateJavaSourceFiles(new ArrayList<>(files.values()));

JavaFileAssert.assertThat(files.get("PetRequest.java"))
.isInterface()
.fileDoesNotContain("AbstractOpenApiSchema", "TypeReference", "getActualInstance")
.assertTypeAnnotations()
.containsWithNameAndAttributes("JsonTypeInfo", Map.of("use", "JsonTypeInfo.Id.NAME", "property", "\"petType\""))
.recursivelyContainsWithNameAndAttributes("JsonSubTypes.Type", Map.of("value", "CatRequest.class", "name", "\"CAT\""))
.recursivelyContainsWithNameAndAttributes("JsonSubTypes.Type", Map.of("value", "DogRequest.class", "name", "\"DOG\""));
JavaFileAssert.assertThat(files.get("CatRequest.java")).isNormalClass().implementsInterfaces("PetRequest");
JavaFileAssert.assertThat(files.get("DogRequest.java")).isNormalClass().implementsInterfaces("PetRequest");
}

@DataProvider(name = "nativeJacksonVersions")
public Object[][] nativeJacksonVersions() {
return new Object[][]{{false}, {true}};
}

@Test(dataProvider = "nativeJacksonVersions")
public void testNativeUseDeductionForOneOfInterfaces(boolean useJackson3) {
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/native/oneof-interface-deduction.yaml",
JavaClientCodegen.NATIVE,
Map.of(USE_ONE_OF_INTERFACES, "true", USE_DEDUCTION_FOR_ONE_OF_INTERFACES, "true",
JavaClientCodegen.USE_JACKSON_3, useJackson3));
validateJavaSourceFiles(new ArrayList<>(files.values()));

JavaFileAssert.assertThat(files.get("Author.java"))
.isInterface()
.fileDoesNotContain("AbstractOpenApiSchema", "TypeReference", "getActualInstance")
// used by the generated api classes for deepObject and exploded query parameters
.fileContains("public String toUrlQueryString(String prefix);", "default String toUrlQueryString()")
.assertTypeAnnotations()
.containsWithNameAndAttributes("JsonTypeInfo", Map.of("use", "JsonTypeInfo.Id.DEDUCTION"))
.recursivelyContainsWithNameAndAttributes("JsonSubTypes.Type", Map.of("value", "ServiceAuthor.class"))
.recursivelyContainsWithNameAndAttributes("JsonSubTypes.Type", Map.of("value", "UserAuthor.class"));
JavaFileAssert.assertThat(files.get("ServiceAuthor.java")).isNormalClass().implementsInterfaces("Author");
JavaFileAssert.assertThat(files.get("UserAuthor.java")).isNormalClass().implementsInterfaces("Author");
}

@Test
public void testNativeOneOfWithoutUseOneOfInterfacesStillGeneratesWrapperClass() {
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/native/oneof-interface-deduction.yaml",
JavaClientCodegen.NATIVE, Map.of());
validateJavaSourceFiles(new ArrayList<>(files.values()));

JavaFileAssert.assertThat(files.get("Author.java"))
.isNormalClass()
.extendsClass("AbstractOpenApiSchema")
.fileContains("getActualInstance");
JavaFileAssert.assertThat(files.get("ServiceAuthor.java")).doesNotImplementInterfaces("Author");
}

@Test
public void testNativeOneOfInterfaceOmitsUrlQueryMembersWithoutSupportUrlQuery() {
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/native/oneof-interface-deduction.yaml",
JavaClientCodegen.NATIVE,
Map.of(USE_ONE_OF_INTERFACES, "true", JavaClientCodegen.SUPPORT_URL_QUERY, false));
validateJavaSourceFiles(new ArrayList<>(files.values()));

JavaFileAssert.assertThat(files.get("Author.java"))
.isInterface()
.fileDoesNotContain("toUrlQueryString");
}

@Test
public void testSwagger2TagImportRestAssured() throws IOException {
final Map<String, File> files = generateFromContract(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
openapi: 3.0.3
info:
title: oneOf without discriminator
description: >
oneOf of two object schemas without a discriminator. The variants are told apart by their
(disjoint) sets of properties, which is what useDeductionForOneOfInterfaces relies on.
version: 1.0.0
paths:
/author:
get:
operationId: getAuthor
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Author'
post:
operationId: createAuthor
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Author'
responses:
'204':
description: created
components:
schemas:
Author:
oneOf:
- $ref: '#/components/schemas/ServiceAuthor'
- $ref: '#/components/schemas/UserAuthor'
ServiceAuthor:
type: object
required:
- subject
properties:
subject:
type: string
UserAuthor:
type: object
required:
- id
- domainId
properties:
id:
type: string
domainId:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
#
# This file is auto-generated by OpenAPI Generator (https://openapi-generator.tech)

name: Java CI with Maven

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

jobs:
build:
name: Build oneOf without discriminator
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 17, 21 ]
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --no-transfer-progress --file pom.xml
21 changes: 21 additions & 0 deletions samples/client/others/java/native-oneof-interface/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# exclude jar for gradle wrapper
!gradle/wrapper/*.jar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# build files
**/target
target
.gradle
build
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,36 @@
.github/workflows/maven.yml
.gitignore
.travis.yml
README.md
api/openapi.yaml
build.gradle
build.sbt
docs/Author.md
docs/DefaultApi.md
docs/ServiceAuthor.md
docs/UserAuthor.md
git_push.sh
gradle.properties
gradle/wrapper/gradle-wrapper.jar
gradle/wrapper/gradle-wrapper.properties
gradlew
gradlew.bat
pom.xml
settings.gradle
src/main/AndroidManifest.xml
src/main/java/org/openapitools/client/ApiClient.java
src/main/java/org/openapitools/client/ApiException.java
src/main/java/org/openapitools/client/ApiResponse.java
src/main/java/org/openapitools/client/Configuration.java
src/main/java/org/openapitools/client/JSON.java
src/main/java/org/openapitools/client/Pair.java
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/ServerConfiguration.java
src/main/java/org/openapitools/client/ServerVariable.java
src/main/java/org/openapitools/client/api/DefaultApi.java
src/main/java/org/openapitools/client/model/AbstractOpenApiSchema.java
src/main/java/org/openapitools/client/model/Author.java
src/main/java/org/openapitools/client/model/ServiceAuthor.java
src/main/java/org/openapitools/client/model/UserAuthor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.28.0-SNAPSHOT
16 changes: 16 additions & 0 deletions samples/client/others/java/native-oneof-interface/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Generated by: https://openapi-generator.tech
#
language: java
jdk:
- oraclejdk11
before_install:
# ensure gradlew has proper permission
- chmod a+x ./gradlew
script:
# test using maven
- mvn test
# uncomment below to test using gradle
# - gradle test
# uncomment below to test using sbt
# - sbt test
Loading
Loading