diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java
index 77b471c59c9..b8bf2bcd669 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java
@@ -2128,7 +2128,7 @@ public class ModelUtils {
}
if (schema instanceof JsonSchema) {
- if (schema.getTypes() != null) {
+ if (schema.getTypes() != null && !schema.getTypes().isEmpty()) {
return String.valueOf(schema.getTypes().iterator().next());
} else {
return null;
diff --git a/modules/openapi-generator/src/test/resources/3_1/java/petstore.yaml b/modules/openapi-generator/src/test/resources/3_1/java/petstore.yaml
index 5877e4448fa..4b20b4fa28b 100644
--- a/modules/openapi-generator/src/test/resources/3_1/java/petstore.yaml
+++ b/modules/openapi-generator/src/test/resources/3_1/java/petstore.yaml
@@ -665,6 +665,47 @@ paths:
responses:
'200':
description: Successful Response
+ "/fake/inline/schema/anyof/path1":
+ get:
+ tags:
+ - fake
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ anyOf:
+ - type: 'null'
+ - "$ref": "#/components/schemas/myObject"
+ "/fake/inline/schema/anyof/path2":
+ get:
+ tags:
+ - fake
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ anyOf:
+ - "$ref": "#/components/schemas/myObject"
+ - type: 'null'
+ "/fake/inline/schema/anyof/path3":
+ get:
+ tags:
+ - fake
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ anyOf:
+ - type: array
+ items:
+ "$ref": "#/components/schemas/myObject"
+ - type: 'null'
externalDocs:
description: Find out more about Swagger
url: 'http://swagger.io'
@@ -981,3 +1022,5 @@ components:
AllOfSimpleModel:
allOf:
- $ref: '#/components/schemas/SimpleModelWithArrayProperty'
+ myObject:
+ type: object
\ No newline at end of file
diff --git a/samples/client/petstore/java/okhttp-gson-3.1/README.md b/samples/client/petstore/java/okhttp-gson-3.1/README.md
index ef09be2b770..4e0b2c0ce5f 100644
--- a/samples/client/petstore/java/okhttp-gson-3.1/README.md
+++ b/samples/client/petstore/java/okhttp-gson-3.1/README.md
@@ -93,10 +93,10 @@ public class Example {
FakeApi apiInstance = new FakeApi(defaultClient);
try {
- Object result = apiInstance.op1();
+ Object result = apiInstance.fakeInlineSchemaAnyofPath1Get();
System.out.println(result);
} catch (ApiException e) {
- System.err.println("Exception when calling FakeApi#op1");
+ System.err.println("Exception when calling FakeApi#fakeInlineSchemaAnyofPath1Get");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
@@ -113,6 +113,9 @@ All URIs are relative to *http://petstore.swagger.io/v2*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
+*FakeApi* | [**fakeInlineSchemaAnyofPath1Get**](docs/FakeApi.md#fakeInlineSchemaAnyofPath1Get) | **GET** /fake/inline/schema/anyof/path1 |
+*FakeApi* | [**fakeInlineSchemaAnyofPath2Get**](docs/FakeApi.md#fakeInlineSchemaAnyofPath2Get) | **GET** /fake/inline/schema/anyof/path2 |
+*FakeApi* | [**fakeInlineSchemaAnyofPath3Get**](docs/FakeApi.md#fakeInlineSchemaAnyofPath3Get) | **GET** /fake/inline/schema/anyof/path3 |
*FakeApi* | [**op1**](docs/FakeApi.md#op1) | **POST** /fake/api/changeowner | op1
*FakeApi* | [**op2**](docs/FakeApi.md#op2) | **POST** /fake/api/changename | op2
*FakeApi* | [**op3**](docs/FakeApi.md#op3) | **POST** /fake/api/query/enum | op3
diff --git a/samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml b/samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml
index 4f61199e49a..262309383b0 100644
--- a/samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml
+++ b/samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml
@@ -751,6 +751,47 @@ paths:
- fake
x-accepts:
- application/json
+ /fake/inline/schema/anyof/path1:
+ get:
+ responses:
+ "200":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/myObject'
+ description: ""
+ tags:
+ - fake
+ x-accepts:
+ - application/json
+ /fake/inline/schema/anyof/path2:
+ get:
+ responses:
+ "200":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/myObject'
+ description: ""
+ tags:
+ - fake
+ x-accepts:
+ - application/json
+ /fake/inline/schema/anyof/path3:
+ get:
+ responses:
+ "200":
+ content:
+ application/json:
+ schema:
+ items:
+ $ref: '#/components/schemas/myObject'
+ nullable: true
+ description: ""
+ tags:
+ - fake
+ x-accepts:
+ - application/json
components:
parameters:
ref_to_uuid:
@@ -1074,6 +1115,8 @@ components:
AllOfSimpleModel:
allOf:
- $ref: '#/components/schemas/SimpleModelWithArrayProperty'
+ myObject:
+ type: object
updatePetWithForm_request:
properties:
name:
diff --git a/samples/client/petstore/java/okhttp-gson-3.1/docs/FakeApi.md b/samples/client/petstore/java/okhttp-gson-3.1/docs/FakeApi.md
index 12709419253..19db959c0ed 100644
--- a/samples/client/petstore/java/okhttp-gson-3.1/docs/FakeApi.md
+++ b/samples/client/petstore/java/okhttp-gson-3.1/docs/FakeApi.md
@@ -4,6 +4,9 @@ All URIs are relative to *http://petstore.swagger.io/v2*
| Method | HTTP request | Description |
|------------- | ------------- | -------------|
+| [**fakeInlineSchemaAnyofPath1Get**](FakeApi.md#fakeInlineSchemaAnyofPath1Get) | **GET** /fake/inline/schema/anyof/path1 | |
+| [**fakeInlineSchemaAnyofPath2Get**](FakeApi.md#fakeInlineSchemaAnyofPath2Get) | **GET** /fake/inline/schema/anyof/path2 | |
+| [**fakeInlineSchemaAnyofPath3Get**](FakeApi.md#fakeInlineSchemaAnyofPath3Get) | **GET** /fake/inline/schema/anyof/path3 | |
| [**op1**](FakeApi.md#op1) | **POST** /fake/api/changeowner | op1 |
| [**op2**](FakeApi.md#op2) | **POST** /fake/api/changename | op2 |
| [**op3**](FakeApi.md#op3) | **POST** /fake/api/query/enum | op3 |
@@ -13,6 +16,174 @@ All URIs are relative to *http://petstore.swagger.io/v2*
| [**responseRefToRef**](FakeApi.md#responseRefToRef) | **GET** /ref/ref | |
+
+# **fakeInlineSchemaAnyofPath1Get**
+> Object fakeInlineSchemaAnyofPath1Get()
+
+
+
+### 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.FakeApi;
+
+public class Example {
+ public static void main(String[] args) {
+ ApiClient defaultClient = Configuration.getDefaultApiClient();
+ defaultClient.setBasePath("http://petstore.swagger.io/v2");
+
+ FakeApi apiInstance = new FakeApi(defaultClient);
+ try {
+ Object result = apiInstance.fakeInlineSchemaAnyofPath1Get();
+ System.out.println(result);
+ } catch (ApiException e) {
+ System.err.println("Exception when calling FakeApi#fakeInlineSchemaAnyofPath1Get");
+ System.err.println("Status code: " + e.getCode());
+ System.err.println("Reason: " + e.getResponseBody());
+ System.err.println("Response headers: " + e.getResponseHeaders());
+ e.printStackTrace();
+ }
+ }
+}
+```
+
+### Parameters
+This endpoint does not need any parameter.
+
+### Return type
+
+**Object**
+
+### Authorization
+
+No authorization required
+
+### HTTP request headers
+
+ - **Content-Type**: Not defined
+ - **Accept**: application/json
+
+### HTTP response details
+| Status code | Description | Response headers |
+|-------------|-------------|------------------|
+| **200** | | - |
+
+
+# **fakeInlineSchemaAnyofPath2Get**
+> Object fakeInlineSchemaAnyofPath2Get()
+
+
+
+### 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.FakeApi;
+
+public class Example {
+ public static void main(String[] args) {
+ ApiClient defaultClient = Configuration.getDefaultApiClient();
+ defaultClient.setBasePath("http://petstore.swagger.io/v2");
+
+ FakeApi apiInstance = new FakeApi(defaultClient);
+ try {
+ Object result = apiInstance.fakeInlineSchemaAnyofPath2Get();
+ System.out.println(result);
+ } catch (ApiException e) {
+ System.err.println("Exception when calling FakeApi#fakeInlineSchemaAnyofPath2Get");
+ System.err.println("Status code: " + e.getCode());
+ System.err.println("Reason: " + e.getResponseBody());
+ System.err.println("Response headers: " + e.getResponseHeaders());
+ e.printStackTrace();
+ }
+ }
+}
+```
+
+### Parameters
+This endpoint does not need any parameter.
+
+### Return type
+
+**Object**
+
+### Authorization
+
+No authorization required
+
+### HTTP request headers
+
+ - **Content-Type**: Not defined
+ - **Accept**: application/json
+
+### HTTP response details
+| Status code | Description | Response headers |
+|-------------|-------------|------------------|
+| **200** | | - |
+
+
+# **fakeInlineSchemaAnyofPath3Get**
+> List<Object> fakeInlineSchemaAnyofPath3Get()
+
+
+
+### 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.FakeApi;
+
+public class Example {
+ public static void main(String[] args) {
+ ApiClient defaultClient = Configuration.getDefaultApiClient();
+ defaultClient.setBasePath("http://petstore.swagger.io/v2");
+
+ FakeApi apiInstance = new FakeApi(defaultClient);
+ try {
+ List