add operation id option (#17750)

This commit is contained in:
William Cheng 2024-02-01 17:21:49 +08:00 committed by GitHub
parent 2129b15c8f
commit 7c7634dda9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 449 additions and 278 deletions

View File

@ -17,3 +17,6 @@ additionalProperties:
enumNameMappings:
s: LOWER_CASE_S
S: UPPER_CASE_S
operationIdNameMappings:
getArrayOfEnums: getFakeArrayofenums
fakeHealthGet: getFakeHealth

View File

@ -436,6 +436,13 @@ Not all generators support thess features yet. Please give it a try to confirm t
NOTE: some generators use `baseName` (original name obtained direclty from OpenAPI spec, e.g. `shipping-date`) mustache tag in the templates so the mapping feature won't work.
To map `operationId` (used in method naming) to something else, use `operationIdNameMappings` option, e.g.
```sh
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o /tmp/java/ --operation-id-name-mappings getPetById=returnPetById
```
will name the API method as `returnPetById` instead of `getPetById` obtained from OpenAPI doc/spec.
## Schema Mapping
One can map the schema to something else (e.g. external objects/models outside of the package) using the `schemaMappings` option, e.g. in CLI

View File

@ -92,6 +92,9 @@ public class ConfigHelp extends OpenApiGeneratorCommand {
@Option(name = {"--enum-name-mappings"}, title = "enum name mappings", description = "displays the enum name mappings (none)")
private Boolean enumNameMappings;
@Option(name = {"--operation-id-name-mappings"}, title = "operation id name mappings", description = "displays the operation id name mappings (none)")
private Boolean operationIdNameMappings;
@Option(name = {"--openapi-normalizer"}, title = "openapi normalizer rules", description = "displays the OpenAPI normalizer rules (none)")
private Boolean openapiNormalizer;
@ -560,6 +563,18 @@ public class ConfigHelp extends OpenApiGeneratorCommand {
sb.append(newline);
}
if (Boolean.TRUE.equals(operationIdNameMappings)) {
sb.append(newline).append("OPERATION ID MAPPING").append(newline).append(newline);
Map<String, String> map = config.operationIdNameMapping()
.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> {
throw new IllegalStateException(String.format(Locale.ROOT, "Duplicated options! %s and %s", a, b));
}, TreeMap::new));
writePlainTextFromMap(sb, map, optIndent, optNestedIndent, "operation id name", "Mapped to");
sb.append(newline);
}
if (Boolean.TRUE.equals(openapiNormalizer)) {
sb.append(newline).append("OPENAPI NORMALIZER RULES").append(newline).append(newline);
Map<String, String> map = config.openapiNormalizer()

View File

@ -223,6 +223,13 @@ public class Generate extends OpenApiGeneratorCommand {
+ " You can also have multiple occurrences of this option.")
private List<String> enumNameMappings = new ArrayList<>();
@Option(
name = {"--operation-id-name-mappings"},
title = "operation id name mappings",
description = "specifies mappings between the operation id name and the new name in the format of operation_id_name=AnotherName,operation_id_name2=OtherName2."
+ " You can also have multiple occurrences of this option.")
private List<String> operationIdNameMappings = new ArrayList<>();
@Option(
name = {"--openapi-normalizer"},
title = "OpenAPI normalizer rules",
@ -507,6 +514,7 @@ public class Generate extends OpenApiGeneratorCommand {
applyParameterNameMappingsKvpList(parameterNameMappings, configurator);
applyModelNameMappingsKvpList(modelNameMappings, configurator);
applyEnumNameMappingsKvpList(enumNameMappings, configurator);
applyOperationIdNameMappingsKvpList(operationIdNameMappings, configurator);
applyOpenAPINormalizerKvpList(openapiNormalizer, configurator);
applyTypeMappingsKvpList(typeMappings, configurator);
applyAdditionalPropertiesKvpList(additionalProperties, configurator);

View File

@ -57,6 +57,7 @@ public final class GeneratorSettings implements Serializable {
private final Map<String, String> parameterNameMappings;
private final Map<String, String> modelNameMappings;
private final Map<String, String> enumNameMappings;
private final Map<String, String> operationIdNameMappings;
private final Map<String, String> openapiNormalizer;
private final Set<String> languageSpecificPrimitives;
private final Set<String> openapiGeneratorIgnoreList;
@ -306,6 +307,15 @@ public final class GeneratorSettings implements Serializable {
return enumNameMappings;
}
/**
* Gets operation id name mappings between an operation id name and the new name.
*
* @return the operation id name mappings
*/
public Map<String, String> getOperationIdNameMappings() {
return operationIdNameMappings;
}
/**
* Gets OpenAPI normalizer rules
*
@ -446,6 +456,7 @@ public final class GeneratorSettings implements Serializable {
parameterNameMappings = Collections.unmodifiableMap(builder.parameterNameMappings);
modelNameMappings = Collections.unmodifiableMap(builder.modelNameMappings);
enumNameMappings = Collections.unmodifiableMap(builder.enumNameMappings);
operationIdNameMappings = Collections.unmodifiableMap(builder.operationIdNameMappings);
openapiNormalizer = Collections.unmodifiableMap(builder.openapiNormalizer);
languageSpecificPrimitives = Collections.unmodifiableSet(builder.languageSpecificPrimitives);
openapiGeneratorIgnoreList = Collections.unmodifiableSet(builder.openapiGeneratorIgnoreList);
@ -525,6 +536,7 @@ public final class GeneratorSettings implements Serializable {
parameterNameMappings = Collections.unmodifiableMap(new HashMap<>(0));
modelNameMappings = Collections.unmodifiableMap(new HashMap<>(0));
enumNameMappings = Collections.unmodifiableMap(new HashMap<>(0));
operationIdNameMappings = Collections.unmodifiableMap(new HashMap<>(0));
openapiNormalizer = Collections.unmodifiableMap(new HashMap<>(0));
languageSpecificPrimitives = Collections.unmodifiableSet(new HashSet<>(0));
openapiGeneratorIgnoreList = Collections.unmodifiableSet(new HashSet<>(0));
@ -599,6 +611,9 @@ public final class GeneratorSettings implements Serializable {
if (copy.getEnumNameMappings() != null) {
builder.enumNameMappings.putAll(copy.getEnumNameMappings());
}
if (copy.getOperationIdNameMappings() != null) {
builder.operationIdNameMappings.putAll(copy.getOperationIdNameMappings());
}
if (copy.getOpenAPINormalizer() != null) {
builder.openapiNormalizer.putAll(copy.getOpenAPINormalizer());
}
@ -651,6 +666,7 @@ public final class GeneratorSettings implements Serializable {
private Map<String, String> parameterNameMappings;
private Map<String, String> modelNameMappings;
private Map<String, String> enumNameMappings;
private Map<String, String> operationIdNameMappings;
private Map<String, String> openapiNormalizer;
private Set<String> languageSpecificPrimitives;
private Set<String> openapiGeneratorIgnoreList;
@ -677,6 +693,7 @@ public final class GeneratorSettings implements Serializable {
parameterNameMappings = new HashMap<>();
modelNameMappings = new HashMap<>();
enumNameMappings = new HashMap<>();
operationIdNameMappings = new HashMap<>();
openapiNormalizer = new HashMap<>();
languageSpecificPrimitives = new HashSet<>();
openapiGeneratorIgnoreList = new HashSet<>();
@ -1103,6 +1120,32 @@ public final class GeneratorSettings implements Serializable {
return this;
}
/**
* Sets the {@code operationIdNameMappings} and returns a reference to this Builder so that the methods can be chained together.
*
* @param operationIdNameMappings the {@code operationIdNameMappings} to set
* @return a reference to this Builder
*/
public Builder withOperationIdNameMappings(Map<String, String> operationIdNameMappings) {
this.operationIdNameMappings = operationIdNameMappings;
return this;
}
/**
* Sets a single {@code operationIdNameMappings} and returns a reference to this Builder so that the methods can be chained together.
*
* @param key A key for the name mapping
* @param value The value of name mapping
* @return a reference to this Builder
*/
public Builder withOperationIdNameMapping(String key, String value) {
if (this.operationIdNameMappings == null) {
this.operationIdNameMappings = new HashMap<>();
}
this.operationIdNameMappings.put(key, value);
return this;
}
/**
* Sets the {@code openapiNormalizer} and returns a reference to this Builder so that the methods can be chained together.
*
@ -1346,6 +1389,7 @@ public final class GeneratorSettings implements Serializable {
Objects.equals(getParameterNameMappings(), that.getParameterNameMappings()) &&
Objects.equals(getModelNameMappings(), that.getModelNameMappings()) &&
Objects.equals(getEnumNameMappings(), that.getEnumNameMappings()) &&
Objects.equals(getOperationIdNameMappings(), that.getOperationIdNameMappings()) &&
Objects.equals(getOpenAPINormalizer(), that.getOpenAPINormalizer()) &&
Objects.equals(getLanguageSpecificPrimitives(), that.getLanguageSpecificPrimitives()) &&
Objects.equals(getOpenAPIGeneratorIgnoreList(), that.getOpenAPIGeneratorIgnoreList()) &&
@ -1383,6 +1427,7 @@ public final class GeneratorSettings implements Serializable {
getParameterNameMappings(),
getModelNameMappings(),
getEnumNameMappings(),
getOperationIdNameMappings(),
getOpenAPINormalizer(),
getLanguageSpecificPrimitives(),
getOpenAPIGeneratorIgnoreList(),

View File

@ -192,6 +192,11 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
*/
val enumNameMappings = project.objects.mapProperty<String, String>()
/**
* Specifies mappings between an operation id name and the new name
*/
val operationIdNameMappings = project.objects.mapProperty<String, String>()
/**
* Specifies mappings (rules) in OpenAPI normalizer
*/

View File

@ -307,6 +307,13 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
@Input
val enumNameMappings = project.objects.mapProperty<String, String>()
/**
* Specifies mappings between the operation id name and the new name
*/
@Optional
@Input
val operationIdNameMappings = project.objects.mapProperty<String, String>()
/**
* Specifies mappings (rules) in OpenAPI normalizer
*/
@ -872,6 +879,12 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
}
}
if (operationIdNameMappings.isPresent) {
operationIdNameMappings.get().forEach { entry ->
configurator.addOperationIdNameMapping(entry.key, entry.value)
}
}
if (openapiNormalizer.isPresent) {
openapiNormalizer.get().forEach { entry ->
configurator.addOpenAPINormalizer(entry.key, entry.value)

View File

@ -356,6 +356,12 @@ public class CodeGenMojo extends AbstractMojo {
@Parameter(name = "enumNameMappings", property = "openapi.generator.maven.plugin.enumNameMappings")
private List<String> enumNameMappings;
/**
* A map of operation id names and the new names
*/
@Parameter(name = "operationIdNameMappings", property = "openapi.generator.maven.plugin.operationIdNameMappings")
private List<String> operationIdNameMappings;
/**
* A set of rules for OpenAPI normalizer
*/
@ -857,6 +863,11 @@ public class CodeGenMojo extends AbstractMojo {
applyEnumNameMappingsKvpList(enumNameMappings, configurator);
}
// Apply Operation ID Name Mappings
if (operationIdNameMappings != null && (configOptions == null || !configOptions.containsKey("operation-id-name-mappings"))) {
applyOperationIdNameMappingsKvpList(operationIdNameMappings, configurator);
}
// Apply OpenAPI normalizer rules
if (openapiNormalizer != null && (configOptions == null || !configOptions.containsKey("openapi-normalizer"))) {
applyOpenAPINormalizerKvpList(openapiNormalizer, configurator);

View File

@ -158,6 +158,8 @@ public interface CodegenConfig {
Map<String, String> enumNameMapping();
Map<String, String> operationIdNameMapping();
Map<String, String> openapiNormalizer();
Map<String, String> apiTemplateFiles();

View File

@ -177,6 +177,8 @@ public class DefaultCodegen implements CodegenConfig {
protected Map<String, String> modelNameMapping = new HashMap<>();
// a map to store the mapping between enum name and the name provided by the user
protected Map<String, String> enumNameMapping = new HashMap<>();
// a map to store the mapping between operation id name and the name provided by the user
protected Map<String, String> operationIdNameMapping = new HashMap<>();
// a map to store the rules in OpenAPI Normalizer
protected Map<String, String> openapiNormalizer = new HashMap<>();
protected String modelPackage = "", apiPackage = "", fileSuffix;
@ -1271,6 +1273,11 @@ public class DefaultCodegen implements CodegenConfig {
return enumNameMapping;
}
@Override
public Map<String, String> operationIdNameMapping() {
return operationIdNameMapping;
}
@Override
public Map<String, String> openapiNormalizer() {
return openapiNormalizer;
@ -4551,7 +4558,11 @@ public class DefaultCodegen implements CodegenConfig {
op.path = path;
}
op.operationId = toOperationId(operationId);
if (operationIdNameMapping.containsKey(operationId)) {
op.operationId = operationIdNameMapping.get(operationId);
} else {
op.operationId = toOperationId(operationId);
}
op.summary = escapeText(operation.getSummary());
op.unescapedNotes = operation.getDescription();
op.notes = escapeText(operation.getDescription());

View File

@ -75,6 +75,7 @@ public class CodegenConfigurator {
private Map<String, String> parameterNameMappings = new HashMap<>();
private Map<String, String> modelNameMappings = new HashMap<>();
private Map<String, String> enumNameMappings = new HashMap<>();
private Map<String, String> operationIdNameMappings = new HashMap<>();
private Map<String, String> openapiNormalizer = new HashMap<>();
private Set<String> languageSpecificPrimitives = new HashSet<>();
private Set<String> openapiGeneratorIgnoreList = new HashSet<>();
@ -141,6 +142,9 @@ public class CodegenConfigurator {
if(generatorSettings.getEnumNameMappings() != null) {
configurator.enumNameMappings.putAll(generatorSettings.getEnumNameMappings());
}
if(generatorSettings.getOperationIdNameMappings() != null) {
configurator.operationIdNameMappings.putAll(generatorSettings.getOperationIdNameMappings());
}
if(generatorSettings.getOpenAPINormalizer() != null) {
configurator.openapiNormalizer.putAll(generatorSettings.getOpenAPINormalizer());
}
@ -258,6 +262,12 @@ public class CodegenConfigurator {
return this;
}
public CodegenConfigurator addOperationIdNameMapping(String key, String value) {
this.operationIdNameMappings.put(key, value);
generatorSettingsBuilder.withOperationIdNameMapping(key, value);
return this;
}
public CodegenConfigurator addOpenAPINormalizer(String key, String value) {
this.openapiNormalizer.put(key, value);
generatorSettingsBuilder.withOpenAPINormalizer(key, value);
@ -466,6 +476,12 @@ public class CodegenConfigurator {
return this;
}
public CodegenConfigurator setOperationIdNameMappings(Map<String, String> operationIdNameMappings) {
this.operationIdNameMappings = operationIdNameMappings;
generatorSettingsBuilder.withOperationIdNameMappings(operationIdNameMappings);
return this;
}
public CodegenConfigurator setOpenAPINormalizer(Map<String, String> openapiNormalizer) {
this.openapiNormalizer = openapiNormalizer;
generatorSettingsBuilder.withOpenAPINormalizer(openapiNormalizer);
@ -762,6 +778,7 @@ public class CodegenConfigurator {
config.parameterNameMapping().putAll(generatorSettings.getParameterNameMappings());
config.modelNameMapping().putAll(generatorSettings.getModelNameMappings());
config.enumNameMapping().putAll(generatorSettings.getEnumNameMappings());
config.operationIdNameMapping().putAll(generatorSettings.getOperationIdNameMappings());
config.openapiNormalizer().putAll(generatorSettings.getOpenAPINormalizer());
config.languageSpecificPrimitives().addAll(generatorSettings.getLanguageSpecificPrimitives());
config.openapiGeneratorIgnoreList().addAll(generatorSettings.getOpenAPIGeneratorIgnoreList());

View File

@ -172,6 +172,19 @@ public final class CodegenConfiguratorUtils {
}
}
public static void applyOperationIdNameMappingsKvpList(List<String> operationIdNameMappings, CodegenConfigurator configurator) {
for (String propString : operationIdNameMappings) {
applyOperationIdNameMappingsKvp(propString, configurator);
}
}
public static void applyOperationIdNameMappingsKvp(String operationIdNameMappings, CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(operationIdNameMappings);
for (Map.Entry<String, String> entry : map.entrySet()) {
configurator.addOperationIdNameMapping(entry.getKey().trim(), entry.getValue().trim());
}
}
public static void applyOpenAPINormalizerKvpList(List<String> openapiNormalizer, CodegenConfigurator configurator) {
for (String propString : openapiNormalizer) {
applyOpenAPINormalizerKvp(propString, configurator);

View File

@ -118,12 +118,12 @@ Class | Method | HTTP request | Description
*AnotherFakeApi* | [**getParameterStringNumber**](docs/AnotherFakeApi.md#getParameterStringNumber) | **GET** /fake/parameter-string-number | parameter string number
*AnotherFakeApi* | [**nullRequestBody**](docs/AnotherFakeApi.md#nullRequestBody) | **GET** /fake/null-request-body | null request body
*DefaultApi* | [**fooGet**](docs/DefaultApi.md#fooGet) | **GET** /foo |
*FakeApi* | [**fakeHealthGet**](docs/FakeApi.md#fakeHealthGet) | **GET** /fake/health | Health check endpoint
*FakeApi* | [**fakeOuterBooleanSerialize**](docs/FakeApi.md#fakeOuterBooleanSerialize) | **POST** /fake/outer/boolean |
*FakeApi* | [**fakeOuterCompositeSerialize**](docs/FakeApi.md#fakeOuterCompositeSerialize) | **POST** /fake/outer/composite |
*FakeApi* | [**fakeOuterNumberSerialize**](docs/FakeApi.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number |
*FakeApi* | [**fakeOuterStringSerialize**](docs/FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string |
*FakeApi* | [**getArrayOfEnums**](docs/FakeApi.md#getArrayOfEnums) | **GET** /fake/array-of-enums | Array of Enums
*FakeApi* | [**getFakeArrayofenums**](docs/FakeApi.md#getFakeArrayofenums) | **GET** /fake/array-of-enums | Array of Enums
*FakeApi* | [**getFakeHealth**](docs/FakeApi.md#getFakeHealth) | **GET** /fake/health | Health check endpoint
*FakeApi* | [**getParameterNameMapping**](docs/FakeApi.md#getParameterNameMapping) | **GET** /fake/parameter-name-mapping | parameter name mapping test
*FakeApi* | [**testAdditionalPropertiesReference**](docs/FakeApi.md#testAdditionalPropertiesReference) | **POST** /fake/additionalProperties-reference | test referenced additionalProperties
*FakeApi* | [**testBodyWithFileSchema**](docs/FakeApi.md#testBodyWithFileSchema) | **PUT** /fake/body-with-file-schema |

View File

@ -4,12 +4,12 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
| Method | HTTP request | Description |
|------------- | ------------- | -------------|
| [**fakeHealthGet**](FakeApi.md#fakeHealthGet) | **GET** /fake/health | Health check endpoint |
| [**fakeOuterBooleanSerialize**](FakeApi.md#fakeOuterBooleanSerialize) | **POST** /fake/outer/boolean | |
| [**fakeOuterCompositeSerialize**](FakeApi.md#fakeOuterCompositeSerialize) | **POST** /fake/outer/composite | |
| [**fakeOuterNumberSerialize**](FakeApi.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number | |
| [**fakeOuterStringSerialize**](FakeApi.md#fakeOuterStringSerialize) | **POST** /fake/outer/string | |
| [**getArrayOfEnums**](FakeApi.md#getArrayOfEnums) | **GET** /fake/array-of-enums | Array of Enums |
| [**getFakeArrayofenums**](FakeApi.md#getFakeArrayofenums) | **GET** /fake/array-of-enums | Array of Enums |
| [**getFakeHealth**](FakeApi.md#getFakeHealth) | **GET** /fake/health | Health check endpoint |
| [**getParameterNameMapping**](FakeApi.md#getParameterNameMapping) | **GET** /fake/parameter-name-mapping | parameter name mapping test |
| [**testAdditionalPropertiesReference**](FakeApi.md#testAdditionalPropertiesReference) | **POST** /fake/additionalProperties-reference | test referenced additionalProperties |
| [**testBodyWithFileSchema**](FakeApi.md#testBodyWithFileSchema) | **PUT** /fake/body-with-file-schema | |
@ -25,62 +25,6 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
| [**testStringMapReference**](FakeApi.md#testStringMapReference) | **POST** /fake/stringMap-reference | test referenced string map |
<a id="fakeHealthGet"></a>
# **fakeHealthGet**
> HealthCheckResult fakeHealthGet()
Health check endpoint
### 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:80/v2");
FakeApi apiInstance = new FakeApi(defaultClient);
try {
HealthCheckResult result = apiInstance.fakeHealthGet();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#fakeHealthGet");
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
[**HealthCheckResult**](HealthCheckResult.md)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/json
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | The instance started successfully | - |
<a id="fakeOuterBooleanSerialize"></a>
# **fakeOuterBooleanSerialize**
> Boolean fakeOuterBooleanSerialize(body)
@ -329,9 +273,9 @@ No authorization required
|-------------|-------------|------------------|
| **200** | Output string | - |
<a id="getArrayOfEnums"></a>
# **getArrayOfEnums**
> List&lt;OuterEnum&gt; getArrayOfEnums()
<a id="getFakeArrayofenums"></a>
# **getFakeArrayofenums**
> List&lt;OuterEnum&gt; getFakeArrayofenums()
Array of Enums
@ -351,10 +295,10 @@ public class Example {
FakeApi apiInstance = new FakeApi(defaultClient);
try {
List<OuterEnum> result = apiInstance.getArrayOfEnums();
List<OuterEnum> result = apiInstance.getFakeArrayofenums();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#getArrayOfEnums");
System.err.println("Exception when calling FakeApi#getFakeArrayofenums");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
@ -385,6 +329,62 @@ No authorization required
|-------------|-------------|------------------|
| **200** | Got named array of enums | - |
<a id="getFakeHealth"></a>
# **getFakeHealth**
> HealthCheckResult getFakeHealth()
Health check endpoint
### 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:80/v2");
FakeApi apiInstance = new FakeApi(defaultClient);
try {
HealthCheckResult result = apiInstance.getFakeHealth();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#getFakeHealth");
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
[**HealthCheckResult**](HealthCheckResult.md)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/json
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | The instance started successfully | - |
<a id="getParameterNameMapping"></a>
# **getParameterNameMapping**
> getParameterNameMapping(underscoreType, type, typeWithUnderscore)

View File

@ -82,119 +82,6 @@ public class FakeApi {
this.localCustomBaseUrl = customBaseUrl;
}
/**
* Build call for fakeHealthGet
* @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> The instance started successfully </td><td> - </td></tr>
</table>
*/
public okhttp3.Call fakeHealthGetCall(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 = "/fake/health";
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 fakeHealthGetValidateBeforeCall(final ApiCallback _callback) throws ApiException {
return fakeHealthGetCall(_callback);
}
/**
* Health check endpoint
*
* @return HealthCheckResult
* @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> The instance started successfully </td><td> - </td></tr>
</table>
*/
public HealthCheckResult fakeHealthGet() throws ApiException {
ApiResponse<HealthCheckResult> localVarResp = fakeHealthGetWithHttpInfo();
return localVarResp.getData();
}
/**
* Health check endpoint
*
* @return ApiResponse&lt;HealthCheckResult&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> The instance started successfully </td><td> - </td></tr>
</table>
*/
public ApiResponse<HealthCheckResult> fakeHealthGetWithHttpInfo() throws ApiException {
okhttp3.Call localVarCall = fakeHealthGetValidateBeforeCall(null);
Type localVarReturnType = new TypeToken<HealthCheckResult>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}
/**
* Health check endpoint (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> The instance started successfully </td><td> - </td></tr>
</table>
*/
public okhttp3.Call fakeHealthGetAsync(final ApiCallback<HealthCheckResult> _callback) throws ApiException {
okhttp3.Call localVarCall = fakeHealthGetValidateBeforeCall(_callback);
Type localVarReturnType = new TypeToken<HealthCheckResult>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
/**
* Build call for fakeOuterBooleanSerialize
* @param body Input boolean as post body (optional)
@ -668,7 +555,7 @@ public class FakeApi {
return localVarCall;
}
/**
* Build call for getArrayOfEnums
* Build call for getFakeArrayofenums
* @param _callback Callback for upload/download progress
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
@ -678,7 +565,7 @@ public class FakeApi {
<tr><td> 200 </td><td> Got named array of enums </td><td> - </td></tr>
</table>
*/
public okhttp3.Call getArrayOfEnumsCall(final ApiCallback _callback) throws ApiException {
public okhttp3.Call getFakeArrayofenumsCall(final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
@ -723,8 +610,8 @@ public class FakeApi {
}
@SuppressWarnings("rawtypes")
private okhttp3.Call getArrayOfEnumsValidateBeforeCall(final ApiCallback _callback) throws ApiException {
return getArrayOfEnumsCall(_callback);
private okhttp3.Call getFakeArrayofenumsValidateBeforeCall(final ApiCallback _callback) throws ApiException {
return getFakeArrayofenumsCall(_callback);
}
@ -739,8 +626,8 @@ public class FakeApi {
<tr><td> 200 </td><td> Got named array of enums </td><td> - </td></tr>
</table>
*/
public List<OuterEnum> getArrayOfEnums() throws ApiException {
ApiResponse<List<OuterEnum>> localVarResp = getArrayOfEnumsWithHttpInfo();
public List<OuterEnum> getFakeArrayofenums() throws ApiException {
ApiResponse<List<OuterEnum>> localVarResp = getFakeArrayofenumsWithHttpInfo();
return localVarResp.getData();
}
@ -755,8 +642,8 @@ public class FakeApi {
<tr><td> 200 </td><td> Got named array of enums </td><td> - </td></tr>
</table>
*/
public ApiResponse<List<OuterEnum>> getArrayOfEnumsWithHttpInfo() throws ApiException {
okhttp3.Call localVarCall = getArrayOfEnumsValidateBeforeCall(null);
public ApiResponse<List<OuterEnum>> getFakeArrayofenumsWithHttpInfo() throws ApiException {
okhttp3.Call localVarCall = getFakeArrayofenumsValidateBeforeCall(null);
Type localVarReturnType = new TypeToken<List<OuterEnum>>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}
@ -773,13 +660,126 @@ public class FakeApi {
<tr><td> 200 </td><td> Got named array of enums </td><td> - </td></tr>
</table>
*/
public okhttp3.Call getArrayOfEnumsAsync(final ApiCallback<List<OuterEnum>> _callback) throws ApiException {
public okhttp3.Call getFakeArrayofenumsAsync(final ApiCallback<List<OuterEnum>> _callback) throws ApiException {
okhttp3.Call localVarCall = getArrayOfEnumsValidateBeforeCall(_callback);
okhttp3.Call localVarCall = getFakeArrayofenumsValidateBeforeCall(_callback);
Type localVarReturnType = new TypeToken<List<OuterEnum>>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
/**
* Build call for getFakeHealth
* @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> The instance started successfully </td><td> - </td></tr>
</table>
*/
public okhttp3.Call getFakeHealthCall(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 = "/fake/health";
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 getFakeHealthValidateBeforeCall(final ApiCallback _callback) throws ApiException {
return getFakeHealthCall(_callback);
}
/**
* Health check endpoint
*
* @return HealthCheckResult
* @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> The instance started successfully </td><td> - </td></tr>
</table>
*/
public HealthCheckResult getFakeHealth() throws ApiException {
ApiResponse<HealthCheckResult> localVarResp = getFakeHealthWithHttpInfo();
return localVarResp.getData();
}
/**
* Health check endpoint
*
* @return ApiResponse&lt;HealthCheckResult&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> The instance started successfully </td><td> - </td></tr>
</table>
*/
public ApiResponse<HealthCheckResult> getFakeHealthWithHttpInfo() throws ApiException {
okhttp3.Call localVarCall = getFakeHealthValidateBeforeCall(null);
Type localVarReturnType = new TypeToken<HealthCheckResult>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}
/**
* Health check endpoint (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> The instance started successfully </td><td> - </td></tr>
</table>
*/
public okhttp3.Call getFakeHealthAsync(final ApiCallback<HealthCheckResult> _callback) throws ApiException {
okhttp3.Call localVarCall = getFakeHealthValidateBeforeCall(_callback);
Type localVarReturnType = new TypeToken<HealthCheckResult>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
/**
* Build call for getParameterNameMapping
* @param underscoreType _type (required)

View File

@ -23,9 +23,10 @@ import java.time.LocalDate;
import java.time.OffsetDateTime;
import org.openapitools.client.model.OuterComposite;
import org.openapitools.client.model.OuterEnum;
import org.openapitools.client.model.TestInlineFreeformAdditionalPropertiesRequest;
import org.openapitools.client.model.User;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;
@ -40,148 +41,147 @@ public class FakeApiTest {
private final FakeApi api = new FakeApi();
/**
* Health check endpoint
*
*
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void fakeHealthGetTest() throws ApiException {
HealthCheckResult response = api.fakeHealthGet();
// TODO: test validations
}
/**
*
*
* Test serialization of outer boolean types
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void fakeOuterBooleanSerializeTest() throws ApiException {
Boolean body = null;
Boolean response = api.fakeOuterBooleanSerialize(body);
Boolean response = api.fakeOuterBooleanSerialize(body);
// TODO: test validations
}
/**
*
*
* Test serialization of object with outer number type
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void fakeOuterCompositeSerializeTest() throws ApiException {
OuterComposite outerComposite = null;
OuterComposite response = api.fakeOuterCompositeSerialize(outerComposite);
OuterComposite response = api.fakeOuterCompositeSerialize(outerComposite);
// TODO: test validations
}
/**
*
*
* Test serialization of outer number types
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void fakeOuterNumberSerializeTest() throws ApiException {
BigDecimal body = null;
BigDecimal response = api.fakeOuterNumberSerialize(body);
BigDecimal response = api.fakeOuterNumberSerialize(body);
// TODO: test validations
}
/**
*
*
* Test serialization of outer string types
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void fakeOuterStringSerializeTest() throws ApiException {
String body = null;
String response = api.fakeOuterStringSerialize(body);
String response = api.fakeOuterStringSerialize(body);
// TODO: test validations
}
/**
* Array of Enums
*
*
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void getArrayOfEnumsTest() throws ApiException {
List<OuterEnum> response = api.getArrayOfEnums();
public void getFakeArrayofenumsTest() throws ApiException {
List<OuterEnum> response = api.getFakeArrayofenums();
// TODO: test validations
}
/**
* Health check endpoint
*
* @throws ApiException if the Api call fails
*/
@Test
public void getFakeHealthTest() throws ApiException {
HealthCheckResult response = api.getFakeHealth();
// TODO: test validations
}
/**
* parameter name mapping test
*
* @throws ApiException if the Api call fails
*/
@Test
public void getParameterNameMappingTest() throws ApiException {
Long underscoreType = null;
String type = null;
String typeWithUnderscore = null;
api.getParameterNameMapping(underscoreType, type, typeWithUnderscore);
// TODO: test validations
}
/**
* test referenced additionalProperties
*
*
*
* @throws ApiException if the Api call fails
*/
@Test
public void testAdditionalPropertiesReferenceTest() throws ApiException {
Map<String, Object> requestBody = null;
api.testAdditionalPropertiesReference(requestBody);
// TODO: test validations
}
/**
* For this test, the body for this request much reference a schema named &#x60;File&#x60;.
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void testBodyWithFileSchemaTest() throws ApiException {
FileSchemaTestClass fileSchemaTestClass = null;
api.testBodyWithFileSchema(fileSchemaTestClass);
api.testBodyWithFileSchema(fileSchemaTestClass);
// TODO: test validations
}
/**
*
*
*
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void testBodyWithQueryParamsTest() throws ApiException {
String query = null;
User user = null;
api.testBodyWithQueryParams(query, user);
api.testBodyWithQueryParams(query, user);
// TODO: test validations
}
/**
* To test \&quot;client\&quot; model
*
* To test \&quot;client\&quot; model
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void testClientModelTest() throws ApiException {
Client client = null;
Client response = api.testClientModel(client);
Client response = api.testClientModel(client);
// TODO: test validations
}
/**
* Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
*
* Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void testEndpointParametersTest() throws ApiException {
@ -199,17 +199,16 @@ public class FakeApiTest {
OffsetDateTime dateTime = null;
String password = null;
String paramCallback = null;
api.testEndpointParameters(number, _double, patternWithoutDelimiter, _byte, integer, int32, int64, _float, string, binary, date, dateTime, password, paramCallback);
api.testEndpointParameters(number, _double, patternWithoutDelimiter, _byte, integer, int32, int64, _float, string, binary, date, dateTime, password, paramCallback);
// TODO: test validations
}
/**
* To test enum parameters
*
* To test enum parameters
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void testEnumParametersTest() throws ApiException {
@ -221,17 +220,16 @@ public class FakeApiTest {
Double enumQueryDouble = null;
List<String> enumFormStringArray = null;
String enumFormString = null;
api.testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumFormStringArray, enumFormString);
api.testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumFormStringArray, enumFormString);
// TODO: test validations
}
/**
* Fake endpoint to test group parameters (optional)
*
* Fake endpoint to test group parameters (optional)
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void testGroupParametersTest() throws ApiException {
@ -241,52 +239,61 @@ public class FakeApiTest {
Integer stringGroup = null;
Boolean booleanGroup = null;
Long int64Group = null;
api.testGroupParameters(requiredStringGroup, requiredBooleanGroup, requiredInt64Group)
api.testGroupParameters(requiredStringGroup, requiredBooleanGroup, requiredInt64Group)
.stringGroup(stringGroup)
.booleanGroup(booleanGroup)
.int64Group(int64Group)
.execute();
// TODO: test validations
}
/**
* test inline additionalProperties
*
*
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void testInlineAdditionalPropertiesTest() throws ApiException {
Map<String, String> requestBody = null;
api.testInlineAdditionalProperties(requestBody);
api.testInlineAdditionalProperties(requestBody);
// TODO: test validations
}
/**
* test inline free-form additionalProperties
*
*
*
* @throws ApiException if the Api call fails
*/
@Test
public void testInlineFreeformAdditionalPropertiesTest() throws ApiException {
TestInlineFreeformAdditionalPropertiesRequest testInlineFreeformAdditionalPropertiesRequest = null;
api.testInlineFreeformAdditionalProperties(testInlineFreeformAdditionalPropertiesRequest);
// TODO: test validations
}
/**
* test json serialization of form data
*
*
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void testJsonFormDataTest() throws ApiException {
String param = null;
String param2 = null;
api.testJsonFormData(param, param2);
api.testJsonFormData(param, param2);
// TODO: test validations
}
/**
*
*
* To test the collection format in query parameters
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void testQueryParameterCollectionFormatTest() throws ApiException {
@ -295,8 +302,22 @@ public class FakeApiTest {
List<String> http = null;
List<String> url = null;
List<String> context = null;
api.testQueryParameterCollectionFormat(pipe, ioutil, http, url, context);
api.testQueryParameterCollectionFormat(pipe, ioutil, http, url, context);
// TODO: test validations
}
/**
* test referenced string map
*
*
*
* @throws ApiException if the Api call fails
*/
@Test
public void testStringMapReferenceTest() throws ApiException {
Map<String, String> requestBody = null;
api.testStringMapReference(requestBody);
// TODO: test validations
}
}