Add model name mapping feature to C# codegen (#16209)

* add model name mapping feature to C# codegen

* rename file

* update samples

* update doc
This commit is contained in:
William Cheng 2023-08-02 10:06:11 +08:00 committed by GitHub
parent 3278eea9a4
commit 4602f18ca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 509 additions and 59 deletions

View File

@ -10,6 +10,9 @@ parameterNameMappings:
_type: UnderscoreType
type_: TypeWithUnderscore
http_debug_operation: HttpDebugOperation
modelNameMappings:
Environment: Env
additionalProperties:
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
hideGenerationTimestamp: "true"
targetFramework: net6.0

View File

@ -416,7 +416,16 @@ Here is an example to use `nameMappings` and `parameterNameMapping` in CLI:
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml -o /tmp/java2/ --name-mappings _type=underscoreType, type_=typeWithUnderscore, --parameter-name-mappings _type=paramType, type_=typeParam
```
(Not all generators support this feature yet. Please give it a try to confirm the behaviour and open an issue (ticket) to let us know which generators you would like to have this feature enabled and we'll prioritize accordingly.)
To map model names, use `modelNameMappings` option, e.g.
```sh
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g csharp -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o /tmp/csharp/ --model-name-mappings Tag=Label
```
will rename the Tag schema to Label instead.
(Not all generators support thess features yet. Please give it a try to confirm the behaviour and open an issue (ticket) to let us know which generators you would like to have this feature enabled and we'll prioritize accordingly.)
Related PRs: #16209 (modelNameMappings), #16194, #16206 (nameMappings, parameterNameMappings)
## Schema Mapping

View File

@ -86,6 +86,9 @@ public class ConfigHelp extends OpenApiGeneratorCommand {
@Option(name = {"--parameter-name-mappings"}, title = "parameter name mappings", description = "displays the parameter name mappings (none)")
private Boolean parameterNameMappings;
@Option(name = {"--model-name-mappings"}, title = "model name mappings", description = "displays the model name mappings (none)")
private Boolean modelNameMappings;
@Option(name = {"--openapi-normalizer"}, title = "openapi normalizer rules", description = "displays the OpenAPI normalizer rules (none)")
private Boolean openapiNormalizer;
@ -527,6 +530,18 @@ public class ConfigHelp extends OpenApiGeneratorCommand {
sb.append(newline);
}
if (Boolean.TRUE.equals(modelNameMappings)) {
sb.append(newline).append("MODEL NAME MAPPING").append(newline).append(newline);
Map<String, String> map = config.modelNameMapping()
.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, "model 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

@ -202,6 +202,13 @@ public class Generate extends OpenApiGeneratorCommand {
+ " You can also have multiple occurrences of this option.")
private List<String> parameterNameMappings = new ArrayList<>();
@Option(
name = {"--model-name-mappings"},
title = "model name mappings",
description = "specifies mappings between the model name and the new name in the format of model_name=AnotherName,model_name2=OtherName2."
+ " You can also have multiple occurrences of this option.")
private List<String> modelNameMappings = new ArrayList<>();
@Option(
name = {"--openapi-normalizer"},
title = "OpenAPI normalizer rules",
@ -484,6 +491,7 @@ public class Generate extends OpenApiGeneratorCommand {
applyInlineSchemaOptionsKvpList(inlineSchemaOptions, configurator);
applyNameMappingsKvpList(nameMappings, configurator);
applyParameterNameMappingsKvpList(parameterNameMappings, configurator);
applyModelNameMappingsKvpList(modelNameMappings, configurator);
applyOpenAPINormalizerKvpList(openapiNormalizer, configurator);
applyTypeMappingsKvpList(typeMappings, configurator);
applyAdditionalPropertiesKvpList(additionalProperties, configurator);

View File

@ -55,6 +55,7 @@ public final class GeneratorSettings implements Serializable {
private final Map<String, String> inlineSchemaOptions;
private final Map<String, String> nameMappings;
private final Map<String, String> parameterNameMappings;
private final Map<String, String> modelNameMappings;
private final Map<String, String> openapiNormalizer;
private final Set<String> languageSpecificPrimitives;
private final Map<String, String> reservedWordsMappings;
@ -285,6 +286,15 @@ public final class GeneratorSettings implements Serializable {
return parameterNameMappings;
}
/**
* Gets model name mappings between a model name and the new name.
*
* @return the model name mappings
*/
public Map<String, String> getModelNameMappings() {
return modelNameMappings;
}
/**
* Gets OpenAPI normalizer rules
*
@ -414,6 +424,7 @@ public final class GeneratorSettings implements Serializable {
inlineSchemaOptions = Collections.unmodifiableMap(builder.inlineSchemaOptions);
nameMappings = Collections.unmodifiableMap(builder.nameMappings);
parameterNameMappings = Collections.unmodifiableMap(builder.parameterNameMappings);
modelNameMappings = Collections.unmodifiableMap(builder.modelNameMappings);
openapiNormalizer = Collections.unmodifiableMap(builder.openapiNormalizer);
languageSpecificPrimitives = Collections.unmodifiableSet(builder.languageSpecificPrimitives);
reservedWordsMappings = Collections.unmodifiableMap(builder.reservedWordsMappings);
@ -490,6 +501,7 @@ public final class GeneratorSettings implements Serializable {
inlineSchemaOptions = Collections.unmodifiableMap(new HashMap<>(0));
nameMappings = Collections.unmodifiableMap(new HashMap<>(0));
parameterNameMappings = Collections.unmodifiableMap(new HashMap<>(0));
modelNameMappings = Collections.unmodifiableMap(new HashMap<>(0));
openapiNormalizer = Collections.unmodifiableMap(new HashMap<>(0));
languageSpecificPrimitives = Collections.unmodifiableSet(new HashSet<>(0));
reservedWordsMappings = Collections.unmodifiableMap(new HashMap<>(0));
@ -557,6 +569,9 @@ public final class GeneratorSettings implements Serializable {
if (copy.getParameterNameMappings() != null) {
builder.parameterNameMappings.putAll(copy.getParameterNameMappings());
}
if (copy.getModelNameMappings() != null) {
builder.modelNameMappings.putAll(copy.getModelNameMappings());
}
if (copy.getOpenAPINormalizer() != null) {
builder.openapiNormalizer.putAll(copy.getOpenAPINormalizer());
}
@ -604,6 +619,7 @@ public final class GeneratorSettings implements Serializable {
private Map<String, String> inlineSchemaOptions;
private Map<String, String> nameMappings;
private Map<String, String> parameterNameMappings;
private Map<String, String> modelNameMappings;
private Map<String, String> openapiNormalizer;
private Set<String> languageSpecificPrimitives;
private Map<String, String> reservedWordsMappings;
@ -627,6 +643,7 @@ public final class GeneratorSettings implements Serializable {
inlineSchemaOptions = new HashMap<>();
nameMappings = new HashMap<>();
parameterNameMappings = new HashMap<>();
modelNameMappings = new HashMap<>();
openapiNormalizer = new HashMap<>();
languageSpecificPrimitives = new HashSet<>();
reservedWordsMappings = new HashMap<>();
@ -1000,6 +1017,32 @@ public final class GeneratorSettings implements Serializable {
return this;
}
/**
* Sets the {@code modelNameMappings} and returns a reference to this Builder so that the methods can be chained together.
*
* @param modelNameMappings the {@code modelNameMappings} to set
* @return a reference to this Builder
*/
public Builder withModelNameMappings(Map<String, String> modelNameMappings) {
this.modelNameMappings = modelNameMappings;
return this;
}
/**
* Sets a single {@code modelNameMappings} 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 withModelNameMapping(String key, String value) {
if (this.modelNameMappings == null) {
this.modelNameMappings = new HashMap<>();
}
this.modelNameMappings.put(key, value);
return this;
}
/**
* Sets the {@code openapiNormalizer} and returns a reference to this Builder so that the methods can be chained together.
*
@ -1216,6 +1259,7 @@ public final class GeneratorSettings implements Serializable {
Objects.equals(getInlineSchemaOptions(), that.getInlineSchemaOptions()) &&
Objects.equals(getNameMappings(), that.getNameMappings()) &&
Objects.equals(getParameterNameMappings(), that.getParameterNameMappings()) &&
Objects.equals(getModelNameMappings(), that.getModelNameMappings()) &&
Objects.equals(getOpenAPINormalizer(), that.getOpenAPINormalizer()) &&
Objects.equals(getLanguageSpecificPrimitives(), that.getLanguageSpecificPrimitives()) &&
Objects.equals(getReservedWordsMappings(), that.getReservedWordsMappings()) &&
@ -1250,6 +1294,7 @@ public final class GeneratorSettings implements Serializable {
getInlineSchemaOptions(),
getNameMappings(),
getParameterNameMappings(),
getModelNameMappings(),
getOpenAPINormalizer(),
getLanguageSpecificPrimitives(),
getReservedWordsMappings(),

View File

@ -177,6 +177,11 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
*/
val parameterNameMappings = project.objects.mapProperty<String, String>()
/**
* Specifies mappings between a model name and the new name
*/
val modelNameMappings = project.objects.mapProperty<String, String>()
/**
* Specifies mappings (rules) in OpenAPI normalizer
*/

View File

@ -286,6 +286,13 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
@Input
val parameterNameMappings = project.objects.mapProperty<String, String>()
/**
* Specifies mappings between the model name and the new name
*/
@Optional
@Input
val modelNameMappings = project.objects.mapProperty<String, String>()
/**
* Specifies mappings (rules) in OpenAPI normalizer
*/
@ -833,6 +840,12 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
}
}
if (modelNameMappings.isPresent) {
modelNameMappings.get().forEach { entry ->
configurator.addModelNameMapping(entry.key, entry.value)
}
}
if (openapiNormalizer.isPresent) {
openapiNormalizer.get().forEach { entry ->
configurator.addOpenAPINormalizer(entry.key, entry.value)

View File

@ -344,6 +344,12 @@ public class CodeGenMojo extends AbstractMojo {
@Parameter(name = "parameterNameMappings", property = "openapi.generator.maven.plugin.parameterNameMappings")
private List<String> parameterNameMappings;
/**
* A map of model names and the new names
*/
@Parameter(name = "modelNameMappings", property = "openapi.generator.maven.plugin.modelNameMappings")
private List<String> modelNameMappings;
/**
* A set of rules for OpenAPI normalizer
*/
@ -823,6 +829,11 @@ public class CodeGenMojo extends AbstractMojo {
applyParameterNameMappingsKvpList(parameterNameMappings, configurator);
}
// Apply Model Name Mappings
if (modelNameMappings != null && (configOptions == null || !configOptions.containsKey("model-name-mappings"))) {
applyModelNameMappingsKvpList(modelNameMappings, configurator);
}
// Apply OpenAPI normalizer rules
if (openapiNormalizer != null && (configOptions == null || !configOptions.containsKey("openapi-normalizer"))) {
applyOpenAPINormalizerKvpList(openapiNormalizer, configurator);

View File

@ -151,6 +151,8 @@ public interface CodegenConfig {
Map<String, String> parameterNameMapping();
Map<String, String> modelNameMapping();
Map<String, String> openapiNormalizer();
Map<String, String> apiTemplateFiles();

View File

@ -168,6 +168,8 @@ public class DefaultCodegen implements CodegenConfig {
protected Map<String, String> nameMapping = new HashMap<>();
// a map to store the mapping between parameter name and the name provided by the user
protected Map<String, String> parameterNameMapping = new HashMap<>();
// a map to store the mapping between model name and the name provided by the user
protected Map<String, String> modelNameMapping = new HashMap<>();
// a map to store the rules in OpenAPI Normalizer
protected Map<String, String> openapiNormalizer = new HashMap<>();
protected String modelPackage = "", apiPackage = "", fileSuffix;
@ -1213,6 +1215,11 @@ public class DefaultCodegen implements CodegenConfig {
return parameterNameMapping;
}
@Override
public Map<String, String> modelNameMapping() {
return modelNameMapping;
}
@Override
public Map<String, String> openapiNormalizer() {
return openapiNormalizer;
@ -2616,6 +2623,11 @@ public class DefaultCodegen implements CodegenConfig {
*/
@Override
public String toModelName(final String name) {
// obtain the name from modelNameMapping directly if provided
if (modelNameMapping.containsKey(name)) {
return modelNameMapping.get(name);
}
if (schemaKeyToModelNameCache.containsKey(name)) {
return schemaKeyToModelNameCache.get(name);
}

View File

@ -73,6 +73,7 @@ public class CodegenConfigurator {
private Map<String, String> inlineSchemaOptions = new HashMap<>();
private Map<String, String> nameMappings = new HashMap<>();
private Map<String, String> parameterNameMappings = new HashMap<>();
private Map<String, String> modelNameMappings = new HashMap<>();
private Map<String, String> openapiNormalizer = new HashMap<>();
private Set<String> languageSpecificPrimitives = new HashSet<>();
private Map<String, String> reservedWordsMappings = new HashMap<>();
@ -132,6 +133,9 @@ public class CodegenConfigurator {
if(generatorSettings.getParameterNameMappings() != null) {
configurator.parameterNameMappings.putAll(generatorSettings.getParameterNameMappings());
}
if(generatorSettings.getModelNameMappings() != null) {
configurator.modelNameMappings.putAll(generatorSettings.getModelNameMappings());
}
if(generatorSettings.getOpenAPINormalizer() != null) {
configurator.openapiNormalizer.putAll(generatorSettings.getOpenAPINormalizer());
}
@ -234,6 +238,12 @@ public class CodegenConfigurator {
return this;
}
public CodegenConfigurator addModelNameMapping(String key, String value) {
this.modelNameMappings.put(key, value);
generatorSettingsBuilder.withModelNameMapping(key, value);
return this;
}
public CodegenConfigurator addOpenAPINormalizer(String key, String value) {
this.openapiNormalizer.put(key, value);
generatorSettingsBuilder.withOpenAPINormalizer(key, value);
@ -424,6 +434,12 @@ public class CodegenConfigurator {
return this;
}
public CodegenConfigurator setModelNameMappings(Map<String, String> modelNameMappings) {
this.modelNameMappings = modelNameMappings;
generatorSettingsBuilder.withModelNameMappings(modelNameMappings);
return this;
}
public CodegenConfigurator setOpenAPINormalizer(Map<String, String> openapiNormalizer) {
this.openapiNormalizer = openapiNormalizer;
generatorSettingsBuilder.withOpenAPINormalizer(openapiNormalizer);
@ -711,6 +727,7 @@ public class CodegenConfigurator {
config.inlineSchemaOption().putAll(generatorSettings.getInlineSchemaOptions());
config.nameMapping().putAll(generatorSettings.getNameMappings());
config.parameterNameMapping().putAll(generatorSettings.getParameterNameMappings());
config.modelNameMapping().putAll(generatorSettings.getModelNameMappings());
config.openapiNormalizer().putAll(generatorSettings.getOpenAPINormalizer());
config.languageSpecificPrimitives().addAll(generatorSettings.getLanguageSpecificPrimitives());
config.reservedWordsMappings().putAll(generatorSettings.getReservedWordsMappings());

View File

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

View File

@ -521,10 +521,10 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
// GrandparentAnimal has a discriminator, but no oneOf nor anyOf
// modules\openapi-generator\src\test\resources\3_0\csharp\petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
model.setHasDiscriminatorWithNonEmptyMapping(
((model.anyOf != null && model.anyOf.size() > 0) || (model.anyOf != null &&model.oneOf.size() > 0)) &&
model.discriminator != null &&
model.discriminator.getMappedModels() != null &&
model.discriminator.getMappedModels().size() > 0);
((model.anyOf != null && model.anyOf.size() > 0) || (model.anyOf != null && model.oneOf.size() > 0)) &&
model.discriminator != null &&
model.discriminator.getMappedModels() != null &&
model.discriminator.getMappedModels().size() > 0);
if (model.isEnum) {
enumRefs.put(model.getClassname(), model);
@ -539,7 +539,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
if (composedSchemas != null) {
List<CodegenProperty> allOf = composedSchemas.getAllOf();
if (allOf != null) {
for(CodegenProperty property : allOf) {
for (CodegenProperty property : allOf) {
property.name = patchPropertyName(model, property.baseType);
patchPropertyVendorExtensinos(property);
}
@ -548,7 +548,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
List<CodegenProperty> anyOf = composedSchemas.getAnyOf();
if (anyOf != null) {
removePropertiesDeclaredInComposedTypes(objs, model, anyOf);
for(CodegenProperty property : anyOf) {
for (CodegenProperty property : anyOf) {
property.name = patchPropertyName(model, property.baseType);
property.isNullable = true;
patchPropertyVendorExtensinos(property);
@ -558,7 +558,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
List<CodegenProperty> oneOf = composedSchemas.getOneOf();
if (oneOf != null) {
removePropertiesDeclaredInComposedTypes(objs, model, oneOf);
for(CodegenProperty property : oneOf) {
for (CodegenProperty property : oneOf) {
property.name = patchPropertyName(model, property.baseType);
property.isNullable = true;
patchPropertyVendorExtensinos(property);
@ -598,10 +598,10 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
}
/**
* Returns true if the model contains any properties with a public setter
* If true, the model's constructor accessor should be made public to ensure end users
* can instantiate the object. If false, then the model is only ever given
* to us by the server, so we do not need a public constructor
* Returns true if the model contains any properties with a public setter
* If true, the model's constructor accessor should be made public to ensure end users
* can instantiate the object. If false, then the model is only ever given
* to us by the server, so we do not need a public constructor
*/
private boolean modelIsMutatable(CodegenModel model, Set<String> processed) {
if (processed == null) {
@ -850,14 +850,18 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
}
}
/** Returns the model related to the given parameter */
/**
* Returns the model related to the given parameter
*/
private CodegenModel getModelFromParameter(List<ModelMap> allModels, CodegenParameter parameter) {
return parameter.isModel
? allModels.stream().map(m -> m.getModel()).filter(m -> m.getClassname().equals(parameter.dataType)).findFirst().orElse(null)
: null;
? allModels.stream().map(m -> m.getModel()).filter(m -> m.getClassname().equals(parameter.dataType)).findFirst().orElse(null)
: null;
}
/** This is the same as patchVendorExtensionNullableValueType except it uses the deprecated getNullableTypes property */
/**
* This is the same as patchVendorExtensionNullableValueType except it uses the deprecated getNullableTypes property
*/
protected void patchVendorExtensionNullableValueTypeLegacy(CodegenParameter parameter) {
if (parameter.isNullable && !parameter.isContainer && (this.getNullableTypes().contains(parameter.dataType) || parameter.isEnum)) {
parameter.vendorExtensions.put("x-nullable-value-type", true);
@ -1021,8 +1025,8 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
name = this.escapeReservedWord(name);
return name.equalsIgnoreCase(model.getClassname())
? this.invalidNamePrefix + camelize(name)
: name;
? this.invalidNamePrefix + camelize(name)
: name;
}
@Override
@ -1046,8 +1050,8 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
@Override
public String toExampleValue(Schema p) {
return p.getExample() == null
? null
: p.getExample().toString();
? null
: p.getExample().toString();
}
/**
@ -1176,6 +1180,11 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
@Override
public String toModelName(String name) {
// obtain the name from modelNameMapping directly if provided
if (modelNameMapping.containsKey(name)) {
return modelNameMapping.get(name);
}
// We need to check if schema-mapping has a different model for this class, so we use it
// instead of the auto-generated one.
if (schemaMapping.containsKey(name)) {

View File

@ -42,8 +42,16 @@ paths:
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Environment'
components:
schemas:
Environment:
properties:
dummy:
type: string
PropertyNameMapping:
properties:
http_debug_operation:

View File

@ -3,6 +3,7 @@ Org.OpenAPITools.sln
README.md
api/openapi.yaml
appveyor.yml
docs/Env.md
docs/FakeApi.md
docs/PropertyNameMapping.md
git_push.sh
@ -25,5 +26,6 @@ src/Org.OpenAPITools/Client/OpenAPIDateConverter.cs
src/Org.OpenAPITools/Client/RequestOptions.cs
src/Org.OpenAPITools/Client/RetryConfiguration.cs
src/Org.OpenAPITools/Model/AbstractOpenAPISchema.cs
src/Org.OpenAPITools/Model/Env.cs
src/Org.OpenAPITools/Model/PropertyNameMapping.cs
src/Org.OpenAPITools/Org.OpenAPITools.csproj

View File

@ -94,7 +94,8 @@ namespace Example
try
{
// parameter name mapping test
apiInstance.GetParameterNameMapping(UnderscoreType, type, TypeWithUnderscore, httpDebugOption);
Env result = apiInstance.GetParameterNameMapping(UnderscoreType, type, TypeWithUnderscore, httpDebugOption);
Debug.WriteLine(result);
}
catch (ApiException e)
{
@ -121,6 +122,7 @@ Class | Method | HTTP request | Description
<a id="documentation-for-models"></a>
## Documentation for Models
- [Model.Env](docs/Env.md)
- [Model.PropertyNameMapping](docs/PropertyNameMapping.md)

View File

@ -48,12 +48,22 @@ paths:
style: form
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/Environment'
description: OK
summary: parameter name mapping test
tags:
- fake
components:
schemas:
Environment:
example:
dummy: dummy
properties:
dummy:
type: string
PropertyNameMapping:
properties:
http_debug_operation:

View File

@ -0,0 +1,10 @@
# Org.OpenAPITools.Model.Env
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Dummy** | **string** | | [optional]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -8,7 +8,7 @@ All URIs are relative to *http://localhost*
<a id="getparameternamemapping"></a>
# **GetParameterNameMapping**
> void GetParameterNameMapping (long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption)
> Env GetParameterNameMapping (long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption)
parameter name mapping test
@ -37,7 +37,8 @@ namespace Example
try
{
// parameter name mapping test
apiInstance.GetParameterNameMapping(UnderscoreType, type, TypeWithUnderscore, httpDebugOption);
Env result = apiInstance.GetParameterNameMapping(UnderscoreType, type, TypeWithUnderscore, httpDebugOption);
Debug.WriteLine(result);
}
catch (ApiException e)
{
@ -57,7 +58,10 @@ This returns an ApiResponse object which contains the response data, status code
try
{
// parameter name mapping test
apiInstance.GetParameterNameMappingWithHttpInfo(UnderscoreType, type, TypeWithUnderscore, httpDebugOption);
ApiResponse<Env> response = apiInstance.GetParameterNameMappingWithHttpInfo(UnderscoreType, type, TypeWithUnderscore, httpDebugOption);
Debug.Write("Status Code: " + response.StatusCode);
Debug.Write("Response Headers: " + response.Headers);
Debug.Write("Response Body: " + response.Data);
}
catch (ApiException e)
{
@ -78,7 +82,7 @@ catch (ApiException e)
### Return type
void (empty response body)
[**Env**](Env.md)
### Authorization
@ -87,7 +91,7 @@ No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined
- **Accept**: application/json
### HTTP response details

View File

@ -0,0 +1,66 @@
/*
* Dummy
*
* To test name, parameter mapping options
*
* The version of the OpenAPI document: 1.0.0
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
using Xunit;
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using Org.OpenAPITools.Model;
using Org.OpenAPITools.Client;
using System.Reflection;
using Newtonsoft.Json;
namespace Org.OpenAPITools.Test.Model
{
/// <summary>
/// Class for testing Env
/// </summary>
/// <remarks>
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
/// Please update the test case below to test the model.
/// </remarks>
public class EnvTests : IDisposable
{
// TODO uncomment below to declare an instance variable for Env
//private Env instance;
public EnvTests()
{
// TODO uncomment below to create an instance of Env
//instance = new Env();
}
public void Dispose()
{
// Cleanup when everything is done.
}
/// <summary>
/// Test an instance of Env
/// </summary>
[Fact]
public void EnvInstanceTest()
{
// TODO uncomment below to test "IsType" Env
//Assert.IsType<Env>(instance);
}
/// <summary>
/// Test the property 'Dummy'
/// </summary>
[Fact]
public void DummyTest()
{
// TODO unit test for the property 'Dummy'
}
}
}

View File

@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>Org.OpenAPITools.Test</AssemblyName>
<RootNamespace>Org.OpenAPITools.Test</RootNamespace>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<Nullable>annotations</Nullable>
</PropertyGroup>

View File

@ -15,6 +15,7 @@ using System.Linq;
using System.Net;
using System.Net.Mime;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;
namespace Org.OpenAPITools.Api
{
@ -34,8 +35,8 @@ namespace Org.OpenAPITools.Api
/// <param name="TypeWithUnderscore">type_</param>
/// <param name="httpDebugOption">http debug option (to test parameter naming option)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns></returns>
void GetParameterNameMapping(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0);
/// <returns>Env</returns>
Env GetParameterNameMapping(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0);
/// <summary>
/// parameter name mapping test
@ -49,8 +50,8 @@ namespace Org.OpenAPITools.Api
/// <param name="TypeWithUnderscore">type_</param>
/// <param name="httpDebugOption">http debug option (to test parameter naming option)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>ApiResponse of Object(void)</returns>
ApiResponse<Object> GetParameterNameMappingWithHttpInfo(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0);
/// <returns>ApiResponse of Env</returns>
ApiResponse<Env> GetParameterNameMappingWithHttpInfo(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0);
#endregion Synchronous Operations
}
@ -73,8 +74,8 @@ namespace Org.OpenAPITools.Api
/// <param name="httpDebugOption">http debug option (to test parameter naming option)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of void</returns>
System.Threading.Tasks.Task GetParameterNameMappingAsync(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
/// <returns>Task of Env</returns>
System.Threading.Tasks.Task<Env> GetParameterNameMappingAsync(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
/// <summary>
/// parameter name mapping test
@ -89,8 +90,8 @@ namespace Org.OpenAPITools.Api
/// <param name="httpDebugOption">http debug option (to test parameter naming option)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of ApiResponse</returns>
System.Threading.Tasks.Task<ApiResponse<Object>> GetParameterNameMappingWithHttpInfoAsync(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
/// <returns>Task of ApiResponse (Env)</returns>
System.Threading.Tasks.Task<ApiResponse<Env>> GetParameterNameMappingWithHttpInfoAsync(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
#endregion Asynchronous Operations
}
@ -220,10 +221,11 @@ namespace Org.OpenAPITools.Api
/// <param name="TypeWithUnderscore">type_</param>
/// <param name="httpDebugOption">http debug option (to test parameter naming option)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns></returns>
public void GetParameterNameMapping(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0)
/// <returns>Env</returns>
public Env GetParameterNameMapping(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0)
{
GetParameterNameMappingWithHttpInfo(UnderscoreType, type, TypeWithUnderscore, httpDebugOption);
Org.OpenAPITools.Client.ApiResponse<Env> localVarResponse = GetParameterNameMappingWithHttpInfo(UnderscoreType, type, TypeWithUnderscore, httpDebugOption);
return localVarResponse.Data;
}
/// <summary>
@ -235,8 +237,8 @@ namespace Org.OpenAPITools.Api
/// <param name="TypeWithUnderscore">type_</param>
/// <param name="httpDebugOption">http debug option (to test parameter naming option)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>ApiResponse of Object(void)</returns>
public Org.OpenAPITools.Client.ApiResponse<Object> GetParameterNameMappingWithHttpInfo(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0)
/// <returns>ApiResponse of Env</returns>
public Org.OpenAPITools.Client.ApiResponse<Env> GetParameterNameMappingWithHttpInfo(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0)
{
// verify the required parameter 'type' is set
if (type == null)
@ -263,6 +265,7 @@ namespace Org.OpenAPITools.Api
// to determine the Accept header
string[] _accepts = new string[] {
"application/json"
};
var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes);
@ -287,7 +290,7 @@ namespace Org.OpenAPITools.Api
// make the HTTP request
var localVarResponse = this.Client.Get<Object>("/fake/parameter-name-mapping", localVarRequestOptions, this.Configuration);
var localVarResponse = this.Client.Get<Env>("/fake/parameter-name-mapping", localVarRequestOptions, this.Configuration);
if (this.ExceptionFactory != null)
{
Exception _exception = this.ExceptionFactory("GetParameterNameMapping", localVarResponse);
@ -310,10 +313,11 @@ namespace Org.OpenAPITools.Api
/// <param name="httpDebugOption">http debug option (to test parameter naming option)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of void</returns>
public async System.Threading.Tasks.Task GetParameterNameMappingAsync(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
/// <returns>Task of Env</returns>
public async System.Threading.Tasks.Task<Env> GetParameterNameMappingAsync(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
await GetParameterNameMappingWithHttpInfoAsync(UnderscoreType, type, TypeWithUnderscore, httpDebugOption, operationIndex, cancellationToken).ConfigureAwait(false);
Org.OpenAPITools.Client.ApiResponse<Env> localVarResponse = await GetParameterNameMappingWithHttpInfoAsync(UnderscoreType, type, TypeWithUnderscore, httpDebugOption, operationIndex, cancellationToken).ConfigureAwait(false);
return localVarResponse.Data;
}
/// <summary>
@ -326,8 +330,8 @@ namespace Org.OpenAPITools.Api
/// <param name="httpDebugOption">http debug option (to test parameter naming option)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of ApiResponse</returns>
public async System.Threading.Tasks.Task<Org.OpenAPITools.Client.ApiResponse<Object>> GetParameterNameMappingWithHttpInfoAsync(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
/// <returns>Task of ApiResponse (Env)</returns>
public async System.Threading.Tasks.Task<Org.OpenAPITools.Client.ApiResponse<Env>> GetParameterNameMappingWithHttpInfoAsync(long UnderscoreType, string type, string TypeWithUnderscore, string httpDebugOption, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
// verify the required parameter 'type' is set
if (type == null)
@ -355,6 +359,7 @@ namespace Org.OpenAPITools.Api
// to determine the Accept header
string[] _accepts = new string[] {
"application/json"
};
var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes);
@ -379,7 +384,7 @@ namespace Org.OpenAPITools.Api
// make the HTTP request
var localVarResponse = await this.AsynchronousClient.GetAsync<Object>("/fake/parameter-name-mapping", localVarRequestOptions, this.Configuration, cancellationToken).ConfigureAwait(false);
var localVarResponse = await this.AsynchronousClient.GetAsync<Env>("/fake/parameter-name-mapping", localVarRequestOptions, this.Configuration, cancellationToken).ConfigureAwait(false);
if (this.ExceptionFactory != null)
{

View File

@ -0,0 +1,128 @@
/*
* Dummy
*
* To test name, parameter mapping options
*
* The version of the OpenAPI document: 1.0.0
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.IO;
using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Env
/// </summary>
[DataContract(Name = "Environment")]
public partial class Env : IEquatable<Env>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Env" /> class.
/// </summary>
/// <param name="dummy">dummy.</param>
public Env(string dummy = default(string))
{
this.Dummy = dummy;
}
/// <summary>
/// Gets or Sets Dummy
/// </summary>
[DataMember(Name = "dummy", EmitDefaultValue = false)]
public string Dummy { get; set; }
/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("class Env {\n");
sb.Append(" Dummy: ").Append(Dummy).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
/// <summary>
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
}
/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="input">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object input)
{
return this.Equals(input as Env);
}
/// <summary>
/// Returns true if Env instances are equal
/// </summary>
/// <param name="input">Instance of Env to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(Env input)
{
if (input == null)
{
return false;
}
return
(
this.Dummy == input.Dummy ||
(this.Dummy != null &&
this.Dummy.Equals(input.Dummy))
);
}
/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.Dummy != null)
{
hashCode = (hashCode * 59) + this.Dummy.GetHashCode();
}
return hashCode;
}
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
yield break;
}
}
}

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo><!-- setting GenerateAssemblyInfo to false causes this bug https://github.com/dotnet/project-system/issues/3934 -->
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>Org.OpenAPITools</AssemblyName>
<PackageId>Org.OpenAPITools</PackageId>
<OutputType>Library</OutputType>

View File

@ -1,5 +1,6 @@
README.md
build.gradle
docs/Environment.md
docs/FakeApi.md
docs/PropertyNameMapping.md
gradle/wrapper/gradle-wrapper.jar
@ -25,4 +26,5 @@ src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt
src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt
src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt
src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt
src/main/kotlin/org/openapitools/client/models/Environment.kt
src/main/kotlin/org/openapitools/client/models/PropertyNameMapping.kt

View File

@ -50,6 +50,7 @@ Class | Method | HTTP request | Description
<a id="documentation-for-models"></a>
## Documentation for Models
- [org.openapitools.client.models.Environment](docs/Environment.md)
- [org.openapitools.client.models.PropertyNameMapping](docs/PropertyNameMapping.md)

View File

@ -0,0 +1,10 @@
# Environment
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**dummy** | **kotlin.String** | | [optional]

View File

@ -9,7 +9,7 @@ Method | HTTP request | Description
<a id="getParameterNameMapping"></a>
# **getParameterNameMapping**
> getParameterNameMapping(underscoreType, type, typeWithUnderscore, httpDebugOption)
> Environment getParameterNameMapping(underscoreType, type, typeWithUnderscore, httpDebugOption)
parameter name mapping test
@ -25,7 +25,8 @@ val type : kotlin.String = type_example // kotlin.String | type
val typeWithUnderscore : kotlin.String = typeWithUnderscore_example // kotlin.String | type_
val httpDebugOption : kotlin.String = httpDebugOption_example // kotlin.String | http debug option (to test parameter naming option)
try {
apiInstance.getParameterNameMapping(underscoreType, type, typeWithUnderscore, httpDebugOption)
val result : Environment = apiInstance.getParameterNameMapping(underscoreType, type, typeWithUnderscore, httpDebugOption)
println(result)
} catch (e: ClientException) {
println("4xx response calling FakeApi#getParameterNameMapping")
e.printStackTrace()
@ -46,7 +47,7 @@ Name | Type | Description | Notes
### Return type
null (empty response body)
[**Environment**](Environment.md)
### Authorization
@ -55,5 +56,5 @@ No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined
- **Accept**: application/json

View File

@ -19,6 +19,7 @@ import java.io.IOException
import okhttp3.OkHttpClient
import okhttp3.HttpUrl
import org.openapitools.client.models.Environment
import com.squareup.moshi.Json
@ -51,19 +52,20 @@ class FakeApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient =
* @param type type
* @param typeWithUnderscore type_
* @param httpDebugOption http debug option (to test parameter naming option)
* @return void
* @return Environment
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Suppress("UNCHECKED_CAST")
@Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun getParameterNameMapping(underscoreType: kotlin.Long, type: kotlin.String, typeWithUnderscore: kotlin.String, httpDebugOption: kotlin.String) : Unit {
fun getParameterNameMapping(underscoreType: kotlin.Long, type: kotlin.String, typeWithUnderscore: kotlin.String, httpDebugOption: kotlin.String) : Environment {
val localVarResponse = getParameterNameMappingWithHttpInfo(underscoreType = underscoreType, type = type, typeWithUnderscore = typeWithUnderscore, httpDebugOption = httpDebugOption)
return when (localVarResponse.responseType) {
ResponseType.Success -> Unit
ResponseType.Success -> (localVarResponse as Success<*>).data as Environment
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
@ -84,15 +86,16 @@ class FakeApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient =
* @param type type
* @param typeWithUnderscore type_
* @param httpDebugOption http debug option (to test parameter naming option)
* @return ApiResponse<Unit?>
* @return ApiResponse<Environment?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Suppress("UNCHECKED_CAST")
@Throws(IllegalStateException::class, IOException::class)
fun getParameterNameMappingWithHttpInfo(underscoreType: kotlin.Long, type: kotlin.String, typeWithUnderscore: kotlin.String, httpDebugOption: kotlin.String) : ApiResponse<Unit?> {
fun getParameterNameMappingWithHttpInfo(underscoreType: kotlin.Long, type: kotlin.String, typeWithUnderscore: kotlin.String, httpDebugOption: kotlin.String) : ApiResponse<Environment?> {
val localVariableConfig = getParameterNameMappingRequestConfig(underscoreType = underscoreType, type = type, typeWithUnderscore = typeWithUnderscore, httpDebugOption = httpDebugOption)
return request<Unit, Unit>(
return request<Unit, Environment>(
localVariableConfig
)
}
@ -116,7 +119,8 @@ class FakeApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient =
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
underscoreType.apply { localVariableHeaders["_type"] = this.toString() }
typeWithUnderscore.apply { localVariableHeaders["type_"] = this.toString() }
localVariableHeaders["Accept"] = "application/json"
return RequestConfig(
method = RequestMethod.GET,
path = "/fake/parameter-name-mapping",

View File

@ -0,0 +1,35 @@
/**
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*
*/
@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)
package org.openapitools.client.models
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
/**
*
*
* @param dummy
*/
data class Environment (
@Json(name = "dummy")
val dummy: kotlin.String? = null
)