Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support x-internal in models and operations #17639

Merged
merged 1 commit into from
Jan 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -4507,6 +4507,11 @@ public CodegenOperation fromOperation(String path,
if (operation == null)
throw new RuntimeException("operation cannot be null in fromOperation");

if (operation.getExtensions() != null && Boolean.TRUE.equals(operation.getExtensions().get("x-internal"))) {
LOGGER.info("Operation ({} {} - {}) not generated since x-internal is set to true",
httpMethod, path, operation.getOperationId());
}

Map<String, Schema> schemas = ModelUtils.getSchemas(this.openAPI);
CodegenOperation op = CodegenModelFactory.newInstance(CodegenModelType.OPERATION);
Set<String> imports = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,10 @@ void generateModels(List<File> files, List<ModelMap> allModels, List<String> unu

Schema schema = schemas.get(name);

if (ModelUtils.isFreeFormObject(schema)) { // check to see if it's a free-form object
if (schema.getExtensions() != null && Boolean.TRUE.equals(schema.getExtensions().get("x-internal"))) {
LOGGER.info("Model {} not generated since x-internal is set to true", name);
continue;
} else if (ModelUtils.isFreeFormObject(schema)) { // check to see if it's a free-form object
if (!ModelUtils.shouldGenerateFreeFormObjectModel(name, config)) {
LOGGER.info("Model {} not generated since it's a free-form object", name);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,22 @@ paths:
$ref: '#/components/schemas/Variable'
'400':
description: Invalid Value
/internal/only:
get:
x-internal: true
tags:
- values
summary: internal only
description: ''
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Variable'
'400':
description: Invalid Value
servers:
- url: 'http://{server}.swagger.io:{port}/v2'
description: petstore server
Expand Down Expand Up @@ -2490,6 +2506,7 @@ components:
- pending
- sold
PropertyNameCollision:
x-internal: false
type: object
properties:
_type:
Expand All @@ -2498,6 +2515,12 @@ components:
type: string
type_:
type: string
InteralOnly:
type: object
x-internal: true
properties:
type:
type: string
AllOfModelArrayAnyOf:
allOf:
- $ref: "#/components/schemas/Category"
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/java/okhttp-gson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Class | Method | HTTP request | Description
*UserApi* | [**logoutUser**](docs/UserApi.md#logoutUser) | **GET** /user/logout | Logs out current logged in user session
*UserApi* | [**updateUser**](docs/UserApi.md#updateUser) | **PUT** /user/{username} | Updated user
*ValuesApi* | [**getSomeValues**](docs/ValuesApi.md#getSomeValues) | **GET** /values | Get some primitive variable values
*ValuesApi* | [**internalOnlyGet**](docs/ValuesApi.md#internalOnlyGet) | **GET** /internal/only | internal only


## Documentation for Models
Expand Down
24 changes: 24 additions & 0 deletions samples/client/petstore/java/okhttp-gson/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,23 @@ paths:
tags:
- values
x-accepts: application/json
/internal/only:
get:
description: ""
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/Variable'
description: successful operation
"400":
description: Invalid Value
summary: internal only
tags:
- values
x-internal: true
x-accepts: application/json
components:
requestBodies:
UserArray:
Expand Down Expand Up @@ -2494,6 +2511,13 @@ components:
type_:
type: string
type: object
x-internal: false
InteralOnly:
properties:
type:
type: string
type: object
x-internal: true
AllOfModelArrayAnyOf:
allOf:
- $ref: '#/components/schemas/Category'
Expand Down
60 changes: 60 additions & 0 deletions samples/client/petstore/java/okhttp-gson/docs/ValuesApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
| Method | HTTP request | Description |
|------------- | ------------- | -------------|
| [**getSomeValues**](ValuesApi.md#getSomeValues) | **GET** /values | Get some primitive variable values |
| [**internalOnlyGet**](ValuesApi.md#internalOnlyGet) | **GET** /internal/only | internal only |


<a id="getSomeValues"></a>
Expand Down Expand Up @@ -66,3 +67,62 @@ No authorization required
| **200** | successful operation | - |
| **400** | Invalid Value | - |

<a id="internalOnlyGet"></a>
# **internalOnlyGet**
> Variable internalOnlyGet()

internal only



### 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.ValuesApi;

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

ValuesApi apiInstance = new ValuesApi(defaultClient);
try {
Variable result = apiInstance.internalOnlyGet();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ValuesApi#internalOnlyGet");
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

[**Variable**](Variable.md)

### Authorization

No authorization required

### HTTP request headers

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,121 @@ public okhttp3.Call getSomeValuesAsync(final ApiCallback<Variable> _callback) th
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
/**
* Build call for internalOnlyGet
* @param _callback Callback for upload/download progress
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> successful operation </td><td> - </td></tr>
<tr><td> 400 </td><td> Invalid Value </td><td> - </td></tr>
</table>
*/
public okhttp3.Call internalOnlyGetCall(final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };

// Determine Base Path to Use
if (localCustomBaseUrl != null){
basePath = localCustomBaseUrl;
} else if ( localBasePaths.length > 0 ) {
basePath = localBasePaths[localHostIndex];
} else {
basePath = null;
}

Object localVarPostBody = null;

// create path and map variables
String localVarPath = "/internal/only";

List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();

final String[] localVarAccepts = {
"application/json"
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) {
localVarHeaderParams.put("Accept", localVarAccept);
}

final String[] localVarContentTypes = {
};
final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
if (localVarContentType != null) {
localVarHeaderParams.put("Content-Type", localVarContentType);
}

String[] localVarAuthNames = new String[] { };
return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
}

@SuppressWarnings("rawtypes")
private okhttp3.Call internalOnlyGetValidateBeforeCall(final ApiCallback _callback) throws ApiException {
return internalOnlyGetCall(_callback);

}

/**
* internal only
*
* @return Variable
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> successful operation </td><td> - </td></tr>
<tr><td> 400 </td><td> Invalid Value </td><td> - </td></tr>
</table>
*/
public Variable internalOnlyGet() throws ApiException {
ApiResponse<Variable> localVarResp = internalOnlyGetWithHttpInfo();
return localVarResp.getData();
}

/**
* internal only
*
* @return ApiResponse&lt;Variable&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> successful operation </td><td> - </td></tr>
<tr><td> 400 </td><td> Invalid Value </td><td> - </td></tr>
</table>
*/
public ApiResponse<Variable> internalOnlyGetWithHttpInfo() throws ApiException {
okhttp3.Call localVarCall = internalOnlyGetValidateBeforeCall(null);
Type localVarReturnType = new TypeToken<Variable>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}

/**
* internal only (asynchronously)
*
* @param _callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> successful operation </td><td> - </td></tr>
<tr><td> 400 </td><td> Invalid Value </td><td> - </td></tr>
</table>
*/
public okhttp3.Call internalOnlyGetAsync(final ApiCallback<Variable> _callback) throws ApiException {

okhttp3.Call localVarCall = internalOnlyGetValidateBeforeCall(_callback);
Type localVarReturnType = new TypeToken<Variable>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
}
Loading