Skip to content

Commit

Permalink
better npe handling when processing openapi 3.1 spec
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Jan 13, 2024
1 parent 75ef9e0 commit c6efe88
Show file tree
Hide file tree
Showing 6 changed files with 445 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,11 @@ private Schema processNormalize31Spec(Schema schema, Set<Schema> visitedSchemas)
return new Schema();
}

// return schema if nothing in 3.1 spec types to normalize
if (schema.getTypes() == null) {
return schema;
}

// process null
if (schema.getTypes().contains("null")) {
schema.setNullable(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,44 @@ paths:
$ref: '#/components/responses/ref'
parameters:
- $ref: '#/components/parameters/ref_to_uuid'
"/fake/api/changeowner":
post:
summary: op1
operationId: op1
tags:
- fake
parameters: []
responses:
'201':
description: Successful Response
content:
application/json:
schema: {}
'422':
description: Validation Error
content:
application/json:
schema:
"$ref": "#/components/schemas/HTTPValidationError"
"/fake/api/changename":
post:
summary: op2
operationId: op2
tags:
- fake
parameters: []
responses:
'201':
description: Successful Response
content:
application/json:
schema: {}
'422':
description: Validation Error
content:
application/json:
schema:
"$ref": "#/components/schemas/HTTPValidationError"
externalDocs:
description: Find out more about Swagger
url: 'http://swagger.io'
Expand Down Expand Up @@ -847,3 +885,7 @@ components:
description: test array in 3.1 spec
items:
type: string
HTTPValidationError:
properties: {}
type: object
title: HTTPValidationError
7 changes: 4 additions & 3 deletions samples/client/petstore/java/okhttp-gson-3.1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,11 @@ public class Example {
defaultClient.setBasePath("http://petstore.swagger.io/v2");

FakeApi apiInstance = new FakeApi(defaultClient);
UUID refToUuid = UUID.fromString("61864654-6e6b-4152-a62f-795fdd606bc2"); // UUID | to test ref to parameter (uuid)
try {
String result = apiInstance.refToRefParameter(refToUuid);
Object result = apiInstance.op1();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#refToRefParameter");
System.err.println("Exception when calling FakeApi#op1");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
Expand All @@ -113,6 +112,8 @@ All URIs are relative to *http://petstore.swagger.io/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*FakeApi* | [**op1**](docs/FakeApi.md#op1) | **POST** /fake/api/changeowner | op1
*FakeApi* | [**op2**](docs/FakeApi.md#op2) | **POST** /fake/api/changename | op2
*FakeApi* | [**refToRefParameter**](docs/FakeApi.md#refToRefParameter) | **GET** /ref/ref_to_parameter |
*FakeApi* | [**responseNoRef**](docs/FakeApi.md#responseNoRef) | **GET** /no_ref |
*FakeApi* | [**responseRefToNoRef**](docs/FakeApi.md#responseRefToNoRef) | **GET** /ref/no_ref |
Expand Down
44 changes: 44 additions & 0 deletions samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,46 @@ paths:
x-accepts: text/plain
parameters:
- $ref: '#/components/parameters/ref_to_uuid'
/fake/api/changeowner:
post:
operationId: op1
parameters: []
responses:
"201":
content:
application/json:
schema: {}
description: Successful Response
"422":
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
description: Validation Error
summary: op1
tags:
- fake
x-accepts: application/json
/fake/api/changename:
post:
operationId: op2
parameters: []
responses:
"201":
content:
application/json:
schema: {}
description: Successful Response
"422":
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
description: Validation Error
summary: op2
tags:
- fake
x-accepts: application/json
components:
parameters:
ref_to_uuid:
Expand Down Expand Up @@ -912,6 +952,10 @@ components:
items:
type: string
type: array
HTTPValidationError:
properties: {}
title: HTTPValidationError
type: object
updatePetWithForm_request:
properties:
name:
Expand Down
116 changes: 116 additions & 0 deletions samples/client/petstore/java/okhttp-gson-3.1/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,128 @@ All URIs are relative to *http://petstore.swagger.io/v2*

| Method | HTTP request | Description |
|------------- | ------------- | -------------|
| [**op1**](FakeApi.md#op1) | **POST** /fake/api/changeowner | op1 |
| [**op2**](FakeApi.md#op2) | **POST** /fake/api/changename | op2 |
| [**refToRefParameter**](FakeApi.md#refToRefParameter) | **GET** /ref/ref_to_parameter | |
| [**responseNoRef**](FakeApi.md#responseNoRef) | **GET** /no_ref | |
| [**responseRefToNoRef**](FakeApi.md#responseRefToNoRef) | **GET** /ref/no_ref | |
| [**responseRefToRef**](FakeApi.md#responseRefToRef) | **GET** /ref/ref | |


<a id="op1"></a>
# **op1**
> Object op1()
op1

### 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.op1();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#op1");
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 |
|-------------|-------------|------------------|
| **201** | Successful Response | - |
| **422** | Validation Error | - |

<a id="op2"></a>
# **op2**
> Object op2()
op2

### 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.op2();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#op2");
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 |
|-------------|-------------|------------------|
| **201** | Successful Response | - |
| **422** | Validation Error | - |

<a id="refToRefParameter"></a>
# **refToRefParameter**
> String refToRefParameter(refToUuid)
Expand Down
Loading

0 comments on commit c6efe88

Please sign in to comment.