diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 0eb4fa5c55d5..9dd9df65b4bc 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -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 schemas = ModelUtils.getSchemas(this.openAPI); CodegenOperation op = CodegenModelFactory.newInstance(CodegenModelType.OPERATION); Set imports = new HashSet<>(); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java index 6af7f8cfb430..b4ae0a7842f1 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java @@ -508,7 +508,10 @@ void generateModels(List files, List allModels, List 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; diff --git a/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml b/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml index 0fcc9905aae3..b2eb6c526368 100644 --- a/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml @@ -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 @@ -2490,6 +2506,7 @@ components: - pending - sold PropertyNameCollision: + x-internal: false type: object properties: _type: @@ -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" diff --git a/samples/client/petstore/java/okhttp-gson/README.md b/samples/client/petstore/java/okhttp-gson/README.md index 999fe54e5946..cbe0318b9611 100644 --- a/samples/client/petstore/java/okhttp-gson/README.md +++ b/samples/client/petstore/java/okhttp-gson/README.md @@ -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 diff --git a/samples/client/petstore/java/okhttp-gson/api/openapi.yaml b/samples/client/petstore/java/okhttp-gson/api/openapi.yaml index 6479fd9a5473..13cdc72e3d36 100644 --- a/samples/client/petstore/java/okhttp-gson/api/openapi.yaml +++ b/samples/client/petstore/java/okhttp-gson/api/openapi.yaml @@ -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: @@ -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' diff --git a/samples/client/petstore/java/okhttp-gson/docs/ValuesApi.md b/samples/client/petstore/java/okhttp-gson/docs/ValuesApi.md index 4210bff03ec9..a607e93df06e 100644 --- a/samples/client/petstore/java/okhttp-gson/docs/ValuesApi.md +++ b/samples/client/petstore/java/okhttp-gson/docs/ValuesApi.md @@ -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 | @@ -66,3 +67,62 @@ No authorization required | **200** | successful operation | - | | **400** | Invalid Value | - | + +# **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 | - | + diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/api/ValuesApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/api/ValuesApi.java index 79fe043970d5..327ccfafe4c1 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/api/ValuesApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/api/ValuesApi.java @@ -189,4 +189,121 @@ public okhttp3.Call getSomeValuesAsync(final ApiCallback _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 + + + + +
Status Code Description Response Headers
200 successful operation -
400 Invalid Value -
+ */ + 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 localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); + Map localVarHeaderParams = new HashMap(); + Map localVarCookieParams = new HashMap(); + Map localVarFormParams = new HashMap(); + + 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 + + + + +
Status Code Description Response Headers
200 successful operation -
400 Invalid Value -
+ */ + public Variable internalOnlyGet() throws ApiException { + ApiResponse localVarResp = internalOnlyGetWithHttpInfo(); + return localVarResp.getData(); + } + + /** + * internal only + * + * @return ApiResponse<Variable> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + * @http.response.details + + + + +
Status Code Description Response Headers
200 successful operation -
400 Invalid Value -
+ */ + public ApiResponse internalOnlyGetWithHttpInfo() throws ApiException { + okhttp3.Call localVarCall = internalOnlyGetValidateBeforeCall(null); + Type localVarReturnType = new TypeToken(){}.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 + + + + +
Status Code Description Response Headers
200 successful operation -
400 Invalid Value -
+ */ + public okhttp3.Call internalOnlyGetAsync(final ApiCallback _callback) throws ApiException { + + okhttp3.Call localVarCall = internalOnlyGetValidateBeforeCall(_callback); + Type localVarReturnType = new TypeToken(){}.getType(); + localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback); + return localVarCall; + } }