Skip to content

Commit

Permalink
Resolve inline schemas in webhooks (#20165)
Browse files Browse the repository at this point in the history
* resolve inline schemas in webhooks

* update samples
  • Loading branch information
wing328 authored Nov 24, 2024
1 parent 1ba18a0 commit 093a51e
Show file tree
Hide file tree
Showing 15 changed files with 1,186 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.annotations.Webhook;
import io.swagger.v3.oas.annotations.Webhooks;
import io.swagger.v3.oas.models.*;
import io.swagger.v3.oas.models.PathItem.HttpMethod;
import io.swagger.v3.oas.models.callbacks.Callback;
Expand All @@ -35,6 +37,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Path;
import java.util.*;

public class InlineModelResolver {
Expand Down Expand Up @@ -106,10 +109,22 @@ void flatten(OpenAPI openAPI) {
}

flattenPaths();
flattenWebhooks();
flattenComponents();
flattenComponentResponses();
}

/**
* Flatten inline models in Webhooks
*/
private void flattenWebhooks() {
Map<String, PathItem> webhooks = openAPI.getWebhooks();
if (webhooks == null) {
return;
}
flattenPathItems(webhooks);
}

/**
* Flatten inline models in Paths
*/
Expand All @@ -118,8 +133,16 @@ private void flattenPaths() {
if (paths == null) {
return;
}
flattenPathItems(paths);
}

for (Map.Entry<String, PathItem> pathsEntry : paths.entrySet()) {
/**
* Flatten inline models in path items
*
* @param pathItemMap Map of path items
*/
private void flattenPathItems(Map<String, PathItem> pathItemMap) {
for (Map.Entry<String, PathItem> pathsEntry : pathItemMap.entrySet()) {
PathItem path = pathsEntry.getValue();
List<Map.Entry<HttpMethod, Operation>> toFlatten = new ArrayList<>(path.readOperationsMap().entrySet());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,36 @@ tags:
description: Access to Petstore orders
- name: user
description: Operations about user
webhooks:
/fake/webhooks/sources/deleted:
post:
requestBody:
content:
application/json:
schema:
description: inline schema in webhooks
required:
- event_timestamp
- event_type
- event
properties:
event_timestamp:
type: string
format: date-time
event_type:
type: string
event:
type: object
required:
- event_id
properties:
event_id:
type: string
responses:
'200':
description: successful operation
'405':
description: Invalid input
paths:
/pet:
post:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ docs/CircularReference1.md
docs/CircularReference2.md
docs/CircularReference3.md
docs/CodesEnum.md
docs/DefaultApi.md
docs/Dog.md
docs/FakeApi.md
docs/FakeWebhooksSourcesDeletedPostRequest.md
docs/FakeWebhooksSourcesDeletedPostRequestEvent.md
docs/ModelApiResponse.md
docs/OneOfStringOrInt.md
docs/Order.md
Expand Down Expand Up @@ -55,6 +58,7 @@ src/main/java/org/openapitools/client/ProgressResponseBody.java
src/main/java/org/openapitools/client/ServerConfiguration.java
src/main/java/org/openapitools/client/ServerVariable.java
src/main/java/org/openapitools/client/StringUtil.java
src/main/java/org/openapitools/client/api/DefaultApi.java
src/main/java/org/openapitools/client/api/FakeApi.java
src/main/java/org/openapitools/client/api/PetApi.java
src/main/java/org/openapitools/client/api/StoreApi.java
Expand All @@ -79,6 +83,8 @@ src/main/java/org/openapitools/client/model/CircularReference2.java
src/main/java/org/openapitools/client/model/CircularReference3.java
src/main/java/org/openapitools/client/model/CodesEnum.java
src/main/java/org/openapitools/client/model/Dog.java
src/main/java/org/openapitools/client/model/FakeWebhooksSourcesDeletedPostRequest.java
src/main/java/org/openapitools/client/model/FakeWebhooksSourcesDeletedPostRequestEvent.java
src/main/java/org/openapitools/client/model/ModelApiResponse.java
src/main/java/org/openapitools/client/model/OneOfStringOrInt.java
src/main/java/org/openapitools/client/model/Order.java
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/java/okhttp-gson-3.1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ Class | Method | HTTP request | Description
- [CircularReference3](docs/CircularReference3.md)
- [CodesEnum](docs/CodesEnum.md)
- [Dog](docs/Dog.md)
- [FakeWebhooksSourcesDeletedPostRequest](docs/FakeWebhooksSourcesDeletedPostRequest.md)
- [FakeWebhooksSourcesDeletedPostRequestEvent](docs/FakeWebhooksSourcesDeletedPostRequestEvent.md)
- [ModelApiResponse](docs/ModelApiResponse.md)
- [OneOfStringOrInt](docs/OneOfStringOrInt.md)
- [Order](docs/Order.md)
Expand Down
20 changes: 20 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 @@ -1203,6 +1203,26 @@ components:
- items:
type: string
type: array
_fake_webhooks_sources_deleted_post_request_event:
properties:
event_id:
type: string
required:
- event_id
_fake_webhooks_sources_deleted_post_request:
description: inline schema in webhooks
properties:
event_timestamp:
format: date-time
type: string
event_type:
type: string
event:
$ref: '#/components/schemas/_fake_webhooks_sources_deleted_post_request_event'
required:
- event
- event_timestamp
- event_type
securitySchemes:
petstore_auth:
flows:
Expand Down
69 changes: 69 additions & 0 deletions samples/client/petstore/java/okhttp-gson-3.1/docs/DefaultApi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# DefaultApi

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

| Method | HTTP request | Description |
|------------- | ------------- | -------------|
| [**fakeWebhooksSourcesDeletedPost**](DefaultApi.md#fakeWebhooksSourcesDeletedPost) | **POST** /fake/webhooks/sources/deleted | |


<a id="fakeWebhooksSourcesDeletedPost"></a>
# **fakeWebhooksSourcesDeletedPost**
> fakeWebhooksSourcesDeletedPost(fakeWebhooksSourcesDeletedPostRequest)


### 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://petstore.swagger.io/v2");

DefaultApi apiInstance = new DefaultApi(defaultClient);
FakeWebhooksSourcesDeletedPostRequest fakeWebhooksSourcesDeletedPostRequest = new FakeWebhooksSourcesDeletedPostRequest(); // FakeWebhooksSourcesDeletedPostRequest |
try {
apiInstance.fakeWebhooksSourcesDeletedPost(fakeWebhooksSourcesDeletedPostRequest);
} catch (ApiException e) {
System.err.println("Exception when calling DefaultApi#fakeWebhooksSourcesDeletedPost");
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 |
|------------- | ------------- | ------------- | -------------|
| **fakeWebhooksSourcesDeletedPostRequest** | [**FakeWebhooksSourcesDeletedPostRequest**](FakeWebhooksSourcesDeletedPostRequest.md)| | [optional] |

### Return type

null (empty response body)

### Authorization

No authorization required

### HTTP request headers

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

### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | successful operation | - |
| **405** | Invalid input | - |

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


# FakeWebhooksSourcesDeletedPostRequest

inline schema in webhooks

## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**eventTimestamp** | **OffsetDateTime** | | |
|**eventType** | **String** | | |
|**event** | [**FakeWebhooksSourcesDeletedPostRequestEvent**](FakeWebhooksSourcesDeletedPostRequestEvent.md) | | |



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


# FakeWebhooksSourcesDeletedPostRequestEvent


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**eventId** | **String** | | |



Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, Stri
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.CircularReference2.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.CircularReference3.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Dog.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.FakeWebhooksSourcesDeletedPostRequest.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.FakeWebhooksSourcesDeletedPostRequestEvent.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.ModelApiResponse.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.OneOfStringOrInt.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(new org.openapitools.client.model.Order.CustomTypeAdapterFactory());
Expand Down
Loading

0 comments on commit 093a51e

Please sign in to comment.