Skip to content

Commit 27f7667

Browse files
authored
support x-internal in models and operations (#17639)
1 parent 50ae17b commit 27f7667

File tree

7 files changed

+234
-1
lines changed

7 files changed

+234
-1
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

+5
Original file line numberDiff line numberDiff line change
@@ -4507,6 +4507,11 @@ public CodegenOperation fromOperation(String path,
45074507
if (operation == null)
45084508
throw new RuntimeException("operation cannot be null in fromOperation");
45094509

4510+
if (operation.getExtensions() != null && Boolean.TRUE.equals(operation.getExtensions().get("x-internal"))) {
4511+
LOGGER.info("Operation ({} {} - {}) not generated since x-internal is set to true",
4512+
httpMethod, path, operation.getOperationId());
4513+
}
4514+
45104515
Map<String, Schema> schemas = ModelUtils.getSchemas(this.openAPI);
45114516
CodegenOperation op = CodegenModelFactory.newInstance(CodegenModelType.OPERATION);
45124517
Set<String> imports = new HashSet<>();

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,10 @@ void generateModels(List<File> files, List<ModelMap> allModels, List<String> unu
508508

509509
Schema schema = schemas.get(name);
510510

511-
if (ModelUtils.isFreeFormObject(schema)) { // check to see if it's a free-form object
511+
if (schema.getExtensions() != null && Boolean.TRUE.equals(schema.getExtensions().get("x-internal"))) {
512+
LOGGER.info("Model {} not generated since x-internal is set to true", name);
513+
continue;
514+
} else if (ModelUtils.isFreeFormObject(schema)) { // check to see if it's a free-form object
512515
if (!ModelUtils.shouldGenerateFreeFormObjectModel(name, config)) {
513516
LOGGER.info("Model {} not generated since it's a free-form object", name);
514517
continue;

modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,22 @@ paths:
12751275
$ref: '#/components/schemas/Variable'
12761276
'400':
12771277
description: Invalid Value
1278+
/internal/only:
1279+
get:
1280+
x-internal: true
1281+
tags:
1282+
- values
1283+
summary: internal only
1284+
description: ''
1285+
responses:
1286+
'200':
1287+
description: successful operation
1288+
content:
1289+
application/json:
1290+
schema:
1291+
$ref: '#/components/schemas/Variable'
1292+
'400':
1293+
description: Invalid Value
12781294
servers:
12791295
- url: 'http://{server}.swagger.io:{port}/v2'
12801296
description: petstore server
@@ -2490,6 +2506,7 @@ components:
24902506
- pending
24912507
- sold
24922508
PropertyNameCollision:
2509+
x-internal: false
24932510
type: object
24942511
properties:
24952512
_type:
@@ -2498,6 +2515,12 @@ components:
24982515
type: string
24992516
type_:
25002517
type: string
2518+
InteralOnly:
2519+
type: object
2520+
x-internal: true
2521+
properties:
2522+
type:
2523+
type: string
25012524
AllOfModelArrayAnyOf:
25022525
allOf:
25032526
- $ref: "#/components/schemas/Category"

samples/client/petstore/java/okhttp-gson/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ Class | Method | HTTP request | Description
159159
*UserApi* | [**logoutUser**](docs/UserApi.md#logoutUser) | **GET** /user/logout | Logs out current logged in user session
160160
*UserApi* | [**updateUser**](docs/UserApi.md#updateUser) | **PUT** /user/{username} | Updated user
161161
*ValuesApi* | [**getSomeValues**](docs/ValuesApi.md#getSomeValues) | **GET** /values | Get some primitive variable values
162+
*ValuesApi* | [**internalOnlyGet**](docs/ValuesApi.md#internalOnlyGet) | **GET** /internal/only | internal only
162163

163164

164165
## Documentation for Models

samples/client/petstore/java/okhttp-gson/api/openapi.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,23 @@ paths:
13161316
tags:
13171317
- values
13181318
x-accepts: application/json
1319+
/internal/only:
1320+
get:
1321+
description: ""
1322+
responses:
1323+
"200":
1324+
content:
1325+
application/json:
1326+
schema:
1327+
$ref: '#/components/schemas/Variable'
1328+
description: successful operation
1329+
"400":
1330+
description: Invalid Value
1331+
summary: internal only
1332+
tags:
1333+
- values
1334+
x-internal: true
1335+
x-accepts: application/json
13191336
components:
13201337
requestBodies:
13211338
UserArray:
@@ -2494,6 +2511,13 @@ components:
24942511
type_:
24952512
type: string
24962513
type: object
2514+
x-internal: false
2515+
InteralOnly:
2516+
properties:
2517+
type:
2518+
type: string
2519+
type: object
2520+
x-internal: true
24972521
AllOfModelArrayAnyOf:
24982522
allOf:
24992523
- $ref: '#/components/schemas/Category'

samples/client/petstore/java/okhttp-gson/docs/ValuesApi.md

+60
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
55
| Method | HTTP request | Description |
66
|------------- | ------------- | -------------|
77
| [**getSomeValues**](ValuesApi.md#getSomeValues) | **GET** /values | Get some primitive variable values |
8+
| [**internalOnlyGet**](ValuesApi.md#internalOnlyGet) | **GET** /internal/only | internal only |
89

910

1011
<a id="getSomeValues"></a>
@@ -66,3 +67,62 @@ No authorization required
6667
| **200** | successful operation | - |
6768
| **400** | Invalid Value | - |
6869

70+
<a id="internalOnlyGet"></a>
71+
# **internalOnlyGet**
72+
> Variable internalOnlyGet()
73+
74+
internal only
75+
76+
77+
78+
### Example
79+
```java
80+
// Import classes:
81+
import org.openapitools.client.ApiClient;
82+
import org.openapitools.client.ApiException;
83+
import org.openapitools.client.Configuration;
84+
import org.openapitools.client.models.*;
85+
import org.openapitools.client.api.ValuesApi;
86+
87+
public class Example {
88+
public static void main(String[] args) {
89+
ApiClient defaultClient = Configuration.getDefaultApiClient();
90+
defaultClient.setBasePath("http://petstore.swagger.io:80/v2");
91+
92+
ValuesApi apiInstance = new ValuesApi(defaultClient);
93+
try {
94+
Variable result = apiInstance.internalOnlyGet();
95+
System.out.println(result);
96+
} catch (ApiException e) {
97+
System.err.println("Exception when calling ValuesApi#internalOnlyGet");
98+
System.err.println("Status code: " + e.getCode());
99+
System.err.println("Reason: " + e.getResponseBody());
100+
System.err.println("Response headers: " + e.getResponseHeaders());
101+
e.printStackTrace();
102+
}
103+
}
104+
}
105+
```
106+
107+
### Parameters
108+
This endpoint does not need any parameter.
109+
110+
### Return type
111+
112+
[**Variable**](Variable.md)
113+
114+
### Authorization
115+
116+
No authorization required
117+
118+
### HTTP request headers
119+
120+
- **Content-Type**: Not defined
121+
- **Accept**: application/json
122+
123+
### HTTP response details
124+
| Status code | Description | Response headers |
125+
|-------------|-------------|------------------|
126+
| **200** | successful operation | - |
127+
| **400** | Invalid Value | - |
128+

samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/api/ValuesApi.java

+117
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,121 @@ public okhttp3.Call getSomeValuesAsync(final ApiCallback<Variable> _callback) th
189189
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
190190
return localVarCall;
191191
}
192+
/**
193+
* Build call for internalOnlyGet
194+
* @param _callback Callback for upload/download progress
195+
* @return Call to execute
196+
* @throws ApiException If fail to serialize the request body object
197+
* @http.response.details
198+
<table summary="Response Details" border="1">
199+
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
200+
<tr><td> 200 </td><td> successful operation </td><td> - </td></tr>
201+
<tr><td> 400 </td><td> Invalid Value </td><td> - </td></tr>
202+
</table>
203+
*/
204+
public okhttp3.Call internalOnlyGetCall(final ApiCallback _callback) throws ApiException {
205+
String basePath = null;
206+
// Operation Servers
207+
String[] localBasePaths = new String[] { };
208+
209+
// Determine Base Path to Use
210+
if (localCustomBaseUrl != null){
211+
basePath = localCustomBaseUrl;
212+
} else if ( localBasePaths.length > 0 ) {
213+
basePath = localBasePaths[localHostIndex];
214+
} else {
215+
basePath = null;
216+
}
217+
218+
Object localVarPostBody = null;
219+
220+
// create path and map variables
221+
String localVarPath = "/internal/only";
222+
223+
List<Pair> localVarQueryParams = new ArrayList<Pair>();
224+
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
225+
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
226+
Map<String, String> localVarCookieParams = new HashMap<String, String>();
227+
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
228+
229+
final String[] localVarAccepts = {
230+
"application/json"
231+
};
232+
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
233+
if (localVarAccept != null) {
234+
localVarHeaderParams.put("Accept", localVarAccept);
235+
}
236+
237+
final String[] localVarContentTypes = {
238+
};
239+
final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
240+
if (localVarContentType != null) {
241+
localVarHeaderParams.put("Content-Type", localVarContentType);
242+
}
243+
244+
String[] localVarAuthNames = new String[] { };
245+
return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
246+
}
247+
248+
@SuppressWarnings("rawtypes")
249+
private okhttp3.Call internalOnlyGetValidateBeforeCall(final ApiCallback _callback) throws ApiException {
250+
return internalOnlyGetCall(_callback);
251+
252+
}
253+
254+
/**
255+
* internal only
256+
*
257+
* @return Variable
258+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
259+
* @http.response.details
260+
<table summary="Response Details" border="1">
261+
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
262+
<tr><td> 200 </td><td> successful operation </td><td> - </td></tr>
263+
<tr><td> 400 </td><td> Invalid Value </td><td> - </td></tr>
264+
</table>
265+
*/
266+
public Variable internalOnlyGet() throws ApiException {
267+
ApiResponse<Variable> localVarResp = internalOnlyGetWithHttpInfo();
268+
return localVarResp.getData();
269+
}
270+
271+
/**
272+
* internal only
273+
*
274+
* @return ApiResponse&lt;Variable&gt;
275+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
276+
* @http.response.details
277+
<table summary="Response Details" border="1">
278+
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
279+
<tr><td> 200 </td><td> successful operation </td><td> - </td></tr>
280+
<tr><td> 400 </td><td> Invalid Value </td><td> - </td></tr>
281+
</table>
282+
*/
283+
public ApiResponse<Variable> internalOnlyGetWithHttpInfo() throws ApiException {
284+
okhttp3.Call localVarCall = internalOnlyGetValidateBeforeCall(null);
285+
Type localVarReturnType = new TypeToken<Variable>(){}.getType();
286+
return localVarApiClient.execute(localVarCall, localVarReturnType);
287+
}
288+
289+
/**
290+
* internal only (asynchronously)
291+
*
292+
* @param _callback The callback to be executed when the API call finishes
293+
* @return The request call
294+
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
295+
* @http.response.details
296+
<table summary="Response Details" border="1">
297+
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
298+
<tr><td> 200 </td><td> successful operation </td><td> - </td></tr>
299+
<tr><td> 400 </td><td> Invalid Value </td><td> - </td></tr>
300+
</table>
301+
*/
302+
public okhttp3.Call internalOnlyGetAsync(final ApiCallback<Variable> _callback) throws ApiException {
303+
304+
okhttp3.Call localVarCall = internalOnlyGetValidateBeforeCall(_callback);
305+
Type localVarReturnType = new TypeToken<Variable>(){}.getType();
306+
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
307+
return localVarCall;
308+
}
192309
}

0 commit comments

Comments
 (0)