diff --git a/bin/csharp-petstore-all.sh b/bin/csharp-petstore-all.sh index 81817c3670f..70e5f09e0b1 100755 --- a/bin/csharp-petstore-all.sh +++ b/bin/csharp-petstore-all.sh @@ -1,6 +1,6 @@ #!/bin/sh -# C# Petstore API client +# C# Petstore API client (.NET 3.5) ./bin/csharp-petstore.sh # C# Petstore API client with PropertyChanged @@ -8,3 +8,7 @@ # C# Petstore API client (v5.0 for .net standarnd 1.3+) ./bin/csharp-petstore-net-standard.sh + +# C# Petstore API client (.NET 4.0) +./bin/csharp-petstore-net-40.sh + diff --git a/bin/csharp-petstore.sh b/bin/csharp-petstore.sh index fd5d0876d04..232f706b7fd 100755 --- a/bin/csharp-petstore.sh +++ b/bin/csharp-petstore.sh @@ -26,6 +26,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate $@ -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l csharp -o samples/client/petstore/csharp/SwaggerClientNet40 --additional-properties packageGuid={321C8C3F-0156-40C1-AE42-D59761FB9B6C} -c ./bin/csharp-petstore-net-40.json" +ags="generate $@ -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l csharp -o samples/client/petstore/csharp/SwaggerClient --additional-properties packageGuid={321C8C3F-0156-40C1-AE42-D59761FB9B6C}" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/nancyfx-petstore-server.sh b/bin/nancyfx-petstore-server.sh index 38db6514ded..13516ee67e9 100755 --- a/bin/nancyfx-petstore-server.sh +++ b/bin/nancyfx-petstore-server.sh @@ -26,6 +26,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate $@ -t modules/swagger-codegen/src/main/resources/nancyfx -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l nancyfx -o samples/server/petstore/nancyfx --additional-properties packageGuid={768B8DC6-54EE-4D40-9B20-7857E1D742A4}" +ags="generate $@ -t modules/swagger-codegen/src/main/resources/nancyfx -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l nancyfx -o samples/server/petstore/nancyfx --additional-properties packageGuid={768B8DC6-54EE-4D40-9B20-7857E1D742A4},asyncServer=false" java $JAVA_OPTS -jar $executable $ags diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java index 7a5d41c0dbe..1dc571ac5b1 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java @@ -175,6 +175,9 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case, public static final String SUPPORTS_ES6 = "supportsES6"; public static final String SUPPORTS_ES6_DESC = "Generate code that conforms to ES6."; + public static final String SUPPORTS_ASYNC = "supportsAsync"; + public static final String SUPPORTS_ASYNC_DESC = "Generate code that supports async operations."; + public static final String EXCLUDE_TESTS = "excludeTests"; public static final String EXCLUDE_TESTS_DESC = "Specifies that no tests are to be generated."; @@ -199,6 +202,9 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case, public static final String NON_PUBLIC_API = "nonPublicApi"; public static final String NON_PUBLIC_API_DESC = "Generates code with reduced access modifiers; allows embedding elsewhere without exposing non-public API calls to consumers."; + public static final String VALIDATABLE = "validatable"; + public static final String VALIDATABLE_DESC = "Generates self-validatable models."; + public static final String IGNORE_FILE_OVERRIDE = "ignoreFileOverride"; public static final String IGNORE_FILE_OVERRIDE_DESC = "Specifies an override location for the .swagger-codegen-ignore file. Most useful on initial generation."; diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java index bbd06e02421..7da2e06018c 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java @@ -262,24 +262,33 @@ public void processOpts() { // {{useDateTimeOffset}} if (additionalProperties.containsKey(CodegenConstants.USE_DATETIME_OFFSET)) { - useDateTimeOffset(Boolean.valueOf(additionalProperties.get(CodegenConstants.USE_DATETIME_OFFSET).toString())); + useDateTimeOffset(convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_DATETIME_OFFSET)); + } else { + additionalProperties.put(CodegenConstants.USE_DATETIME_OFFSET, useDateTimeOffsetFlag); } - additionalProperties.put(CodegenConstants.USE_DATETIME_OFFSET, useDateTimeOffsetFlag); if (additionalProperties.containsKey(CodegenConstants.USE_COLLECTION)) { - setUseCollection(Boolean.valueOf(additionalProperties.get(CodegenConstants.USE_COLLECTION).toString())); + setUseCollection(convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_COLLECTION)); + } else { + additionalProperties.put(CodegenConstants.USE_COLLECTION, useCollection); } if (additionalProperties.containsKey(CodegenConstants.RETURN_ICOLLECTION)) { - setReturnICollection(Boolean.valueOf(additionalProperties.get(CodegenConstants.RETURN_ICOLLECTION).toString())); + setReturnICollection(convertPropertyToBooleanAndWriteBack(CodegenConstants.RETURN_ICOLLECTION)); + } else { + additionalProperties.put(CodegenConstants.RETURN_ICOLLECTION, returnICollection); } if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_EMIT_DEFAULT_VALUES)) { - setOptionalEmitDefaultValue(Boolean.valueOf(additionalProperties.get(CodegenConstants.OPTIONAL_EMIT_DEFAULT_VALUES).toString())); + setOptionalEmitDefaultValue(convertPropertyToBooleanAndWriteBack(CodegenConstants.OPTIONAL_EMIT_DEFAULT_VALUES)); + } else { + additionalProperties.put(CodegenConstants.OPTIONAL_EMIT_DEFAULT_VALUES, optionalEmitDefaultValue); } if (additionalProperties.containsKey(CodegenConstants.NETCORE_PROJECT_FILE)) { - setNetCoreProjectFileFlag(Boolean.valueOf(additionalProperties.get(CodegenConstants.NETCORE_PROJECT_FILE).toString())); + setNetCoreProjectFileFlag(convertPropertyToBooleanAndWriteBack(CodegenConstants.NETCORE_PROJECT_FILE)); + } else { + additionalProperties.put(CodegenConstants.NETCORE_PROJECT_FILE, netCoreProjectFileFlag); } if (additionalProperties.containsKey(CodegenConstants.INTERFACE_PREFIX)) { diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AspNetCoreServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AspNetCoreServerCodegen.java index 80c1cbbbf41..7bceec036d1 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AspNetCoreServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AspNetCoreServerCodegen.java @@ -1,5 +1,6 @@ package io.swagger.codegen.languages; +import com.samskivert.mustache.Mustache; import io.swagger.codegen.CodegenConstants; import io.swagger.codegen.CodegenOperation; import io.swagger.codegen.CodegenType; @@ -169,4 +170,10 @@ protected void processOperation(CodegenOperation operation) { // Converts, for example, PUT to HttpPut for controller attributes operation.httpMethod = "Http" + operation.httpMethod.substring(0, 1) + operation.httpMethod.substring(1).toLowerCase(); } + + @Override + public Mustache.Compiler processCompiler(Mustache.Compiler compiler) { + // To avoid unexpected behaviors when options are passed programmatically such as { "useCollection": "" } + return super.processCompiler(compiler).emptyStringIsFalse(true); + } } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java index 5f739840a2f..3708d511f69 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java @@ -1,6 +1,7 @@ package io.swagger.codegen.languages; import com.google.common.collect.ImmutableMap; +import com.samskivert.mustache.Mustache; import io.swagger.codegen.*; import io.swagger.models.Model; import org.slf4j.Logger; @@ -17,21 +18,33 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen { private static final String NET45 = "v4.5"; private static final String NET40 = "v4.0"; private static final String NET35 = "v3.5"; + // TODO: v5.0 is PCL, not netstandard version 1.3, and not a specific .NET Framework. This needs to be updated, + // especially because it will conflict with .NET Framework 5.0 when released, and PCL 5 refers to Framework 4.0. + // We should support either NETSTANDARD, PCL, or Both… but the concepts shouldn't be mixed. private static final String NETSTANDARD = "v5.0"; private static final String UWP = "uwp"; + // Defines the sdk option for targeted frameworks, which differs from targetFramework and targetFrameworkNuget + private static final String MCS_NET_VERSION_KEY = "x-mcs-sdk"; + protected String packageGuid = "{" + java.util.UUID.randomUUID().toString().toUpperCase() + "}"; protected String clientPackage = "IO.Swagger.Client"; protected String localVariablePrefix = ""; protected String apiDocPath = "docs/"; protected String modelDocPath = "docs/"; + // Defines TargetFrameworkVersion in csproj files protected String targetFramework = NET45; + + // Defines nuget identifiers for target framework protected String targetFrameworkNuget = "net45"; protected boolean supportsAsync = Boolean.TRUE; protected boolean supportsUWP = Boolean.FALSE; protected boolean netStandard = Boolean.FALSE; protected boolean generatePropertyChanged = Boolean.FALSE; + protected boolean hideGenerationTimestamp = Boolean.TRUE; + + protected boolean validatable = Boolean.TRUE; protected Map regexModifiers; protected final Map frameworks; @@ -145,6 +158,10 @@ public CSharpClientCodegen() { CodegenConstants.NETCORE_PROJECT_FILE_DESC, this.netCoreProjectFileFlag); + addSwitch(CodegenConstants.VALIDATABLE, + CodegenConstants.VALIDATABLE_DESC, + this.validatable); + regexModifiers = new HashMap(); regexModifiers.put('i', "IgnoreCase"); regexModifiers.put('m', "Multiline"); @@ -156,39 +173,43 @@ public CSharpClientCodegen() { public void processOpts() { super.processOpts(); + /* + * NOTE: When supporting boolean additionalProperties, you should read the value and write it back as a boolean. + * This avoids oddities where additionalProperties contains "false" rather than false, which will cause the + * templating engine to behave unexpectedly. + * + * Use the pattern: + * if (additionalProperties.containsKey(prop)) convertPropertyToBooleanAndWriteBack(prop); + */ + if (additionalProperties.containsKey(CodegenConstants.MODEL_PROPERTY_NAMING)) { setModelPropertyNaming((String) additionalProperties.get(CodegenConstants.MODEL_PROPERTY_NAMING)); } // default HIDE_GENERATION_TIMESTAMP to true - if (!additionalProperties.containsKey(CodegenConstants.HIDE_GENERATION_TIMESTAMP)) { - additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString()); + if (additionalProperties.containsKey(CodegenConstants.HIDE_GENERATION_TIMESTAMP)) { + setHideGenerationTimestamp(convertPropertyToBooleanAndWriteBack(CodegenConstants.HIDE_GENERATION_TIMESTAMP)); } else { - additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, - Boolean.valueOf(additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString())); + additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, hideGenerationTimestamp); } if (isEmpty(apiPackage)) { - apiPackage = "Api"; + setApiPackage("Api"); } if (isEmpty(modelPackage)) { - modelPackage = "Model"; + setModelPackage("Model"); } clientPackage = "Client"; Boolean excludeTests = false; if (additionalProperties.containsKey(CodegenConstants.EXCLUDE_TESTS)) { - excludeTests = Boolean.valueOf(additionalProperties.get(CodegenConstants.EXCLUDE_TESTS).toString()); + excludeTests = convertPropertyToBooleanAndWriteBack(CodegenConstants.EXCLUDE_TESTS); } - additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage); - additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage); - additionalProperties.put("clientPackage", clientPackage); - additionalProperties.put("emitDefaultValue", optionalEmitDefaultValue); - - if (!additionalProperties.containsKey("validatable")) { - // default validatable to true if not set - additionalProperties.put("validatable", true); + if (additionalProperties.containsKey(CodegenConstants.VALIDATABLE)) { + setValidatable(convertPropertyToBooleanAndWriteBack(CodegenConstants.VALIDATABLE)); + } else { + additionalProperties.put(CodegenConstants.VALIDATABLE, validatable); } if (additionalProperties.containsKey(CodegenConstants.DOTNET_FRAMEWORK)) { @@ -196,93 +217,116 @@ public void processOpts() { } else { // Ensure default is set. setTargetFramework(NET45); - additionalProperties.put("targetFramework", this.targetFramework); + additionalProperties.put(CodegenConstants.DOTNET_FRAMEWORK, this.targetFramework); } if (NET35.equals(this.targetFramework)) { + // This is correct, mono will require you build .NET 3.5 sources using 4.0 SDK + additionalProperties.put(MCS_NET_VERSION_KEY, "4"); + additionalProperties.put("net35", true); + if (additionalProperties.containsKey(CodegenConstants.SUPPORTS_ASYNC)) { + LOGGER.warn(".NET 3.5 generator does not support async."); + additionalProperties.remove(CodegenConstants.SUPPORTS_ASYNC); + } + setTargetFrameworkNuget("net35"); + setValidatable(Boolean.FALSE); setSupportsAsync(Boolean.FALSE); - if (additionalProperties.containsKey("supportsAsync")) { - additionalProperties.remove("supportsAsync"); - } - additionalProperties.put("validatable", false); - additionalProperties.put("net35", true); } else if (NETSTANDARD.equals(this.targetFramework)) { + // TODO: NETSTANDARD here is misrepresenting a PCL v5.0 which supports .NET Framework 4.6+, .NET Core 1.0, and Windows Universal 10.0 + additionalProperties.put(MCS_NET_VERSION_KEY, "4.6-api"); + if (additionalProperties.containsKey("supportsUWP")) { + LOGGER.warn(".NET " + NETSTANDARD + " generator does not support UWP."); + additionalProperties.remove("supportsUWP"); + } + + // TODO: NETSTANDARD=v5.0 and targetFrameworkNuget=netstandard1.3. These need to sync. setTargetFrameworkNuget("netstandard1.3"); setSupportsAsync(Boolean.TRUE); setSupportsUWP(Boolean.FALSE); setNetStandard(Boolean.TRUE); - additionalProperties.put("supportsAsync", this.supportsAsync); - additionalProperties.put("supportsUWP", this.supportsUWP); - additionalProperties.put("netStandard", this.netStandard); //Tests not yet implemented for .NET Standard codegen //Todo implement it excludeTests = true; - if (additionalProperties.containsKey(CodegenConstants.EXCLUDE_TESTS)) { - additionalProperties.remove(CodegenConstants.EXCLUDE_TESTS); - } - additionalProperties.put(CodegenConstants.EXCLUDE_TESTS, excludeTests); } else if (UWP.equals(this.targetFramework)) { setTargetFrameworkNuget("uwp"); setSupportsAsync(Boolean.TRUE); setSupportsUWP(Boolean.TRUE); - additionalProperties.put("supportsAsync", this.supportsAsync); - additionalProperties.put("supportsUWP", this.supportsUWP); } else if (NET40.equals(this.targetFramework)) { + additionalProperties.put(MCS_NET_VERSION_KEY, "4"); + additionalProperties.put("isNet40", true); + + if (additionalProperties.containsKey(CodegenConstants.SUPPORTS_ASYNC)) { + LOGGER.warn(".NET " + NET40 + " generator does not support async."); + additionalProperties.remove(CodegenConstants.SUPPORTS_ASYNC); + } + setTargetFrameworkNuget("net40"); setSupportsAsync(Boolean.FALSE); - if (additionalProperties.containsKey("supportsAsync")) { - additionalProperties.remove("supportsAsync"); - } - additionalProperties.put("isNet40", true); } else { + additionalProperties.put(MCS_NET_VERSION_KEY, "4.5.2-api"); setTargetFrameworkNuget("net45"); setSupportsAsync(Boolean.TRUE); - additionalProperties.put("supportsAsync", this.supportsAsync); } if (additionalProperties.containsKey(CodegenConstants.GENERATE_PROPERTY_CHANGED)) { if (NET35.equals(targetFramework)) { LOGGER.warn(CodegenConstants.GENERATE_PROPERTY_CHANGED + " is only supported by generated code for .NET 4+."); + additionalProperties.remove(CodegenConstants.GENERATE_PROPERTY_CHANGED); } else if (NETSTANDARD.equals(targetFramework)) { LOGGER.warn(CodegenConstants.GENERATE_PROPERTY_CHANGED + " is not supported in .NET Standard generated code."); + additionalProperties.remove(CodegenConstants.GENERATE_PROPERTY_CHANGED); } else if (Boolean.TRUE.equals(netCoreProjectFileFlag)) { LOGGER.warn(CodegenConstants.GENERATE_PROPERTY_CHANGED + " is not supported in .NET Core csproj project format."); - } else { - setGeneratePropertyChanged(Boolean.valueOf(additionalProperties.get(CodegenConstants.GENERATE_PROPERTY_CHANGED).toString())); - } - - if (Boolean.FALSE.equals(this.generatePropertyChanged)) { additionalProperties.remove(CodegenConstants.GENERATE_PROPERTY_CHANGED); + } else { + setGeneratePropertyChanged(convertPropertyToBooleanAndWriteBack(CodegenConstants.GENERATE_PROPERTY_CHANGED)); } } + additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage); + additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage); + additionalProperties.put("clientPackage", clientPackage); + + additionalProperties.put(CodegenConstants.EXCLUDE_TESTS, excludeTests); + additionalProperties.put(CodegenConstants.VALIDATABLE, this.validatable); + additionalProperties.put(CodegenConstants.SUPPORTS_ASYNC, this.supportsAsync); + additionalProperties.put("supportsUWP", this.supportsUWP); + additionalProperties.put("netStandard", this.netStandard); additionalProperties.put("targetFrameworkNuget", this.targetFrameworkNuget); + // TODO: either remove this and update templates to match the "optionalEmitDefaultValues" property, or rename that property. + additionalProperties.put("emitDefaultValue", optionalEmitDefaultValue); + if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_PROJECT_FILE)) { - setOptionalProjectFileFlag(Boolean.valueOf( - additionalProperties.get(CodegenConstants.OPTIONAL_PROJECT_FILE).toString())); + setOptionalProjectFileFlag(convertPropertyToBooleanAndWriteBack(CodegenConstants.OPTIONAL_PROJECT_FILE)); + } else { + additionalProperties.put(CodegenConstants.OPTIONAL_PROJECT_FILE, optionalProjectFileFlag); } if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_PROJECT_GUID)) { setPackageGuid((String) additionalProperties.get(CodegenConstants.OPTIONAL_PROJECT_GUID)); + } else { + additionalProperties.put(CodegenConstants.OPTIONAL_PROJECT_GUID, packageGuid); } - additionalProperties.put("packageGuid", packageGuid); if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_METHOD_ARGUMENT)) { - setOptionalMethodArgumentFlag(Boolean.valueOf(additionalProperties - .get(CodegenConstants.OPTIONAL_METHOD_ARGUMENT).toString())); + setOptionalMethodArgumentFlag(convertPropertyToBooleanAndWriteBack(CodegenConstants.OPTIONAL_METHOD_ARGUMENT)); + } else { + additionalProperties.put(CodegenConstants.OPTIONAL_METHOD_ARGUMENT, optionalMethodArgumentFlag); } - additionalProperties.put("optionalMethodArgument", optionalMethodArgumentFlag); if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_ASSEMBLY_INFO)) { - setOptionalAssemblyInfoFlag(Boolean.valueOf(additionalProperties - .get(CodegenConstants.OPTIONAL_ASSEMBLY_INFO).toString())); + setOptionalAssemblyInfoFlag(convertPropertyToBooleanAndWriteBack(CodegenConstants.OPTIONAL_ASSEMBLY_INFO)); + } else { + additionalProperties.put(CodegenConstants.OPTIONAL_ASSEMBLY_INFO, optionalAssemblyInfoFlag); } if (additionalProperties.containsKey(CodegenConstants.NON_PUBLIC_API)) { - setNonPublicApi(Boolean.valueOf(additionalProperties.get(CodegenConstants.NON_PUBLIC_API).toString())); + setNonPublicApi(convertPropertyToBooleanAndWriteBack(CodegenConstants.NON_PUBLIC_API)); + } else { + additionalProperties.put(CodegenConstants.NON_PUBLIC_API, isNonPublicApi()); } final String testPackageName = testPackageName(); @@ -318,6 +362,12 @@ public void processOpts() { supportingFiles.add(new SupportingFile("JsonSubTypes.mustache", clientPackageDir, "JsonSubTypes.cs")); + if (NET40.equals(this.targetFramework)) { + // .net 4.0 doesn't include ReadOnlyDictionary… + supportingFiles.add(new SupportingFile("ReadOnlyDictionary.mustache", + clientPackageDir, "ReadOnlyDictionary.cs")); + } + if (Boolean.FALSE.equals(this.netStandard) && Boolean.FALSE.equals(this.netCoreProjectFileFlag)) { supportingFiles.add(new SupportingFile("compile.mustache", "", "build.bat")); supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "build.sh")); @@ -346,6 +396,13 @@ public void processOpts() { if (Boolean.FALSE.equals(this.netCoreProjectFileFlag)) { supportingFiles.add(new SupportingFile("packages_test.config.mustache", testPackageFolder + File.separator, "packages.config")); } + + if (NET40.equals(this.targetFramework)) { + // Include minimal tests for modifications made to JsonSubTypes, since code is quite different for .net 4.0 from original implementation + supportingFiles.add(new SupportingFile("JsonSubTypesTests.mustache", + testPackageFolder + File.separator + "Client", + "JsonSubTypesTests.cs")); + } } if (Boolean.TRUE.equals(generatePropertyChanged)) { @@ -355,9 +412,6 @@ public void processOpts() { supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore")); - // apache v2 license - // UPDATE (20160612) no longer needed as the Apache v2 LICENSE is added globally - //supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE")); if (optionalAssemblyInfoFlag && Boolean.FALSE.equals(this.netCoreProjectFileFlag)) { supportingFiles.add(new SupportingFile("AssemblyInfo.mustache", packageFolder + File.separator + "Properties", "AssemblyInfo.cs")); @@ -733,6 +787,10 @@ public void setGeneratePropertyChanged(final Boolean generatePropertyChanged) { this.generatePropertyChanged = generatePropertyChanged; } + public void setHideGenerationTimestamp(boolean hideGenerationTimestamp) { + this.hideGenerationTimestamp = hideGenerationTimestamp; + } + public boolean isNonPublicApi() { return nonPublicApi; } @@ -741,6 +799,10 @@ public void setNonPublicApi(final boolean nonPublicApi) { this.nonPublicApi = nonPublicApi; } + public void setValidatable(boolean validatable) { + this.validatable = validatable; + } + @Override public String toModelDocFilename(String name) { return toModelFilename(name); @@ -765,4 +827,10 @@ public String apiTestFileFolder() { public String modelTestFileFolder() { return outputFolder + File.separator + testFolder + File.separator + testPackageName() + File.separator + modelPackage(); } + + @Override + public Mustache.Compiler processCompiler(Mustache.Compiler compiler) { + // To avoid unexpected behaviors when options are passed programmatically such as { "supportsAsync": "" } + return super.processCompiler(compiler).emptyStringIsFalse(true); + } } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java index daa1866db0e..70fd5dcbbeb 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java @@ -91,7 +91,7 @@ public NancyFXServerCodegen() { addSwitch(RETURN_ICOLLECTION, RETURN_ICOLLECTION_DESC, returnICollection); addSwitch(IMMUTABLE_OPTION, "Enabled by default. If disabled generates model classes with setters", true); addSwitch(USE_BASE_PATH, "Enabled by default. If disabled, module paths will not mirror api base path", true); - addSwitch(ASYNC_SERVER, "Set to true to enable the generation of async routes/endpoints.", false); + addSwitch(ASYNC_SERVER, "Set to true to enable the generation of async routes/endpoints.", this.asyncServer); typeMapping.putAll(nodaTimeTypesMappings()); languageSpecificPrimitives.addAll(nodaTimePrimitiveTypes()); @@ -134,7 +134,9 @@ public void processOpts() { } if (additionalProperties.containsKey(ASYNC_SERVER)) { - setAsyncServer(Boolean.valueOf(additionalProperties.get(ASYNC_SERVER).toString())); + setAsyncServer(convertPropertyToBooleanAndWriteBack(ASYNC_SERVER)); + } else { + additionalProperties.put(ASYNC_SERVER, this.asyncServer); } additionalProperties.put("packageGuid", packageGuid); diff --git a/modules/swagger-codegen/src/main/resources/csharp/JsonSubTypes.mustache b/modules/swagger-codegen/src/main/resources/csharp/JsonSubTypes.mustache index 3a6da091b78..90ddf3a2228 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/JsonSubTypes.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/JsonSubTypes.mustache @@ -132,7 +132,7 @@ namespace JsonSubTypes private static IList CreateCompatibleList(Type targetContainerType, Type elementType) { IList list; - if (targetContainerType.IsArray || targetContainerType.GetTypeInfo().IsAbstract) + if (targetContainerType.IsArray || targetContainerType{{^isNet40}}.GetTypeInfo(){{/isNet40}}.IsAbstract) { list = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType)); } @@ -152,7 +152,7 @@ namespace JsonSubTypes } else { - elementType = arrayOrGenericContainer.GenericTypeArguments[0]; + elementType = arrayOrGenericContainer{{#isNet40}}.GetGenericArguments().FirstOrDefault(){{/isNet40}}{{^isNet40}}.GenericTypeArguments[0]{{/isNet40}}; } return elementType; } @@ -190,7 +190,7 @@ namespace JsonSubTypes private static Type GetTypeByPropertyPresence(JObject jObject, Type parentType) { - foreach (var type in parentType.GetTypeInfo().GetCustomAttributes()) + foreach (var type in parentType{{#isNet40}}.GetCustomAttributes(false).OfType{{/isNet40}}{{^isNet40}}.GetTypeInfo().GetCustomAttributes{{/isNet40}}()) { JToken ignore; if (jObject.TryGetValue(type.PropertyName, out ignore)) @@ -222,7 +222,7 @@ namespace JsonSubTypes if (typeName == null) return null; - var insideAssembly = parentType.GetTypeInfo().Assembly; + var insideAssembly = parentType{{^isNet40}}.GetTypeInfo(){{/isNet40}}.Assembly; var typeByName = insideAssembly.GetType(typeName); if (typeByName == null) @@ -233,7 +233,7 @@ namespace JsonSubTypes return typeByName; } - private static Type GetTypeFromMapping(IReadOnlyDictionary typeMapping, object discriminatorValue) + private static Type GetTypeFromMapping(I{{^isNet40}}ReadOnly{{/isNet40}}Dictionary typeMapping, object discriminatorValue) { var targetlookupValueType = typeMapping.First().Key.GetType(); var lookupValue = ConvertJsonValueToType(discriminatorValue, targetlookupValueType); @@ -244,12 +244,12 @@ namespace JsonSubTypes private static Dictionary GetSubTypeMapping(Type type) { - return type.GetTypeInfo().GetCustomAttributes().ToDictionary(x => x.AssociatedValue, x => x.SubType); + return type{{#isNet40}}.GetCustomAttributes(false).OfType{{/isNet40}}{{^isNet40}}.GetTypeInfo().GetCustomAttributes{{/isNet40}}().ToDictionary(x => x.AssociatedValue, x => x.SubType); } private static object ConvertJsonValueToType(object objectType, Type targetlookupValueType) { - if (targetlookupValueType.GetTypeInfo().IsEnum) + if (targetlookupValueType{{^isNet40}}.GetTypeInfo(){{/isNet40}}.IsEnum) return Enum.ToObject(targetlookupValueType, objectType); return Convert.ChangeType(objectType, targetlookupValueType); diff --git a/modules/swagger-codegen/src/main/resources/csharp/JsonSubTypesTests.mustache b/modules/swagger-codegen/src/main/resources/csharp/JsonSubTypesTests.mustache new file mode 100644 index 00000000000..9b1f66624d7 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/csharp/JsonSubTypesTests.mustache @@ -0,0 +1,125 @@ +{{>partial_header}} + +using System.Collections.Generic; +using System.Linq; +using JsonSubTypes; +using Newtonsoft.Json; +using NUnit.Framework; + +using {{packageName}}.{{apiPackage}}; +using {{packageName}}.{{modelPackage}}; +using {{packageName}}.Client; + +namespace {{packageName}}.Test.Client +{ + public class JsonSubTypesTests + { + [Test] + public void TestSimpleJsonSubTypesExample() + { + var annimal = + JsonConvert.DeserializeObject("{\"Kind\":\"Dog\",\"Breed\":\"Jack Russell Terrier\"}"); + Assert.AreEqual("Jack Russell Terrier", (annimal as Dog)?.Breed); + } + + [Test] + public void DeserializeObjectWithCustomMapping() + { + var annimal = + JsonConvert.DeserializeObject("{\"Sound\":\"Bark\",\"Breed\":\"Jack Russell Terrier\"}"); + Assert.AreEqual("Jack Russell Terrier", (annimal as Dog2)?.Breed); + } + + [Test] + public void DeserializeObjectMappingByPropertyPresence() + { + string json = + "[{\"Department\":\"Department1\",\"JobTitle\":\"JobTitle1\",\"FirstName\":\"FirstName1\",\"LastName\":\"LastName1\"}," + + "{\"Department\":\"Department1\",\"JobTitle\":\"JobTitle1\",\"FirstName\":\"FirstName1\",\"LastName\":\"LastName1\"}," + + "{\"Skill\":\"Painter\",\"FirstName\":\"FirstName1\",\"LastName\":\"LastName1\"}]"; + + + var persons = JsonConvert.DeserializeObject>(json); + Assert.AreEqual("Painter", (persons.Last() as Artist)?.Skill); + } + } + + [JsonConverter(typeof(JsonSubtypes), "Kind")] + public interface IAnimal + { + string Kind { get; } + } + + public class Dog : IAnimal + { + public Dog() + { + Kind = "Dog"; + } + + public string Kind { get; } + public string Breed { get; set; } + } + + class Cat : IAnimal + { + public Cat() + { + Kind = "Cat"; + } + + public string Kind { get; } + bool Declawed { get; set; } + } + + [JsonConverter(typeof(JsonSubtypes), "Sound")] + [JsonSubtypes.KnownSubType(typeof(Dog2), "Bark")] + [JsonSubtypes.KnownSubType(typeof(Cat2), "Meow")] + public class Animal2 + { + public virtual string Sound { get; } + public string Color { get; set; } + } + + public class Dog2 : Animal2 + { + public Dog2() + { + Sound = "Bark"; + } + + public override string Sound { get; } + public string Breed { get; set; } + } + + public class Cat2 : Animal2 + { + public Cat2() + { + Sound = "Meow"; + } + + public override string Sound { get; } + public bool Declawed { get; set; } + } + + [JsonConverter(typeof(JsonSubtypes))] + [JsonSubtypes.KnownSubTypeWithProperty(typeof(Employee), "JobTitle")] + [JsonSubtypes.KnownSubTypeWithProperty(typeof(Artist), "Skill")] + public class Person + { + public string FirstName { get; set; } + public string LastName { get; set; } + } + + public class Employee : Person + { + public string Department { get; set; } + public string JobTitle { get; set; } + } + + public class Artist : Person + { + public string Skill { get; set; } + } +} diff --git a/modules/swagger-codegen/src/main/resources/csharp/Project.mustache b/modules/swagger-codegen/src/main/resources/csharp/Project.mustache index d1271b9d515..84afceae190 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/Project.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/Project.mustache @@ -73,10 +73,10 @@ {{binRelativePath}}\Newtonsoft.Json.10.0.3\lib\{{targetFrameworkNuget}}\Newtonsoft.Json.dll - $(SolutionDir)\packages\RestSharp.105.1.0\lib\{{targetFrameworkNuget}}\RestSharp.dll - ..\packages\RestSharp.105.1.0\lib\{{targetFrameworkNuget}}\RestSharp.dll - ..\..\packages\RestSharp.105.1.0\lib\{{targetFrameworkNuget}}\RestSharp.dll - {{binRelativePath}}\RestSharp.105.1.0\lib\{{targetFrameworkNuget}}\RestSharp.dll + $(SolutionDir)\packages\RestSharp.105.1.0\lib\{{#isNet40}}net4{{/isNet40}}{{^isNet40}}{{targetFrameworkNuget}}{{/isNet40}}\RestSharp.dll + ..\packages\RestSharp.105.1.0\lib\{{#isNet40}}net4{{/isNet40}}{{^isNet40}}{{targetFrameworkNuget}}{{/isNet40}}\RestSharp.dll + ..\..\packages\RestSharp.105.1.0\lib\{{#isNet40}}net4{{/isNet40}}{{^isNet40}}{{targetFrameworkNuget}}{{/isNet40}}\RestSharp.dll + {{binRelativePath}}\RestSharp.105.1.0\lib\{{#isNet40}}net4{{/isNet40}}{{^isNet40}}{{targetFrameworkNuget}}{{/isNet40}}\RestSharp.dll {{#generatePropertyChanged}} diff --git a/modules/swagger-codegen/src/main/resources/csharp/ReadOnlyDictionary.mustache b/modules/swagger-codegen/src/main/resources/csharp/ReadOnlyDictionary.mustache new file mode 100644 index 00000000000..1299b2436be --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/csharp/ReadOnlyDictionary.mustache @@ -0,0 +1,137 @@ +{{>partial_header}} +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace {{packageName}}.Client +{ + public class ReadOnlyDictionary : IDictionary + { + private IDictionary _dictionaryImplementation; + public IEnumerator> GetEnumerator() + { + return _dictionaryImplementation.GetEnumerator(); + } + + public ReadOnlyDictionary() + { + _dictionaryImplementation = new Dictionary(); + } + + public ReadOnlyDictionary(IDictionary dictionaryImplementation) + { + if (dictionaryImplementation == null) throw new ArgumentNullException("dictionaryImplementation"); + _dictionaryImplementation = dictionaryImplementation; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable) _dictionaryImplementation).GetEnumerator(); + } + + public void Add(KeyValuePair item) + { + throw new ReadonlyOperationException("This instance is readonly."); + } + + public void Clear() + { + throw new ReadonlyOperationException("This instance is readonly."); + } + + public bool Contains(KeyValuePair item) + { + return _dictionaryImplementation.Contains(item); + } + + public void CopyTo(KeyValuePair[] array, int arrayIndex) + { + _dictionaryImplementation.CopyTo(array, arrayIndex); + } + + public bool Remove(KeyValuePair item) + { + throw new ReadonlyOperationException("This instance is readonly."); + } + + public int Count + { + get { return _dictionaryImplementation.Count; } + } + + public bool IsReadOnly + { + get { return true; } + } + + public void Add(T key, K value) + { + throw new ReadonlyOperationException("This instance is readonly."); + } + + public bool ContainsKey(T key) + { + return _dictionaryImplementation.ContainsKey(key); + } + + public bool Remove(T key) + { + throw new ReadonlyOperationException("This instance is readonly."); + } + + public bool TryGetValue(T key, out K value) + { + return _dictionaryImplementation.TryGetValue(key, out value); + } + + public K this[T key] + { + get { return _dictionaryImplementation[key]; } + set + { + throw new ReadonlyOperationException("This instance is readonly."); + + } + } + + public ICollection Keys + { + get { return _dictionaryImplementation.Keys; } + } + + public ICollection Values + { + get { return _dictionaryImplementation.Values; } + } + } + + [Serializable] + public class ReadonlyOperationException : Exception + { + // + // For guidelines regarding the creation of new exception types, see + // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp + // and + // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp + // + + public ReadonlyOperationException() + { + } + + public ReadonlyOperationException(string message) : base(message) + { + } + + public ReadonlyOperationException(string message, Exception inner) : base(message, inner) + { + } + + protected ReadonlyOperationException( + SerializationInfo info, + StreamingContext context) : base(info, context) + { + } + } +} diff --git a/modules/swagger-codegen/src/main/resources/csharp/TestProject.mustache b/modules/swagger-codegen/src/main/resources/csharp/TestProject.mustache index ee8897d2a62..eee304c3368 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/TestProject.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/TestProject.mustache @@ -65,10 +65,10 @@ {{binRelativePath}}\Newtonsoft.Json.10.0.3\lib\{{targetFrameworkNuget}}\Newtonsoft.Json.dll - $(SolutionDir)\packages\RestSharp.105.1.0\lib\{{targetFrameworkNuget}}\RestSharp.dll - ..\packages\RestSharp.105.1.0\lib\{{targetFrameworkNuget}}\RestSharp.dll - ..\..\packages\RestSharp.105.1.0\lib\{{targetFrameworkNuget}}\RestSharp.dll - {{binRelativePath}}\RestSharp.105.1.0\lib\{{targetFrameworkNuget}}\RestSharp.dll + $(SolutionDir)\packages\RestSharp.105.1.0\lib\{{#isNet40}}net4{{/isNet40}}{{^isNet40}}{{targetFrameworkNuget}}{{/isNet40}}\RestSharp.dll + ..\packages\RestSharp.105.1.0\lib\{{#isNet40}}net4{{/isNet40}}{{^isNet40}}{{targetFrameworkNuget}}{{/isNet40}}\RestSharp.dll + ..\..\packages\RestSharp.105.1.0\lib\{{#isNet40}}net4{{/isNet40}}{{^isNet40}}{{targetFrameworkNuget}}{{/isNet40}}\RestSharp.dll + {{binRelativePath}}\RestSharp.105.1.0\lib\{{#isNet40}}net4{{/isNet40}}{{^isNet40}}{{targetFrameworkNuget}}{{/isNet40}}\RestSharp.dll $(SolutionDir)\packages\NUnit.2.6.4\lib\nunit.framework.dll diff --git a/modules/swagger-codegen/src/main/resources/csharp/compile-mono.sh.mustache b/modules/swagger-codegen/src/main/resources/csharp/compile-mono.sh.mustache index 91fe1d8b323..7f7ab50e5cc 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/compile-mono.sh.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/compile-mono.sh.mustache @@ -4,18 +4,47 @@ # frameworkVersion={{targetFrameworkNuget}} -netfx=${frameworkVersion#net} + +# sdk must match installed framworks under PREFIX/lib/mono/[value] +sdk={{x-mcs-sdk}} + +# langversion refers to C# language features. see man mcs for details. +langversion=${sdk} +nuget_cmd=nuget + +# Match against our known SDK possibilities +case "${sdk}" in + 4) + langversion=4 + ;; + 4.5*) + langversion=5 + ;; + 4.6*) + langversion=6 + ;; + 4.7*) + langversion=7 # ignoring 7.1 for now. + ;; + *) + langversion=6 + ;; +esac echo "[INFO] Target framework: ${frameworkVersion}" -echo "[INFO] Download nuget and packages" -wget -nc https://dist.nuget.org/win-x86-commandline/latest/nuget.exe; +if [ ! type nuget &>/dev/null ]; then + echo "[INFO] Download nuget and packages" + wget -nc https://dist.nuget.org/win-x86-commandline/latest/nuget.exe; + nuget_cmd="mono nuget" +fi + mozroots --import --sync -mono nuget.exe install src/{{packageName}}/packages.config -o packages; +${nuget_cmd} install src/{{packageName}}/packages.config -o packages; echo "[INFO] Copy DLLs to the 'bin' folder" mkdir -p bin; -cp packages/Newtonsoft.Json.{{#isNet40}}4.5.11{{/isNet40}}{{^isNet40}}10.0.3{{/isNet40}}/lib/{{targetFrameworkNuget}}/Newtonsoft.Json.dll bin/Newtonsoft.Json.dll; +cp packages/Newtonsoft.Json.10.0.3/lib/{{targetFrameworkNuget}}/Newtonsoft.Json.dll bin/Newtonsoft.Json.dll; cp packages/RestSharp.105.1.0/lib/{{#isNet40}}net4{{/isNet40}}{{^isNet40}}{{targetFrameworkNuget}}{{/isNet40}}/RestSharp.dll bin/RestSharp.dll; {{#generatePropertyChanged}} cp packages/Fody.1.29.4/Fody.dll bin/Fody.dll @@ -24,7 +53,7 @@ cp packages/PropertyChanged.Fody.1.51.3/Lib/dotnet/PropertyChanged.dll bin/Prope {{/generatePropertyChanged}} echo "[INFO] Run 'mcs' to build bin/{{{packageName}}}.dll" -mcs -sdk:${netfx} -r:bin/Newtonsoft.Json.dll,\ +mcs -langversion:${langversion} -sdk:${sdk} -r:bin/Newtonsoft.Json.dll,\ {{#generatePropertyChanged}} bin/Fody.dll,\ bin/PropertyChanged.Fody.dll,\ diff --git a/modules/swagger-codegen/src/main/resources/csharp/gitignore.mustache b/modules/swagger-codegen/src/main/resources/csharp/gitignore.mustache index d3f4f7b6f55..17302c93bf0 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/gitignore.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/gitignore.mustache @@ -6,6 +6,7 @@ *.suo *.user *.sln.docstates +./nuget # Build results diff --git a/modules/swagger-codegen/src/main/resources/csharp/packages.config.mustache b/modules/swagger-codegen/src/main/resources/csharp/packages.config.mustache index feb72290656..e4c40355533 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/packages.config.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/packages.config.mustache @@ -1,7 +1,7 @@ - - + + {{#generatePropertyChanged}} diff --git a/modules/swagger-codegen/src/main/resources/csharp/packages_test.config.mustache b/modules/swagger-codegen/src/main/resources/csharp/packages_test.config.mustache index 8e102af48aa..661dbac94c0 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/packages_test.config.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/packages_test.config.mustache @@ -1,6 +1,6 @@ - - + + diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/csharp/CSharpClientOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/csharp/CSharpClientOptionsTest.java index 1aa3abc4c54..2d2861d0475 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/csharp/CSharpClientOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/csharp/CSharpClientOptionsTest.java @@ -60,6 +60,8 @@ protected void setExpectations() { times = 1; clientCodegen.setModelPropertyNaming(CSharpClientOptionsProvider.MODEL_PROPERTY_NAMING); times = 1; + clientCodegen.setValidatable(true); + times = 1; }}; } } diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/CSharpClientOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/CSharpClientOptionsProvider.java index 8e3bf9869d9..8df7488e051 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/CSharpClientOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/CSharpClientOptionsProvider.java @@ -42,6 +42,7 @@ public Map createOptions() { .put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE) .put(CodegenConstants.NETCORE_PROJECT_FILE, "false") .put(CodegenConstants.MODEL_PROPERTY_NAMING, MODEL_PROPERTY_NAMING) + .put(CodegenConstants.VALIDATABLE, "true") .build(); } diff --git a/samples/client/petstore/csharp/SwaggerClient/.gitignore b/samples/client/petstore/csharp/SwaggerClient/.gitignore index d3f4f7b6f55..17302c93bf0 100644 --- a/samples/client/petstore/csharp/SwaggerClient/.gitignore +++ b/samples/client/petstore/csharp/SwaggerClient/.gitignore @@ -6,6 +6,7 @@ *.suo *.user *.sln.docstates +./nuget # Build results diff --git a/samples/client/petstore/csharp/SwaggerClient/README.md b/samples/client/petstore/csharp/SwaggerClient/README.md index 257d9c889f2..8257b6b39dc 100644 --- a/samples/client/petstore/csharp/SwaggerClient/README.md +++ b/samples/client/petstore/csharp/SwaggerClient/README.md @@ -102,6 +102,7 @@ Class | Method | HTTP request | Description *FakeApi* | [**TestClientModel**](docs/FakeApi.md#testclientmodel) | **PATCH** /fake | To test \"client\" model *FakeApi* | [**TestEndpointParameters**](docs/FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 *FakeApi* | [**TestEnumParameters**](docs/FakeApi.md#testenumparameters) | **GET** /fake | To test enum parameters +*FakeApi* | [**TestInlineAdditionalProperties**](docs/FakeApi.md#testinlineadditionalproperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties *FakeApi* | [**TestJsonFormData**](docs/FakeApi.md#testjsonformdata) | **GET** /fake/jsonFormData | test json serialization of form data *FakeClassnameTags123Api* | [**TestClassname**](docs/FakeClassnameTags123Api.md#testclassname) | **PATCH** /fake_classname_test | To test class name in snake case *PetApi* | [**AddPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store diff --git a/samples/client/petstore/csharp/SwaggerClient/build.sh b/samples/client/petstore/csharp/SwaggerClient/build.sh index ce37b66b21c..4892f3c07ea 100644 --- a/samples/client/petstore/csharp/SwaggerClient/build.sh +++ b/samples/client/petstore/csharp/SwaggerClient/build.sh @@ -4,14 +4,43 @@ # frameworkVersion=net45 -netfx=${frameworkVersion#net} + +# sdk must match installed framworks under PREFIX/lib/mono/[value] +sdk=4.5.2-api + +# langversion refers to C# language features. see man mcs for details. +langversion=${sdk} +nuget_cmd=nuget + +# Match against our known SDK possibilities +case "${sdk}" in + 4) + langversion=4 + ;; + 4.5*) + langversion=5 + ;; + 4.6*) + langversion=6 + ;; + 4.7*) + langversion=7 # ignoring 7.1 for now. + ;; + *) + langversion=6 + ;; +esac echo "[INFO] Target framework: ${frameworkVersion}" -echo "[INFO] Download nuget and packages" -wget -nc https://dist.nuget.org/win-x86-commandline/latest/nuget.exe; +if [ ! type nuget &>/dev/null ]; then + echo "[INFO] Download nuget and packages" + wget -nc https://dist.nuget.org/win-x86-commandline/latest/nuget.exe; + nuget_cmd="mono nuget" +fi + mozroots --import --sync -mono nuget.exe install src/IO.Swagger/packages.config -o packages; +${nuget_cmd} install src/IO.Swagger/packages.config -o packages; echo "[INFO] Copy DLLs to the 'bin' folder" mkdir -p bin; @@ -19,7 +48,7 @@ cp packages/Newtonsoft.Json.10.0.3/lib/net45/Newtonsoft.Json.dll bin/Newtonsoft. cp packages/RestSharp.105.1.0/lib/net45/RestSharp.dll bin/RestSharp.dll; echo "[INFO] Run 'mcs' to build bin/IO.Swagger.dll" -mcs -sdk:${netfx} -r:bin/Newtonsoft.Json.dll,\ +mcs -langversion:${langversion} -sdk:${sdk} -r:bin/Newtonsoft.Json.dll,\ bin/RestSharp.dll,\ System.ComponentModel.DataAnnotations.dll,\ System.Runtime.Serialization.dll \ diff --git a/samples/client/petstore/csharp/SwaggerClient/docs/FakeApi.md b/samples/client/petstore/csharp/SwaggerClient/docs/FakeApi.md index 8052cf14b72..bfc6bc81324 100644 --- a/samples/client/petstore/csharp/SwaggerClient/docs/FakeApi.md +++ b/samples/client/petstore/csharp/SwaggerClient/docs/FakeApi.md @@ -11,6 +11,7 @@ Method | HTTP request | Description [**TestClientModel**](FakeApi.md#testclientmodel) | **PATCH** /fake | To test \"client\" model [**TestEndpointParameters**](FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 [**TestEnumParameters**](FakeApi.md#testenumparameters) | **GET** /fake | To test enum parameters +[**TestInlineAdditionalProperties**](FakeApi.md#testinlineadditionalproperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties [**TestJsonFormData**](FakeApi.md#testjsonformdata) | **GET** /fake/jsonFormData | test json serialization of form data @@ -342,10 +343,10 @@ namespace Example Configuration.Default.Password = "YOUR_PASSWORD"; var apiInstance = new FakeApi(); - var number = 3.4; // decimal? | None + var number = 8.14; // decimal? | None var _double = 1.2; // double? | None var patternWithoutDelimiter = patternWithoutDelimiter_example; // string | None - var _byte = _byte_example; // byte[] | None + var _byte = B; // byte[] | None var integer = 56; // int? | None (optional) var int32 = 56; // int? | None (optional) var int64 = 789; // long? | None (optional) @@ -479,14 +480,70 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **TestInlineAdditionalProperties** +> void TestInlineAdditionalProperties (Object param) + +test inline additionalProperties + +### Example +```csharp +using System; +using System.Diagnostics; +using IO.Swagger.Api; +using IO.Swagger.Client; +using IO.Swagger.Model; + +namespace Example +{ + public class TestInlineAdditionalPropertiesExample + { + public void main() + { + var apiInstance = new FakeApi(); + var param = ; // Object | request body + + try + { + // test inline additionalProperties + apiInstance.TestInlineAdditionalProperties(param); + } + catch (Exception e) + { + Debug.Print("Exception when calling FakeApi.TestInlineAdditionalProperties: " + e.Message ); + } + } + } +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **param** | **Object**| request body | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **TestJsonFormData** > void TestJsonFormData (string param, string param2) test json serialization of form data - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClient/docs/PetApi.md b/samples/client/petstore/csharp/SwaggerClient/docs/PetApi.md index 6b6450a12ab..8654c43e51a 100644 --- a/samples/client/petstore/csharp/SwaggerClient/docs/PetApi.md +++ b/samples/client/petstore/csharp/SwaggerClient/docs/PetApi.md @@ -20,8 +20,6 @@ Method | HTTP request | Description Add a new pet to the store - - ### Example ```csharp using System; @@ -83,8 +81,6 @@ void (empty response body) Deletes a pet - - ### Example ```csharp using System; @@ -342,8 +338,6 @@ Name | Type | Description | Notes Update an existing pet - - ### Example ```csharp using System; @@ -405,8 +399,6 @@ void (empty response body) Updates a pet in the store with form data - - ### Example ```csharp using System; @@ -472,8 +464,6 @@ void (empty response body) uploads an image - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClient/docs/StoreApi.md b/samples/client/petstore/csharp/SwaggerClient/docs/StoreApi.md index 113032c257b..28e3fe59067 100644 --- a/samples/client/petstore/csharp/SwaggerClient/docs/StoreApi.md +++ b/samples/client/petstore/csharp/SwaggerClient/docs/StoreApi.md @@ -199,8 +199,6 @@ No authorization required Place an order for a pet - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClient/docs/UserApi.md b/samples/client/petstore/csharp/SwaggerClient/docs/UserApi.md index 0ddde3f669c..fd9bfb0e973 100644 --- a/samples/client/petstore/csharp/SwaggerClient/docs/UserApi.md +++ b/samples/client/petstore/csharp/SwaggerClient/docs/UserApi.md @@ -80,8 +80,6 @@ No authorization required Creates list of users with given input array - - ### Example ```csharp using System; @@ -140,8 +138,6 @@ No authorization required Creates list of users with given input array - - ### Example ```csharp using System; @@ -260,8 +256,6 @@ No authorization required Get user by user name - - ### Example ```csharp using System; @@ -321,8 +315,6 @@ No authorization required Logs user into the system - - ### Example ```csharp using System; @@ -384,8 +376,6 @@ No authorization required Logs out current logged in user session - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/FakeApi.cs b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/FakeApi.cs index d74183aa9ee..06c068c026a 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/FakeApi.cs @@ -212,6 +212,27 @@ public interface IFakeApi : IApiAccessor /// ApiResponse of Object(void) ApiResponse TestEnumParametersWithHttpInfo (List enumFormStringArray = null, string enumFormString = null, List enumHeaderStringArray = null, string enumHeaderString = null, List enumQueryStringArray = null, string enumQueryString = null, int? enumQueryInteger = null, double? enumQueryDouble = null); /// + /// test inline additionalProperties + /// + /// + /// + /// + /// Thrown when fails to make API call + /// request body + /// + void TestInlineAdditionalProperties (Object param); + + /// + /// test inline additionalProperties + /// + /// + /// + /// + /// Thrown when fails to make API call + /// request body + /// ApiResponse of Object(void) + ApiResponse TestInlineAdditionalPropertiesWithHttpInfo (Object param); + /// /// test json serialization of form data /// /// @@ -424,6 +445,27 @@ public interface IFakeApi : IApiAccessor /// Task of ApiResponse System.Threading.Tasks.Task> TestEnumParametersAsyncWithHttpInfo (List enumFormStringArray = null, string enumFormString = null, List enumHeaderStringArray = null, string enumHeaderString = null, List enumQueryStringArray = null, string enumQueryString = null, int? enumQueryInteger = null, double? enumQueryDouble = null); /// + /// test inline additionalProperties + /// + /// + /// + /// + /// Thrown when fails to make API call + /// request body + /// Task of void + System.Threading.Tasks.Task TestInlineAdditionalPropertiesAsync (Object param); + + /// + /// test inline additionalProperties + /// + /// + /// + /// + /// Thrown when fails to make API call + /// request body + /// Task of ApiResponse + System.Threading.Tasks.Task> TestInlineAdditionalPropertiesAsyncWithHttpInfo (Object param); + /// /// test json serialization of form data /// /// @@ -1665,6 +1707,151 @@ public async System.Threading.Tasks.Task> TestEnumParameters null); } + /// + /// test inline additionalProperties + /// + /// Thrown when fails to make API call + /// request body + /// + public void TestInlineAdditionalProperties (Object param) + { + TestInlineAdditionalPropertiesWithHttpInfo(param); + } + + /// + /// test inline additionalProperties + /// + /// Thrown when fails to make API call + /// request body + /// ApiResponse of Object(void) + public ApiResponse TestInlineAdditionalPropertiesWithHttpInfo (Object param) + { + // verify the required parameter 'param' is set + if (param == null) + throw new ApiException(400, "Missing required parameter 'param' when calling FakeApi->TestInlineAdditionalProperties"); + + var localVarPath = "/fake/inline-additionalProperties"; + var localVarPathParams = new Dictionary(); + var localVarQueryParams = new List>(); + var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); + var localVarFormParams = new Dictionary(); + var localVarFileParams = new Dictionary(); + Object localVarPostBody = null; + + // to determine the Content-Type header + String[] localVarHttpContentTypes = new String[] { + "application/json" + }; + String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); + + // to determine the Accept header + String[] localVarHttpHeaderAccepts = new String[] { + }; + String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); + if (localVarHttpHeaderAccept != null) + localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); + + if (param != null && param.GetType() != typeof(byte[])) + { + localVarPostBody = Configuration.ApiClient.Serialize(param); // http body (model) parameter + } + else + { + localVarPostBody = param; // byte array + } + + + // make the HTTP request + IRestResponse localVarResponse = (IRestResponse) Configuration.ApiClient.CallApi(localVarPath, + Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + localVarPathParams, localVarHttpContentType); + + int localVarStatusCode = (int) localVarResponse.StatusCode; + + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestInlineAdditionalProperties", localVarResponse); + if (exception != null) throw exception; + } + + return new ApiResponse(localVarStatusCode, + localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), + null); + } + + /// + /// test inline additionalProperties + /// + /// Thrown when fails to make API call + /// request body + /// Task of void + public async System.Threading.Tasks.Task TestInlineAdditionalPropertiesAsync (Object param) + { + await TestInlineAdditionalPropertiesAsyncWithHttpInfo(param); + + } + + /// + /// test inline additionalProperties + /// + /// Thrown when fails to make API call + /// request body + /// Task of ApiResponse + public async System.Threading.Tasks.Task> TestInlineAdditionalPropertiesAsyncWithHttpInfo (Object param) + { + // verify the required parameter 'param' is set + if (param == null) + throw new ApiException(400, "Missing required parameter 'param' when calling FakeApi->TestInlineAdditionalProperties"); + + var localVarPath = "/fake/inline-additionalProperties"; + var localVarPathParams = new Dictionary(); + var localVarQueryParams = new List>(); + var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); + var localVarFormParams = new Dictionary(); + var localVarFileParams = new Dictionary(); + Object localVarPostBody = null; + + // to determine the Content-Type header + String[] localVarHttpContentTypes = new String[] { + "application/json" + }; + String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); + + // to determine the Accept header + String[] localVarHttpHeaderAccepts = new String[] { + }; + String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); + if (localVarHttpHeaderAccept != null) + localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); + + if (param != null && param.GetType() != typeof(byte[])) + { + localVarPostBody = Configuration.ApiClient.Serialize(param); // http body (model) parameter + } + else + { + localVarPostBody = param; // byte array + } + + + // make the HTTP request + IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, + Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + localVarPathParams, localVarHttpContentType); + + int localVarStatusCode = (int) localVarResponse.StatusCode; + + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestInlineAdditionalProperties", localVarResponse); + if (exception != null) throw exception; + } + + return new ApiResponse(localVarStatusCode, + localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), + null); + } + /// /// test json serialization of form data /// diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/ApiClient.cs b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/ApiClient.cs index 51042091e7d..da0d7101975 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/ApiClient.cs @@ -139,7 +139,7 @@ private RestRequest PrepareRequest( if (postBody != null) // http body (model or byte[]) parameter { - request.AddParameter(contentType, postBody, ParameterType.RequestBody); + request.AddParameter(contentType, postBody, ParameterType.RequestBody); } return request; @@ -347,18 +347,18 @@ public String Serialize(object obj) /// ///Check if the given MIME is a JSON MIME. ///JSON MIME examples: - /// application/json + /// application/json /// application/json; charset=UTF8 /// APPLICATION/JSON /// application/vnd.company+json /// /// MIME - /// Returns True if MIME type is json. + /// Returns True if MIME type is json. public bool IsJsonMime(String mime) { var jsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"); - return mime != null && (jsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json", StringComparison.InvariantCultureIgnoreCase)); - } + return mime != null && (jsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json")); + } /// /// Select the Content-Type header's value from the given content-type array: @@ -374,7 +374,7 @@ public String SelectHeaderContentType(String[] contentTypes) foreach (var contentType in contentTypes) { - if (IsJsonMime(contentType)) + if (IsJsonMime(contentType.ToLower())) return contentType; } diff --git a/samples/client/petstore/csharp/SwaggerClientNet40/.gitignore b/samples/client/petstore/csharp/SwaggerClientNet40/.gitignore index d3f4f7b6f55..17302c93bf0 100644 --- a/samples/client/petstore/csharp/SwaggerClientNet40/.gitignore +++ b/samples/client/petstore/csharp/SwaggerClientNet40/.gitignore @@ -6,6 +6,7 @@ *.suo *.user *.sln.docstates +./nuget # Build results diff --git a/samples/client/petstore/csharp/SwaggerClientNet40/build.sh b/samples/client/petstore/csharp/SwaggerClientNet40/build.sh index 838fd258d52..0a0213f1828 100644 --- a/samples/client/petstore/csharp/SwaggerClientNet40/build.sh +++ b/samples/client/petstore/csharp/SwaggerClientNet40/build.sh @@ -4,22 +4,51 @@ # frameworkVersion=net40 -netfx=${frameworkVersion#net} + +# sdk must match installed framworks under PREFIX/lib/mono/[value] +sdk=4 + +# langversion refers to C# language features. see man mcs for details. +langversion=${sdk} +nuget_cmd=nuget + +# Match against our known SDK possibilities +case "${sdk}" in + 4) + langversion=4 + ;; + 4.5*) + langversion=5 + ;; + 4.6*) + langversion=6 + ;; + 4.7*) + langversion=7 # ignoring 7.1 for now. + ;; + *) + langversion=6 + ;; +esac echo "[INFO] Target framework: ${frameworkVersion}" -echo "[INFO] Download nuget and packages" -wget -nc https://dist.nuget.org/win-x86-commandline/latest/nuget.exe; +if [ ! type nuget &>/dev/null ]; then + echo "[INFO] Download nuget and packages" + wget -nc https://dist.nuget.org/win-x86-commandline/latest/nuget.exe; + nuget_cmd="mono nuget" +fi + mozroots --import --sync -mono nuget.exe install src/IO.Swagger/packages.config -o packages; +${nuget_cmd} install src/IO.Swagger/packages.config -o packages; echo "[INFO] Copy DLLs to the 'bin' folder" mkdir -p bin; -cp packages/Newtonsoft.Json.4.5.11/lib/net40/Newtonsoft.Json.dll bin/Newtonsoft.Json.dll; +cp packages/Newtonsoft.Json.10.0.3/lib/net40/Newtonsoft.Json.dll bin/Newtonsoft.Json.dll; cp packages/RestSharp.105.1.0/lib/net4/RestSharp.dll bin/RestSharp.dll; echo "[INFO] Run 'mcs' to build bin/IO.Swagger.dll" -mcs -sdk:${netfx} -r:bin/Newtonsoft.Json.dll,\ +mcs -langversion:${langversion} -sdk:${sdk} -r:bin/Newtonsoft.Json.dll,\ bin/RestSharp.dll,\ System.ComponentModel.DataAnnotations.dll,\ System.Runtime.Serialization.dll \ diff --git a/samples/client/petstore/csharp/SwaggerClientNet40/docs/FakeApi.md b/samples/client/petstore/csharp/SwaggerClientNet40/docs/FakeApi.md index 166fc077b26..bfc6bc81324 100644 --- a/samples/client/petstore/csharp/SwaggerClientNet40/docs/FakeApi.md +++ b/samples/client/petstore/csharp/SwaggerClientNet40/docs/FakeApi.md @@ -343,10 +343,10 @@ namespace Example Configuration.Default.Password = "YOUR_PASSWORD"; var apiInstance = new FakeApi(); - var number = 3.4; // decimal? | None + var number = 8.14; // decimal? | None var _double = 1.2; // double? | None var patternWithoutDelimiter = patternWithoutDelimiter_example; // string | None - var _byte = _byte_example; // byte[] | None + var _byte = B; // byte[] | None var integer = 56; // int? | None (optional) var int32 = 56; // int? | None (optional) var int64 = 789; // long? | None (optional) @@ -486,8 +486,6 @@ No authorization required test inline additionalProperties - - ### Example ```csharp using System; @@ -546,8 +544,6 @@ No authorization required test json serialization of form data - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClientNet40/docs/PetApi.md b/samples/client/petstore/csharp/SwaggerClientNet40/docs/PetApi.md index 6b6450a12ab..8654c43e51a 100644 --- a/samples/client/petstore/csharp/SwaggerClientNet40/docs/PetApi.md +++ b/samples/client/petstore/csharp/SwaggerClientNet40/docs/PetApi.md @@ -20,8 +20,6 @@ Method | HTTP request | Description Add a new pet to the store - - ### Example ```csharp using System; @@ -83,8 +81,6 @@ void (empty response body) Deletes a pet - - ### Example ```csharp using System; @@ -342,8 +338,6 @@ Name | Type | Description | Notes Update an existing pet - - ### Example ```csharp using System; @@ -405,8 +399,6 @@ void (empty response body) Updates a pet in the store with form data - - ### Example ```csharp using System; @@ -472,8 +464,6 @@ void (empty response body) uploads an image - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClientNet40/docs/StoreApi.md b/samples/client/petstore/csharp/SwaggerClientNet40/docs/StoreApi.md index 113032c257b..28e3fe59067 100644 --- a/samples/client/petstore/csharp/SwaggerClientNet40/docs/StoreApi.md +++ b/samples/client/petstore/csharp/SwaggerClientNet40/docs/StoreApi.md @@ -199,8 +199,6 @@ No authorization required Place an order for a pet - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClientNet40/docs/UserApi.md b/samples/client/petstore/csharp/SwaggerClientNet40/docs/UserApi.md index 0ddde3f669c..fd9bfb0e973 100644 --- a/samples/client/petstore/csharp/SwaggerClientNet40/docs/UserApi.md +++ b/samples/client/petstore/csharp/SwaggerClientNet40/docs/UserApi.md @@ -80,8 +80,6 @@ No authorization required Creates list of users with given input array - - ### Example ```csharp using System; @@ -140,8 +138,6 @@ No authorization required Creates list of users with given input array - - ### Example ```csharp using System; @@ -260,8 +256,6 @@ No authorization required Get user by user name - - ### Example ```csharp using System; @@ -321,8 +315,6 @@ No authorization required Logs user into the system - - ### Example ```csharp using System; @@ -384,8 +376,6 @@ No authorization required Logs out current logged in user session - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClientNet40/nuget.exe b/samples/client/petstore/csharp/SwaggerClientNet40/nuget.exe deleted file mode 100644 index ec1309c7aa6..00000000000 Binary files a/samples/client/petstore/csharp/SwaggerClientNet40/nuget.exe and /dev/null differ diff --git a/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger.Test/Client/JsonSubTypesTests.cs b/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger.Test/Client/JsonSubTypesTests.cs new file mode 100644 index 00000000000..5da5bc237ad --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger.Test/Client/JsonSubTypesTests.cs @@ -0,0 +1,134 @@ +/* + * Swagger Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + + +using System.Collections.Generic; +using System.Linq; +using JsonSubTypes; +using Newtonsoft.Json; +using NUnit.Framework; + +using IO.Swagger.Api; +using IO.Swagger.Model; +using IO.Swagger.Client; + +namespace IO.Swagger.Test.Client +{ + public class JsonSubTypesTests + { + [Test] + public void TestSimpleJsonSubTypesExample() + { + var annimal = + JsonConvert.DeserializeObject("{\"Kind\":\"Dog\",\"Breed\":\"Jack Russell Terrier\"}"); + Assert.AreEqual("Jack Russell Terrier", (annimal as Dog)?.Breed); + } + + [Test] + public void DeserializeObjectWithCustomMapping() + { + var annimal = + JsonConvert.DeserializeObject("{\"Sound\":\"Bark\",\"Breed\":\"Jack Russell Terrier\"}"); + Assert.AreEqual("Jack Russell Terrier", (annimal as Dog2)?.Breed); + } + + [Test] + public void DeserializeObjectMappingByPropertyPresence() + { + string json = + "[{\"Department\":\"Department1\",\"JobTitle\":\"JobTitle1\",\"FirstName\":\"FirstName1\",\"LastName\":\"LastName1\"}," + + "{\"Department\":\"Department1\",\"JobTitle\":\"JobTitle1\",\"FirstName\":\"FirstName1\",\"LastName\":\"LastName1\"}," + + "{\"Skill\":\"Painter\",\"FirstName\":\"FirstName1\",\"LastName\":\"LastName1\"}]"; + + + var persons = JsonConvert.DeserializeObject>(json); + Assert.AreEqual("Painter", (persons.Last() as Artist)?.Skill); + } + } + + [JsonConverter(typeof(JsonSubtypes), "Kind")] + public interface IAnimal + { + string Kind { get; } + } + + public class Dog : IAnimal + { + public Dog() + { + Kind = "Dog"; + } + + public string Kind { get; } + public string Breed { get; set; } + } + + class Cat : IAnimal + { + public Cat() + { + Kind = "Cat"; + } + + public string Kind { get; } + bool Declawed { get; set; } + } + + [JsonConverter(typeof(JsonSubtypes), "Sound")] + [JsonSubtypes.KnownSubType(typeof(Dog2), "Bark")] + [JsonSubtypes.KnownSubType(typeof(Cat2), "Meow")] + public class Animal2 + { + public virtual string Sound { get; } + public string Color { get; set; } + } + + public class Dog2 : Animal2 + { + public Dog2() + { + Sound = "Bark"; + } + + public override string Sound { get; } + public string Breed { get; set; } + } + + public class Cat2 : Animal2 + { + public Cat2() + { + Sound = "Meow"; + } + + public override string Sound { get; } + public bool Declawed { get; set; } + } + + [JsonConverter(typeof(JsonSubtypes))] + [JsonSubtypes.KnownSubTypeWithProperty(typeof(Employee), "JobTitle")] + [JsonSubtypes.KnownSubTypeWithProperty(typeof(Artist), "Skill")] + public class Person + { + public string FirstName { get; set; } + public string LastName { get; set; } + } + + public class Employee : Person + { + public string Department { get; set; } + public string JobTitle { get; set; } + } + + public class Artist : Person + { + public string Skill { get; set; } + } +} diff --git a/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger.Test/IO.Swagger.Test.csproj b/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger.Test/IO.Swagger.Test.csproj index b1aded9e1a9..0bc4aee06e0 100644 --- a/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger.Test/IO.Swagger.Test.csproj +++ b/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger.Test/IO.Swagger.Test.csproj @@ -53,10 +53,10 @@ Contact: apiteam@swagger.io ..\..\vendor\Newtonsoft.Json.10.0.3\lib\net40\Newtonsoft.Json.dll - $(SolutionDir)\packages\RestSharp.105.1.0\lib\net40\RestSharp.dll - ..\packages\RestSharp.105.1.0\lib\net40\RestSharp.dll - ..\..\packages\RestSharp.105.1.0\lib\net40\RestSharp.dll - ..\..\vendor\RestSharp.105.1.0\lib\net40\RestSharp.dll + $(SolutionDir)\packages\RestSharp.105.1.0\lib\net4\RestSharp.dll + ..\packages\RestSharp.105.1.0\lib\net4\RestSharp.dll + ..\..\packages\RestSharp.105.1.0\lib\net4\RestSharp.dll + ..\..\vendor\RestSharp.105.1.0\lib\net4\RestSharp.dll $(SolutionDir)\packages\NUnit.2.6.4\lib\nunit.framework.dll diff --git a/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger.Test/packages.config b/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger.Test/packages.config index 5d9b19287bc..c01db0f14de 100644 --- a/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger.Test/packages.config +++ b/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger.Test/packages.config @@ -1,6 +1,6 @@ - - + + diff --git a/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/Client/JsonSubTypes.cs b/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/Client/JsonSubTypes.cs index 3a6da091b78..0dd09a25da2 100644 --- a/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/Client/JsonSubTypes.cs +++ b/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/Client/JsonSubTypes.cs @@ -132,7 +132,7 @@ private IList ReadArray(JsonReader reader, Type targetType, JsonSerializer seria private static IList CreateCompatibleList(Type targetContainerType, Type elementType) { IList list; - if (targetContainerType.IsArray || targetContainerType.GetTypeInfo().IsAbstract) + if (targetContainerType.IsArray || targetContainerType.IsAbstract) { list = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType)); } @@ -152,7 +152,7 @@ private static Type GetElementType(Type arrayOrGenericContainer) } else { - elementType = arrayOrGenericContainer.GenericTypeArguments[0]; + elementType = arrayOrGenericContainer.GetGenericArguments().FirstOrDefault(); } return elementType; } @@ -190,7 +190,7 @@ public Type GetType(JObject jObject, Type parentType) private static Type GetTypeByPropertyPresence(JObject jObject, Type parentType) { - foreach (var type in parentType.GetTypeInfo().GetCustomAttributes()) + foreach (var type in parentType.GetCustomAttributes(false).OfType()) { JToken ignore; if (jObject.TryGetValue(type.PropertyName, out ignore)) @@ -222,7 +222,7 @@ private static Type GetTypeByName(string typeName, Type parentType) if (typeName == null) return null; - var insideAssembly = parentType.GetTypeInfo().Assembly; + var insideAssembly = parentType.Assembly; var typeByName = insideAssembly.GetType(typeName); if (typeByName == null) @@ -233,7 +233,7 @@ private static Type GetTypeByName(string typeName, Type parentType) return typeByName; } - private static Type GetTypeFromMapping(IReadOnlyDictionary typeMapping, object discriminatorValue) + private static Type GetTypeFromMapping(IDictionary typeMapping, object discriminatorValue) { var targetlookupValueType = typeMapping.First().Key.GetType(); var lookupValue = ConvertJsonValueToType(discriminatorValue, targetlookupValueType); @@ -244,12 +244,12 @@ private static Type GetTypeFromMapping(IReadOnlyDictionary typeMap private static Dictionary GetSubTypeMapping(Type type) { - return type.GetTypeInfo().GetCustomAttributes().ToDictionary(x => x.AssociatedValue, x => x.SubType); + return type.GetCustomAttributes(false).OfType().ToDictionary(x => x.AssociatedValue, x => x.SubType); } private static object ConvertJsonValueToType(object objectType, Type targetlookupValueType) { - if (targetlookupValueType.GetTypeInfo().IsEnum) + if (targetlookupValueType.IsEnum) return Enum.ToObject(targetlookupValueType, objectType); return Convert.ChangeType(objectType, targetlookupValueType); diff --git a/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/Client/ReadOnlyDictionary.cs b/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/Client/ReadOnlyDictionary.cs new file mode 100644 index 00000000000..541a058fc86 --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/Client/ReadOnlyDictionary.cs @@ -0,0 +1,146 @@ +/* + * Swagger Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace IO.Swagger.Client +{ + public class ReadOnlyDictionary : IDictionary + { + private IDictionary _dictionaryImplementation; + public IEnumerator> GetEnumerator() + { + return _dictionaryImplementation.GetEnumerator(); + } + + public ReadOnlyDictionary() + { + _dictionaryImplementation = new Dictionary(); + } + + public ReadOnlyDictionary(IDictionary dictionaryImplementation) + { + if (dictionaryImplementation == null) throw new ArgumentNullException("dictionaryImplementation"); + _dictionaryImplementation = dictionaryImplementation; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable) _dictionaryImplementation).GetEnumerator(); + } + + public void Add(KeyValuePair item) + { + throw new ReadonlyOperationException("This instance is readonly."); + } + + public void Clear() + { + throw new ReadonlyOperationException("This instance is readonly."); + } + + public bool Contains(KeyValuePair item) + { + return _dictionaryImplementation.Contains(item); + } + + public void CopyTo(KeyValuePair[] array, int arrayIndex) + { + _dictionaryImplementation.CopyTo(array, arrayIndex); + } + + public bool Remove(KeyValuePair item) + { + throw new ReadonlyOperationException("This instance is readonly."); + } + + public int Count + { + get { return _dictionaryImplementation.Count; } + } + + public bool IsReadOnly + { + get { return true; } + } + + public void Add(T key, K value) + { + throw new ReadonlyOperationException("This instance is readonly."); + } + + public bool ContainsKey(T key) + { + return _dictionaryImplementation.ContainsKey(key); + } + + public bool Remove(T key) + { + throw new ReadonlyOperationException("This instance is readonly."); + } + + public bool TryGetValue(T key, out K value) + { + return _dictionaryImplementation.TryGetValue(key, out value); + } + + public K this[T key] + { + get { return _dictionaryImplementation[key]; } + set + { + throw new ReadonlyOperationException("This instance is readonly."); + + } + } + + public ICollection Keys + { + get { return _dictionaryImplementation.Keys; } + } + + public ICollection Values + { + get { return _dictionaryImplementation.Values; } + } + } + + [Serializable] + public class ReadonlyOperationException : Exception + { + // + // For guidelines regarding the creation of new exception types, see + // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp + // and + // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp + // + + public ReadonlyOperationException() + { + } + + public ReadonlyOperationException(string message) : base(message) + { + } + + public ReadonlyOperationException(string message, Exception inner) : base(message, inner) + { + } + + protected ReadonlyOperationException( + SerializationInfo info, + StreamingContext context) : base(info, context) + { + } + } +} diff --git a/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/IO.Swagger.csproj b/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/IO.Swagger.csproj index fe43f0d9e52..626d37afe39 100644 --- a/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/IO.Swagger.csproj +++ b/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/IO.Swagger.csproj @@ -54,10 +54,10 @@ Contact: apiteam@swagger.io ..\..\vendor\Newtonsoft.Json.10.0.3\lib\net40\Newtonsoft.Json.dll - $(SolutionDir)\packages\RestSharp.105.1.0\lib\net40\RestSharp.dll - ..\packages\RestSharp.105.1.0\lib\net40\RestSharp.dll - ..\..\packages\RestSharp.105.1.0\lib\net40\RestSharp.dll - ..\..\vendor\RestSharp.105.1.0\lib\net40\RestSharp.dll + $(SolutionDir)\packages\RestSharp.105.1.0\lib\net4\RestSharp.dll + ..\packages\RestSharp.105.1.0\lib\net4\RestSharp.dll + ..\..\packages\RestSharp.105.1.0\lib\net4\RestSharp.dll + ..\..\vendor\RestSharp.105.1.0\lib\net4\RestSharp.dll diff --git a/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/packages.config b/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/packages.config index b464072993f..3783fcf1985 100644 --- a/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/packages.config +++ b/samples/client/petstore/csharp/SwaggerClientNet40/src/IO.Swagger/packages.config @@ -1,5 +1,5 @@ - - + + diff --git a/samples/client/petstore/csharp/SwaggerClientNetStandard/.gitignore b/samples/client/petstore/csharp/SwaggerClientNetStandard/.gitignore index d3f4f7b6f55..17302c93bf0 100644 --- a/samples/client/petstore/csharp/SwaggerClientNetStandard/.gitignore +++ b/samples/client/petstore/csharp/SwaggerClientNetStandard/.gitignore @@ -6,6 +6,7 @@ *.suo *.user *.sln.docstates +./nuget # Build results diff --git a/samples/client/petstore/csharp/SwaggerClientNetStandard/README.md b/samples/client/petstore/csharp/SwaggerClientNetStandard/README.md index a153e0e12e4..5efd0ff674e 100644 --- a/samples/client/petstore/csharp/SwaggerClientNetStandard/README.md +++ b/samples/client/petstore/csharp/SwaggerClientNetStandard/README.md @@ -48,17 +48,18 @@ namespace Example public void main() { - var apiInstance = new FakeApi(); - var body = new OuterBoolean(); // OuterBoolean | Input boolean as post body (optional) + var apiInstance = new AnotherFakeApi(); + var body = new ModelClient(); // ModelClient | client model try { - OuterBoolean result = apiInstance.FakeOuterBooleanSerialize(body); + // To test special tags + ModelClient result = apiInstance.TestSpecialTags(body); Debug.WriteLine(result); } catch (Exception e) { - Debug.Print("Exception when calling FakeApi.FakeOuterBooleanSerialize: " + e.Message ); + Debug.Print("Exception when calling AnotherFakeApi.TestSpecialTags: " + e.Message ); } } @@ -73,6 +74,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- +*AnotherFakeApi* | [**TestSpecialTags**](docs/AnotherFakeApi.md#testspecialtags) | **PATCH** /another-fake/dummy | To test special tags *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 | @@ -80,8 +82,9 @@ Class | Method | HTTP request | Description *FakeApi* | [**TestClientModel**](docs/FakeApi.md#testclientmodel) | **PATCH** /fake | To test \"client\" model *FakeApi* | [**TestEndpointParameters**](docs/FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 *FakeApi* | [**TestEnumParameters**](docs/FakeApi.md#testenumparameters) | **GET** /fake | To test enum parameters +*FakeApi* | [**TestInlineAdditionalProperties**](docs/FakeApi.md#testinlineadditionalproperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties *FakeApi* | [**TestJsonFormData**](docs/FakeApi.md#testjsonformdata) | **GET** /fake/jsonFormData | test json serialization of form data -*Fake_classname_tags123Api* | [**TestClassname**](docs/Fake_classname_tags123Api.md#testclassname) | **PATCH** /fake_classname_test | To test class name in snake case +*FakeClassnameTags123Api* | [**TestClassname**](docs/FakeClassnameTags123Api.md#testclassname) | **PATCH** /fake_classname_test | To test class name in snake case *PetApi* | [**AddPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store *PetApi* | [**DeletePet**](docs/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet *PetApi* | [**FindPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status diff --git a/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/AnotherFakeApi.md b/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/AnotherFakeApi.md new file mode 100644 index 00000000000..89bc406754a --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/AnotherFakeApi.md @@ -0,0 +1,70 @@ +# IO.Swagger.Api.AnotherFakeApi + +All URIs are relative to *http://petstore.swagger.io:80/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**TestSpecialTags**](AnotherFakeApi.md#testspecialtags) | **PATCH** /another-fake/dummy | To test special tags + + + +# **TestSpecialTags** +> ModelClient TestSpecialTags (ModelClient body) + +To test special tags + +To test special tags + +### Example +```csharp +using System; +using System.Diagnostics; +using IO.Swagger.Api; +using IO.Swagger.Client; +using IO.Swagger.Model; + +namespace Example +{ + public class TestSpecialTagsExample + { + public void main() + { + var apiInstance = new AnotherFakeApi(); + var body = new ModelClient(); // ModelClient | client model + + try + { + // To test special tags + ModelClient result = apiInstance.TestSpecialTags(body); + Debug.WriteLine(result); + } + catch (Exception e) + { + Debug.Print("Exception when calling AnotherFakeApi.TestSpecialTags: " + e.Message ); + } + } + } +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**ModelClient**](ModelClient.md)| client model | + +### Return type + +[**ModelClient**](ModelClient.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/FakeApi.md b/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/FakeApi.md index 8052cf14b72..bfc6bc81324 100644 --- a/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/FakeApi.md +++ b/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/FakeApi.md @@ -11,6 +11,7 @@ Method | HTTP request | Description [**TestClientModel**](FakeApi.md#testclientmodel) | **PATCH** /fake | To test \"client\" model [**TestEndpointParameters**](FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 [**TestEnumParameters**](FakeApi.md#testenumparameters) | **GET** /fake | To test enum parameters +[**TestInlineAdditionalProperties**](FakeApi.md#testinlineadditionalproperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties [**TestJsonFormData**](FakeApi.md#testjsonformdata) | **GET** /fake/jsonFormData | test json serialization of form data @@ -342,10 +343,10 @@ namespace Example Configuration.Default.Password = "YOUR_PASSWORD"; var apiInstance = new FakeApi(); - var number = 3.4; // decimal? | None + var number = 8.14; // decimal? | None var _double = 1.2; // double? | None var patternWithoutDelimiter = patternWithoutDelimiter_example; // string | None - var _byte = _byte_example; // byte[] | None + var _byte = B; // byte[] | None var integer = 56; // int? | None (optional) var int32 = 56; // int? | None (optional) var int64 = 789; // long? | None (optional) @@ -479,14 +480,70 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **TestInlineAdditionalProperties** +> void TestInlineAdditionalProperties (Object param) + +test inline additionalProperties + +### Example +```csharp +using System; +using System.Diagnostics; +using IO.Swagger.Api; +using IO.Swagger.Client; +using IO.Swagger.Model; + +namespace Example +{ + public class TestInlineAdditionalPropertiesExample + { + public void main() + { + var apiInstance = new FakeApi(); + var param = ; // Object | request body + + try + { + // test inline additionalProperties + apiInstance.TestInlineAdditionalProperties(param); + } + catch (Exception e) + { + Debug.Print("Exception when calling FakeApi.TestInlineAdditionalProperties: " + e.Message ); + } + } + } +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **param** | **Object**| request body | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **TestJsonFormData** > void TestJsonFormData (string param, string param2) test json serialization of form data - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/FakeClassnameTags123Api.md b/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/FakeClassnameTags123Api.md new file mode 100644 index 00000000000..5f1d0ca776b --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/FakeClassnameTags123Api.md @@ -0,0 +1,73 @@ +# IO.Swagger.Api.FakeClassnameTags123Api + +All URIs are relative to *http://petstore.swagger.io:80/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**TestClassname**](FakeClassnameTags123Api.md#testclassname) | **PATCH** /fake_classname_test | To test class name in snake case + + + +# **TestClassname** +> ModelClient TestClassname (ModelClient body) + +To test class name in snake case + +### Example +```csharp +using System; +using System.Diagnostics; +using IO.Swagger.Api; +using IO.Swagger.Client; +using IO.Swagger.Model; + +namespace Example +{ + public class TestClassnameExample + { + public void main() + { + // Configure API key authorization: api_key_query + Configuration.Default.AddApiKey("api_key_query", "YOUR_API_KEY"); + // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed + // Configuration.Default.AddApiKeyPrefix("api_key_query", "Bearer"); + + var apiInstance = new FakeClassnameTags123Api(); + var body = new ModelClient(); // ModelClient | client model + + try + { + // To test class name in snake case + ModelClient result = apiInstance.TestClassname(body); + Debug.WriteLine(result); + } + catch (Exception e) + { + Debug.Print("Exception when calling FakeClassnameTags123Api.TestClassname: " + e.Message ); + } + } + } +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**ModelClient**](ModelClient.md)| client model | + +### Return type + +[**ModelClient**](ModelClient.md) + +### Authorization + +[api_key_query](../README.md#api_key_query) + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/PetApi.md b/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/PetApi.md index 6b6450a12ab..8654c43e51a 100644 --- a/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/PetApi.md +++ b/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/PetApi.md @@ -20,8 +20,6 @@ Method | HTTP request | Description Add a new pet to the store - - ### Example ```csharp using System; @@ -83,8 +81,6 @@ void (empty response body) Deletes a pet - - ### Example ```csharp using System; @@ -342,8 +338,6 @@ Name | Type | Description | Notes Update an existing pet - - ### Example ```csharp using System; @@ -405,8 +399,6 @@ void (empty response body) Updates a pet in the store with form data - - ### Example ```csharp using System; @@ -472,8 +464,6 @@ void (empty response body) uploads an image - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/StoreApi.md b/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/StoreApi.md index 113032c257b..28e3fe59067 100644 --- a/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/StoreApi.md +++ b/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/StoreApi.md @@ -199,8 +199,6 @@ No authorization required Place an order for a pet - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/UserApi.md b/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/UserApi.md index 0ddde3f669c..fd9bfb0e973 100644 --- a/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/UserApi.md +++ b/samples/client/petstore/csharp/SwaggerClientNetStandard/docs/UserApi.md @@ -80,8 +80,6 @@ No authorization required Creates list of users with given input array - - ### Example ```csharp using System; @@ -140,8 +138,6 @@ No authorization required Creates list of users with given input array - - ### Example ```csharp using System; @@ -260,8 +256,6 @@ No authorization required Get user by user name - - ### Example ```csharp using System; @@ -321,8 +315,6 @@ No authorization required Logs user into the system - - ### Example ```csharp using System; @@ -384,8 +376,6 @@ No authorization required Logs out current logged in user session - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Api/AnotherFakeApi.cs b/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Api/AnotherFakeApi.cs new file mode 100644 index 00000000000..fd7f39a2fdd --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Api/AnotherFakeApi.cs @@ -0,0 +1,321 @@ +/* + * Swagger Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using RestSharp.Portable; +using IO.Swagger.Client; +using IO.Swagger.Model; + +namespace IO.Swagger.Api +{ + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public interface IAnotherFakeApi : IApiAccessor + { + #region Synchronous Operations + /// + /// To test special tags + /// + /// + /// To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// ModelClient + ModelClient TestSpecialTags (ModelClient body); + + /// + /// To test special tags + /// + /// + /// To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// ApiResponse of ModelClient + ApiResponse TestSpecialTagsWithHttpInfo (ModelClient body); + #endregion Synchronous Operations + #region Asynchronous Operations + /// + /// To test special tags + /// + /// + /// To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// Task of ModelClient + System.Threading.Tasks.Task TestSpecialTagsAsync (ModelClient body); + + /// + /// To test special tags + /// + /// + /// To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// Task of ApiResponse (ModelClient) + System.Threading.Tasks.Task> TestSpecialTagsAsyncWithHttpInfo (ModelClient body); + #endregion Asynchronous Operations + } + + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public partial class AnotherFakeApi : IAnotherFakeApi + { + private IO.Swagger.Client.ExceptionFactory _exceptionFactory = (name, response) => null; + + /// + /// Initializes a new instance of the class. + /// + /// + public AnotherFakeApi(String basePath) + { + this.Configuration = new Configuration { BasePath = basePath }; + + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + } + + /// + /// Initializes a new instance of the class + /// using Configuration object + /// + /// An instance of Configuration + /// + public AnotherFakeApi(Configuration configuration = null) + { + if (configuration == null) // use the default one in Configuration + this.Configuration = Configuration.Default; + else + this.Configuration = configuration; + + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + } + + /// + /// Gets the base path of the API client. + /// + /// The base path + public String GetBasePath() + { + return this.Configuration.ApiClient.RestClient.BaseUrl.ToString(); + } + + /// + /// Sets the base path of the API client. + /// + /// The base path + [Obsolete("SetBasePath is deprecated, please do 'Configuration.ApiClient = new ApiClient(\"http://new-path\")' instead.")] + public void SetBasePath(String basePath) + { + // do nothing + } + + /// + /// Gets or sets the configuration object + /// + /// An instance of the Configuration + public Configuration Configuration {get; set;} + + /// + /// Provides a factory method hook for the creation of exceptions. + /// + public IO.Swagger.Client.ExceptionFactory ExceptionFactory + { + get + { + if (_exceptionFactory != null && _exceptionFactory.GetInvocationList().Length > 1) + { + throw new InvalidOperationException("Multicast delegate for ExceptionFactory is unsupported."); + } + return _exceptionFactory; + } + set { _exceptionFactory = value; } + } + + /// + /// Gets the default header. + /// + /// Dictionary of HTTP header + [Obsolete("DefaultHeader is deprecated, please use Configuration.DefaultHeader instead.")] + public IDictionary DefaultHeader() + { + return new ReadOnlyDictionary(this.Configuration.DefaultHeader); + } + + /// + /// Add default header. + /// + /// Header field name. + /// Header field value. + /// + [Obsolete("AddDefaultHeader is deprecated, please use Configuration.AddDefaultHeader instead.")] + public void AddDefaultHeader(string key, string value) + { + this.Configuration.AddDefaultHeader(key, value); + } + + /// + /// To test special tags To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// ModelClient + public ModelClient TestSpecialTags (ModelClient body) + { + ApiResponse localVarResponse = TestSpecialTagsWithHttpInfo(body); + return localVarResponse.Data; + } + + /// + /// To test special tags To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// ApiResponse of ModelClient + public ApiResponse< ModelClient > TestSpecialTagsWithHttpInfo (ModelClient body) + { + // verify the required parameter 'body' is set + if (body == null) + throw new ApiException(400, "Missing required parameter 'body' when calling AnotherFakeApi->TestSpecialTags"); + + var localVarPath = "./another-fake/dummy"; + var localVarPathParams = new Dictionary(); + var localVarQueryParams = new List>(); + var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); + var localVarFormParams = new Dictionary(); + var localVarFileParams = new Dictionary(); + Object localVarPostBody = null; + + // to determine the Content-Type header + String[] localVarHttpContentTypes = new String[] { + "application/json" + }; + String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); + + // to determine the Accept header + String[] localVarHttpHeaderAccepts = new String[] { + "application/json" + }; + String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); + if (localVarHttpHeaderAccept != null) + localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); + + if (body != null && body.GetType() != typeof(byte[])) + { + localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter + } + else + { + localVarPostBody = body; // byte array + } + + + // make the HTTP request + IRestResponse localVarResponse = (IRestResponse) Configuration.ApiClient.CallApi(localVarPath, + Method.PATCH, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + localVarPathParams, localVarHttpContentType); + + int localVarStatusCode = (int) localVarResponse.StatusCode; + + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestSpecialTags", localVarResponse); + if (exception != null) throw exception; + } + + return new ApiResponse(localVarStatusCode, + localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()), + (ModelClient) Configuration.ApiClient.Deserialize(localVarResponse, typeof(ModelClient))); + } + + /// + /// To test special tags To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// Task of ModelClient + public async System.Threading.Tasks.Task TestSpecialTagsAsync (ModelClient body) + { + ApiResponse localVarResponse = await TestSpecialTagsAsyncWithHttpInfo(body); + return localVarResponse.Data; + + } + + /// + /// To test special tags To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// Task of ApiResponse (ModelClient) + public async System.Threading.Tasks.Task> TestSpecialTagsAsyncWithHttpInfo (ModelClient body) + { + // verify the required parameter 'body' is set + if (body == null) + throw new ApiException(400, "Missing required parameter 'body' when calling AnotherFakeApi->TestSpecialTags"); + + var localVarPath = "./another-fake/dummy"; + var localVarPathParams = new Dictionary(); + var localVarQueryParams = new List>(); + var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); + var localVarFormParams = new Dictionary(); + var localVarFileParams = new Dictionary(); + Object localVarPostBody = null; + + // to determine the Content-Type header + String[] localVarHttpContentTypes = new String[] { + "application/json" + }; + String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); + + // to determine the Accept header + String[] localVarHttpHeaderAccepts = new String[] { + "application/json" + }; + String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); + if (localVarHttpHeaderAccept != null) + localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); + + if (body != null && body.GetType() != typeof(byte[])) + { + localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter + } + else + { + localVarPostBody = body; // byte array + } + + + // make the HTTP request + IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, + Method.PATCH, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + localVarPathParams, localVarHttpContentType); + + int localVarStatusCode = (int) localVarResponse.StatusCode; + + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestSpecialTags", localVarResponse); + if (exception != null) throw exception; + } + + return new ApiResponse(localVarStatusCode, + localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()), + (ModelClient) Configuration.ApiClient.Deserialize(localVarResponse, typeof(ModelClient))); + } + + } +} diff --git a/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Api/FakeApi.cs b/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Api/FakeApi.cs index ce9fef9c385..994936fbf23 100644 --- a/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Api/FakeApi.cs @@ -212,6 +212,27 @@ public interface IFakeApi : IApiAccessor /// ApiResponse of Object(void) ApiResponse TestEnumParametersWithHttpInfo (List enumFormStringArray = null, string enumFormString = null, List enumHeaderStringArray = null, string enumHeaderString = null, List enumQueryStringArray = null, string enumQueryString = null, int? enumQueryInteger = null, double? enumQueryDouble = null); /// + /// test inline additionalProperties + /// + /// + /// + /// + /// Thrown when fails to make API call + /// request body + /// + void TestInlineAdditionalProperties (Object param); + + /// + /// test inline additionalProperties + /// + /// + /// + /// + /// Thrown when fails to make API call + /// request body + /// ApiResponse of Object(void) + ApiResponse TestInlineAdditionalPropertiesWithHttpInfo (Object param); + /// /// test json serialization of form data /// /// @@ -424,6 +445,27 @@ public interface IFakeApi : IApiAccessor /// Task of ApiResponse System.Threading.Tasks.Task> TestEnumParametersAsyncWithHttpInfo (List enumFormStringArray = null, string enumFormString = null, List enumHeaderStringArray = null, string enumHeaderString = null, List enumQueryStringArray = null, string enumQueryString = null, int? enumQueryInteger = null, double? enumQueryDouble = null); /// + /// test inline additionalProperties + /// + /// + /// + /// + /// Thrown when fails to make API call + /// request body + /// Task of void + System.Threading.Tasks.Task TestInlineAdditionalPropertiesAsync (Object param); + + /// + /// test inline additionalProperties + /// + /// + /// + /// + /// Thrown when fails to make API call + /// request body + /// Task of ApiResponse + System.Threading.Tasks.Task> TestInlineAdditionalPropertiesAsyncWithHttpInfo (Object param); + /// /// test json serialization of form data /// /// @@ -1665,6 +1707,151 @@ public async System.Threading.Tasks.Task> TestEnumParameters null); } + /// + /// test inline additionalProperties + /// + /// Thrown when fails to make API call + /// request body + /// + public void TestInlineAdditionalProperties (Object param) + { + TestInlineAdditionalPropertiesWithHttpInfo(param); + } + + /// + /// test inline additionalProperties + /// + /// Thrown when fails to make API call + /// request body + /// ApiResponse of Object(void) + public ApiResponse TestInlineAdditionalPropertiesWithHttpInfo (Object param) + { + // verify the required parameter 'param' is set + if (param == null) + throw new ApiException(400, "Missing required parameter 'param' when calling FakeApi->TestInlineAdditionalProperties"); + + var localVarPath = "./fake/inline-additionalProperties"; + var localVarPathParams = new Dictionary(); + var localVarQueryParams = new List>(); + var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); + var localVarFormParams = new Dictionary(); + var localVarFileParams = new Dictionary(); + Object localVarPostBody = null; + + // to determine the Content-Type header + String[] localVarHttpContentTypes = new String[] { + "application/json" + }; + String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); + + // to determine the Accept header + String[] localVarHttpHeaderAccepts = new String[] { + }; + String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); + if (localVarHttpHeaderAccept != null) + localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); + + if (param != null && param.GetType() != typeof(byte[])) + { + localVarPostBody = Configuration.ApiClient.Serialize(param); // http body (model) parameter + } + else + { + localVarPostBody = param; // byte array + } + + + // make the HTTP request + IRestResponse localVarResponse = (IRestResponse) Configuration.ApiClient.CallApi(localVarPath, + Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + localVarPathParams, localVarHttpContentType); + + int localVarStatusCode = (int) localVarResponse.StatusCode; + + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestInlineAdditionalProperties", localVarResponse); + if (exception != null) throw exception; + } + + return new ApiResponse(localVarStatusCode, + localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()), + null); + } + + /// + /// test inline additionalProperties + /// + /// Thrown when fails to make API call + /// request body + /// Task of void + public async System.Threading.Tasks.Task TestInlineAdditionalPropertiesAsync (Object param) + { + await TestInlineAdditionalPropertiesAsyncWithHttpInfo(param); + + } + + /// + /// test inline additionalProperties + /// + /// Thrown when fails to make API call + /// request body + /// Task of ApiResponse + public async System.Threading.Tasks.Task> TestInlineAdditionalPropertiesAsyncWithHttpInfo (Object param) + { + // verify the required parameter 'param' is set + if (param == null) + throw new ApiException(400, "Missing required parameter 'param' when calling FakeApi->TestInlineAdditionalProperties"); + + var localVarPath = "./fake/inline-additionalProperties"; + var localVarPathParams = new Dictionary(); + var localVarQueryParams = new List>(); + var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); + var localVarFormParams = new Dictionary(); + var localVarFileParams = new Dictionary(); + Object localVarPostBody = null; + + // to determine the Content-Type header + String[] localVarHttpContentTypes = new String[] { + "application/json" + }; + String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); + + // to determine the Accept header + String[] localVarHttpHeaderAccepts = new String[] { + }; + String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); + if (localVarHttpHeaderAccept != null) + localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); + + if (param != null && param.GetType() != typeof(byte[])) + { + localVarPostBody = Configuration.ApiClient.Serialize(param); // http body (model) parameter + } + else + { + localVarPostBody = param; // byte array + } + + + // make the HTTP request + IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, + Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + localVarPathParams, localVarHttpContentType); + + int localVarStatusCode = (int) localVarResponse.StatusCode; + + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestInlineAdditionalProperties", localVarResponse); + if (exception != null) throw exception; + } + + return new ApiResponse(localVarStatusCode, + localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()), + null); + } + /// /// test json serialization of form data /// diff --git a/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Api/FakeClassnameTags123Api.cs b/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Api/FakeClassnameTags123Api.cs new file mode 100644 index 00000000000..77fcdddb2f7 --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Api/FakeClassnameTags123Api.cs @@ -0,0 +1,331 @@ +/* + * Swagger Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using RestSharp.Portable; +using IO.Swagger.Client; +using IO.Swagger.Model; + +namespace IO.Swagger.Api +{ + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public interface IFakeClassnameTags123Api : IApiAccessor + { + #region Synchronous Operations + /// + /// To test class name in snake case + /// + /// + /// + /// + /// Thrown when fails to make API call + /// client model + /// ModelClient + ModelClient TestClassname (ModelClient body); + + /// + /// To test class name in snake case + /// + /// + /// + /// + /// Thrown when fails to make API call + /// client model + /// ApiResponse of ModelClient + ApiResponse TestClassnameWithHttpInfo (ModelClient body); + #endregion Synchronous Operations + #region Asynchronous Operations + /// + /// To test class name in snake case + /// + /// + /// + /// + /// Thrown when fails to make API call + /// client model + /// Task of ModelClient + System.Threading.Tasks.Task TestClassnameAsync (ModelClient body); + + /// + /// To test class name in snake case + /// + /// + /// + /// + /// Thrown when fails to make API call + /// client model + /// Task of ApiResponse (ModelClient) + System.Threading.Tasks.Task> TestClassnameAsyncWithHttpInfo (ModelClient body); + #endregion Asynchronous Operations + } + + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public partial class FakeClassnameTags123Api : IFakeClassnameTags123Api + { + private IO.Swagger.Client.ExceptionFactory _exceptionFactory = (name, response) => null; + + /// + /// Initializes a new instance of the class. + /// + /// + public FakeClassnameTags123Api(String basePath) + { + this.Configuration = new Configuration { BasePath = basePath }; + + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + } + + /// + /// Initializes a new instance of the class + /// using Configuration object + /// + /// An instance of Configuration + /// + public FakeClassnameTags123Api(Configuration configuration = null) + { + if (configuration == null) // use the default one in Configuration + this.Configuration = Configuration.Default; + else + this.Configuration = configuration; + + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + } + + /// + /// Gets the base path of the API client. + /// + /// The base path + public String GetBasePath() + { + return this.Configuration.ApiClient.RestClient.BaseUrl.ToString(); + } + + /// + /// Sets the base path of the API client. + /// + /// The base path + [Obsolete("SetBasePath is deprecated, please do 'Configuration.ApiClient = new ApiClient(\"http://new-path\")' instead.")] + public void SetBasePath(String basePath) + { + // do nothing + } + + /// + /// Gets or sets the configuration object + /// + /// An instance of the Configuration + public Configuration Configuration {get; set;} + + /// + /// Provides a factory method hook for the creation of exceptions. + /// + public IO.Swagger.Client.ExceptionFactory ExceptionFactory + { + get + { + if (_exceptionFactory != null && _exceptionFactory.GetInvocationList().Length > 1) + { + throw new InvalidOperationException("Multicast delegate for ExceptionFactory is unsupported."); + } + return _exceptionFactory; + } + set { _exceptionFactory = value; } + } + + /// + /// Gets the default header. + /// + /// Dictionary of HTTP header + [Obsolete("DefaultHeader is deprecated, please use Configuration.DefaultHeader instead.")] + public IDictionary DefaultHeader() + { + return new ReadOnlyDictionary(this.Configuration.DefaultHeader); + } + + /// + /// Add default header. + /// + /// Header field name. + /// Header field value. + /// + [Obsolete("AddDefaultHeader is deprecated, please use Configuration.AddDefaultHeader instead.")] + public void AddDefaultHeader(string key, string value) + { + this.Configuration.AddDefaultHeader(key, value); + } + + /// + /// To test class name in snake case + /// + /// Thrown when fails to make API call + /// client model + /// ModelClient + public ModelClient TestClassname (ModelClient body) + { + ApiResponse localVarResponse = TestClassnameWithHttpInfo(body); + return localVarResponse.Data; + } + + /// + /// To test class name in snake case + /// + /// Thrown when fails to make API call + /// client model + /// ApiResponse of ModelClient + public ApiResponse< ModelClient > TestClassnameWithHttpInfo (ModelClient body) + { + // verify the required parameter 'body' is set + if (body == null) + throw new ApiException(400, "Missing required parameter 'body' when calling FakeClassnameTags123Api->TestClassname"); + + var localVarPath = "./fake_classname_test"; + var localVarPathParams = new Dictionary(); + var localVarQueryParams = new List>(); + var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); + var localVarFormParams = new Dictionary(); + var localVarFileParams = new Dictionary(); + Object localVarPostBody = null; + + // to determine the Content-Type header + String[] localVarHttpContentTypes = new String[] { + "application/json" + }; + String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); + + // to determine the Accept header + String[] localVarHttpHeaderAccepts = new String[] { + "application/json" + }; + String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); + if (localVarHttpHeaderAccept != null) + localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); + + if (body != null && body.GetType() != typeof(byte[])) + { + localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter + } + else + { + localVarPostBody = body; // byte array + } + + // authentication (api_key_query) required + if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key_query"))) + { + localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "api_key_query", Configuration.GetApiKeyWithPrefix("api_key_query"))); + } + + // make the HTTP request + IRestResponse localVarResponse = (IRestResponse) Configuration.ApiClient.CallApi(localVarPath, + Method.PATCH, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + localVarPathParams, localVarHttpContentType); + + int localVarStatusCode = (int) localVarResponse.StatusCode; + + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestClassname", localVarResponse); + if (exception != null) throw exception; + } + + return new ApiResponse(localVarStatusCode, + localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()), + (ModelClient) Configuration.ApiClient.Deserialize(localVarResponse, typeof(ModelClient))); + } + + /// + /// To test class name in snake case + /// + /// Thrown when fails to make API call + /// client model + /// Task of ModelClient + public async System.Threading.Tasks.Task TestClassnameAsync (ModelClient body) + { + ApiResponse localVarResponse = await TestClassnameAsyncWithHttpInfo(body); + return localVarResponse.Data; + + } + + /// + /// To test class name in snake case + /// + /// Thrown when fails to make API call + /// client model + /// Task of ApiResponse (ModelClient) + public async System.Threading.Tasks.Task> TestClassnameAsyncWithHttpInfo (ModelClient body) + { + // verify the required parameter 'body' is set + if (body == null) + throw new ApiException(400, "Missing required parameter 'body' when calling FakeClassnameTags123Api->TestClassname"); + + var localVarPath = "./fake_classname_test"; + var localVarPathParams = new Dictionary(); + var localVarQueryParams = new List>(); + var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); + var localVarFormParams = new Dictionary(); + var localVarFileParams = new Dictionary(); + Object localVarPostBody = null; + + // to determine the Content-Type header + String[] localVarHttpContentTypes = new String[] { + "application/json" + }; + String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); + + // to determine the Accept header + String[] localVarHttpHeaderAccepts = new String[] { + "application/json" + }; + String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); + if (localVarHttpHeaderAccept != null) + localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); + + if (body != null && body.GetType() != typeof(byte[])) + { + localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter + } + else + { + localVarPostBody = body; // byte array + } + + // authentication (api_key_query) required + if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key_query"))) + { + localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "api_key_query", Configuration.GetApiKeyWithPrefix("api_key_query"))); + } + + // make the HTTP request + IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, + Method.PATCH, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + localVarPathParams, localVarHttpContentType); + + int localVarStatusCode = (int) localVarResponse.StatusCode; + + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestClassname", localVarResponse); + if (exception != null) throw exception; + } + + return new ApiResponse(localVarStatusCode, + localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()), + (ModelClient) Configuration.ApiClient.Deserialize(localVarResponse, typeof(ModelClient))); + } + + } +} diff --git a/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Client/ApiClient.cs b/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Client/ApiClient.cs index be3e8899247..a6282e41d54 100644 --- a/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Client/ApiClient.cs @@ -144,14 +144,7 @@ private RestRequest PrepareRequest( if (postBody != null) // http body (model or byte[]) parameter { - if (postBody.GetType() == typeof(String)) - { - request.AddParameter(new Parameter { Value = postBody, Type = ParameterType.RequestBody, ContentType = "application/json" }); - } - else if (postBody.GetType() == typeof(byte[])) - { - request.AddParameter(new Parameter { Value = postBody, Type = ParameterType.RequestBody, ContentType = contentType }); - } + request.AddParameter(new Parameter { Value = postBody, Type = ParameterType.RequestBody, ContentType = contentType }); } return request; @@ -356,9 +349,25 @@ public String Serialize(object obj) } } + /// + ///Check if the given MIME is a JSON MIME. + ///JSON MIME examples: + /// application/json + /// application/json; charset=UTF8 + /// APPLICATION/JSON + /// application/vnd.company+json + /// + /// MIME + /// Returns True if MIME type is json. + public bool IsJsonMime(String mime) + { + var jsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"); + return mime != null && (jsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json")); + } + /// /// Select the Content-Type header's value from the given content-type array: - /// if JSON exists in the given array, use it; + /// if JSON type exists in the given array, use it; /// otherwise use the first one defined in 'consumes' /// /// The Content-Type array to select from. @@ -366,11 +375,14 @@ public String Serialize(object obj) public String SelectHeaderContentType(String[] contentTypes) { if (contentTypes.Length == 0) - return null; - - if (contentTypes.Contains("application/json", StringComparer.OrdinalIgnoreCase)) return "application/json"; + foreach (var contentType in contentTypes) + { + if (IsJsonMime(contentType.ToLower())) + return contentType; + } + return contentTypes[0]; // use the first content type specified in 'consumes' } diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/.gitignore b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/.gitignore index d3f4f7b6f55..17302c93bf0 100644 --- a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/.gitignore +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/.gitignore @@ -6,6 +6,7 @@ *.suo *.user *.sln.docstates +./nuget # Build results diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/README.md b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/README.md index 257a7e86293..8257b6b39dc 100644 --- a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/README.md +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/README.md @@ -68,17 +68,18 @@ namespace Example public void main() { - var apiInstance = new FakeApi(); - var body = new OuterBoolean(); // OuterBoolean | Input boolean as post body (optional) + var apiInstance = new AnotherFakeApi(); + var body = new ModelClient(); // ModelClient | client model try { - OuterBoolean result = apiInstance.FakeOuterBooleanSerialize(body); + // To test special tags + ModelClient result = apiInstance.TestSpecialTags(body); Debug.WriteLine(result); } catch (Exception e) { - Debug.Print("Exception when calling FakeApi.FakeOuterBooleanSerialize: " + e.Message ); + Debug.Print("Exception when calling AnotherFakeApi.TestSpecialTags: " + e.Message ); } } @@ -93,6 +94,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- +*AnotherFakeApi* | [**TestSpecialTags**](docs/AnotherFakeApi.md#testspecialtags) | **PATCH** /another-fake/dummy | To test special tags *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 | @@ -100,8 +102,9 @@ Class | Method | HTTP request | Description *FakeApi* | [**TestClientModel**](docs/FakeApi.md#testclientmodel) | **PATCH** /fake | To test \"client\" model *FakeApi* | [**TestEndpointParameters**](docs/FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 *FakeApi* | [**TestEnumParameters**](docs/FakeApi.md#testenumparameters) | **GET** /fake | To test enum parameters +*FakeApi* | [**TestInlineAdditionalProperties**](docs/FakeApi.md#testinlineadditionalproperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties *FakeApi* | [**TestJsonFormData**](docs/FakeApi.md#testjsonformdata) | **GET** /fake/jsonFormData | test json serialization of form data -*Fake_classname_tags123Api* | [**TestClassname**](docs/Fake_classname_tags123Api.md#testclassname) | **PATCH** /fake_classname_test | To test class name in snake case +*FakeClassnameTags123Api* | [**TestClassname**](docs/FakeClassnameTags123Api.md#testclassname) | **PATCH** /fake_classname_test | To test class name in snake case *PetApi* | [**AddPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store *PetApi* | [**DeletePet**](docs/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet *PetApi* | [**FindPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/build.sh b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/build.sh index f24c4f9dee7..872ae9b6838 100644 --- a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/build.sh +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/build.sh @@ -4,14 +4,43 @@ # frameworkVersion=net45 -netfx=${frameworkVersion#net} + +# sdk must match installed framworks under PREFIX/lib/mono/[value] +sdk=4.5.2-api + +# langversion refers to C# language features. see man mcs for details. +langversion=${sdk} +nuget_cmd=nuget + +# Match against our known SDK possibilities +case "${sdk}" in + 4) + langversion=4 + ;; + 4.5*) + langversion=5 + ;; + 4.6*) + langversion=6 + ;; + 4.7*) + langversion=7 # ignoring 7.1 for now. + ;; + *) + langversion=6 + ;; +esac echo "[INFO] Target framework: ${frameworkVersion}" -echo "[INFO] Download nuget and packages" -wget -nc https://dist.nuget.org/win-x86-commandline/latest/nuget.exe; +if [ ! type nuget &>/dev/null ]; then + echo "[INFO] Download nuget and packages" + wget -nc https://dist.nuget.org/win-x86-commandline/latest/nuget.exe; + nuget_cmd="mono nuget" +fi + mozroots --import --sync -mono nuget.exe install src/IO.Swagger/packages.config -o packages; +${nuget_cmd} install src/IO.Swagger/packages.config -o packages; echo "[INFO] Copy DLLs to the 'bin' folder" mkdir -p bin; @@ -22,7 +51,7 @@ cp packages/PropertyChanged.Fody.1.51.3/PropertyChanged.Fody.dll bin/PropertyCha cp packages/PropertyChanged.Fody.1.51.3/Lib/dotnet/PropertyChanged.dll bin/PropertyChanged.dll echo "[INFO] Run 'mcs' to build bin/IO.Swagger.dll" -mcs -sdk:${netfx} -r:bin/Newtonsoft.Json.dll,\ +mcs -langversion:${langversion} -sdk:${sdk} -r:bin/Newtonsoft.Json.dll,\ bin/Fody.dll,\ bin/PropertyChanged.Fody.dll,\ bin/PropertyChanged.dll,\ diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/AnotherFakeApi.md b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/AnotherFakeApi.md new file mode 100644 index 00000000000..89bc406754a --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/AnotherFakeApi.md @@ -0,0 +1,70 @@ +# IO.Swagger.Api.AnotherFakeApi + +All URIs are relative to *http://petstore.swagger.io:80/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**TestSpecialTags**](AnotherFakeApi.md#testspecialtags) | **PATCH** /another-fake/dummy | To test special tags + + + +# **TestSpecialTags** +> ModelClient TestSpecialTags (ModelClient body) + +To test special tags + +To test special tags + +### Example +```csharp +using System; +using System.Diagnostics; +using IO.Swagger.Api; +using IO.Swagger.Client; +using IO.Swagger.Model; + +namespace Example +{ + public class TestSpecialTagsExample + { + public void main() + { + var apiInstance = new AnotherFakeApi(); + var body = new ModelClient(); // ModelClient | client model + + try + { + // To test special tags + ModelClient result = apiInstance.TestSpecialTags(body); + Debug.WriteLine(result); + } + catch (Exception e) + { + Debug.Print("Exception when calling AnotherFakeApi.TestSpecialTags: " + e.Message ); + } + } + } +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**ModelClient**](ModelClient.md)| client model | + +### Return type + +[**ModelClient**](ModelClient.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/FakeApi.md b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/FakeApi.md index 8052cf14b72..bfc6bc81324 100644 --- a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/FakeApi.md +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/FakeApi.md @@ -11,6 +11,7 @@ Method | HTTP request | Description [**TestClientModel**](FakeApi.md#testclientmodel) | **PATCH** /fake | To test \"client\" model [**TestEndpointParameters**](FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 [**TestEnumParameters**](FakeApi.md#testenumparameters) | **GET** /fake | To test enum parameters +[**TestInlineAdditionalProperties**](FakeApi.md#testinlineadditionalproperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties [**TestJsonFormData**](FakeApi.md#testjsonformdata) | **GET** /fake/jsonFormData | test json serialization of form data @@ -342,10 +343,10 @@ namespace Example Configuration.Default.Password = "YOUR_PASSWORD"; var apiInstance = new FakeApi(); - var number = 3.4; // decimal? | None + var number = 8.14; // decimal? | None var _double = 1.2; // double? | None var patternWithoutDelimiter = patternWithoutDelimiter_example; // string | None - var _byte = _byte_example; // byte[] | None + var _byte = B; // byte[] | None var integer = 56; // int? | None (optional) var int32 = 56; // int? | None (optional) var int64 = 789; // long? | None (optional) @@ -479,14 +480,70 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **TestInlineAdditionalProperties** +> void TestInlineAdditionalProperties (Object param) + +test inline additionalProperties + +### Example +```csharp +using System; +using System.Diagnostics; +using IO.Swagger.Api; +using IO.Swagger.Client; +using IO.Swagger.Model; + +namespace Example +{ + public class TestInlineAdditionalPropertiesExample + { + public void main() + { + var apiInstance = new FakeApi(); + var param = ; // Object | request body + + try + { + // test inline additionalProperties + apiInstance.TestInlineAdditionalProperties(param); + } + catch (Exception e) + { + Debug.Print("Exception when calling FakeApi.TestInlineAdditionalProperties: " + e.Message ); + } + } + } +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **param** | **Object**| request body | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **TestJsonFormData** > void TestJsonFormData (string param, string param2) test json serialization of form data - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/FakeClassnameTags123Api.md b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/FakeClassnameTags123Api.md new file mode 100644 index 00000000000..5f1d0ca776b --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/FakeClassnameTags123Api.md @@ -0,0 +1,73 @@ +# IO.Swagger.Api.FakeClassnameTags123Api + +All URIs are relative to *http://petstore.swagger.io:80/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**TestClassname**](FakeClassnameTags123Api.md#testclassname) | **PATCH** /fake_classname_test | To test class name in snake case + + + +# **TestClassname** +> ModelClient TestClassname (ModelClient body) + +To test class name in snake case + +### Example +```csharp +using System; +using System.Diagnostics; +using IO.Swagger.Api; +using IO.Swagger.Client; +using IO.Swagger.Model; + +namespace Example +{ + public class TestClassnameExample + { + public void main() + { + // Configure API key authorization: api_key_query + Configuration.Default.AddApiKey("api_key_query", "YOUR_API_KEY"); + // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed + // Configuration.Default.AddApiKeyPrefix("api_key_query", "Bearer"); + + var apiInstance = new FakeClassnameTags123Api(); + var body = new ModelClient(); // ModelClient | client model + + try + { + // To test class name in snake case + ModelClient result = apiInstance.TestClassname(body); + Debug.WriteLine(result); + } + catch (Exception e) + { + Debug.Print("Exception when calling FakeClassnameTags123Api.TestClassname: " + e.Message ); + } + } + } +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**ModelClient**](ModelClient.md)| client model | + +### Return type + +[**ModelClient**](ModelClient.md) + +### Authorization + +[api_key_query](../README.md#api_key_query) + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/PetApi.md b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/PetApi.md index 6b6450a12ab..8654c43e51a 100644 --- a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/PetApi.md +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/PetApi.md @@ -20,8 +20,6 @@ Method | HTTP request | Description Add a new pet to the store - - ### Example ```csharp using System; @@ -83,8 +81,6 @@ void (empty response body) Deletes a pet - - ### Example ```csharp using System; @@ -342,8 +338,6 @@ Name | Type | Description | Notes Update an existing pet - - ### Example ```csharp using System; @@ -405,8 +399,6 @@ void (empty response body) Updates a pet in the store with form data - - ### Example ```csharp using System; @@ -472,8 +464,6 @@ void (empty response body) uploads an image - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/StoreApi.md b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/StoreApi.md index 113032c257b..28e3fe59067 100644 --- a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/StoreApi.md +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/StoreApi.md @@ -199,8 +199,6 @@ No authorization required Place an order for a pet - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/UserApi.md b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/UserApi.md index 0ddde3f669c..fd9bfb0e973 100644 --- a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/UserApi.md +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/docs/UserApi.md @@ -80,8 +80,6 @@ No authorization required Creates list of users with given input array - - ### Example ```csharp using System; @@ -140,8 +138,6 @@ No authorization required Creates list of users with given input array - - ### Example ```csharp using System; @@ -260,8 +256,6 @@ No authorization required Get user by user name - - ### Example ```csharp using System; @@ -321,8 +315,6 @@ No authorization required Logs user into the system - - ### Example ```csharp using System; @@ -384,8 +376,6 @@ No authorization required Logs out current logged in user session - - ### Example ```csharp using System; diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger.Test/Api/AnotherFakeApiTests.cs b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger.Test/Api/AnotherFakeApiTests.cs new file mode 100644 index 00000000000..070e217a0f5 --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger.Test/Api/AnotherFakeApiTests.cs @@ -0,0 +1,81 @@ +/* + * Swagger Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +using System; +using System.IO; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using RestSharp; +using NUnit.Framework; + +using IO.Swagger.Client; +using IO.Swagger.Api; +using IO.Swagger.Model; + +namespace IO.Swagger.Test +{ + /// + /// Class for testing AnotherFakeApi + /// + /// + /// This file is automatically generated by Swagger Codegen. + /// Please update the test case below to test the API endpoint. + /// + [TestFixture] + public class AnotherFakeApiTests + { + private AnotherFakeApi instance; + + /// + /// Setup before each unit test + /// + [SetUp] + public void Init() + { + instance = new AnotherFakeApi(); + } + + /// + /// Clean up after each unit test + /// + [TearDown] + public void Cleanup() + { + + } + + /// + /// Test an instance of AnotherFakeApi + /// + [Test] + public void InstanceTest() + { + // TODO uncomment below to test 'IsInstanceOfType' AnotherFakeApi + //Assert.IsInstanceOfType(typeof(AnotherFakeApi), instance, "instance is a AnotherFakeApi"); + } + + + /// + /// Test TestSpecialTags + /// + [Test] + public void TestSpecialTagsTest() + { + // TODO uncomment below to test the method and replace null with proper value + //ModelClient body = null; + //var response = instance.TestSpecialTags(body); + //Assert.IsInstanceOf (response, "response is ModelClient"); + } + + } + +} diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger.Test/Api/FakeClassnameTags123ApiTests.cs b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger.Test/Api/FakeClassnameTags123ApiTests.cs new file mode 100644 index 00000000000..36a5acb38a9 --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger.Test/Api/FakeClassnameTags123ApiTests.cs @@ -0,0 +1,81 @@ +/* + * Swagger Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +using System; +using System.IO; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using RestSharp; +using NUnit.Framework; + +using IO.Swagger.Client; +using IO.Swagger.Api; +using IO.Swagger.Model; + +namespace IO.Swagger.Test +{ + /// + /// Class for testing FakeClassnameTags123Api + /// + /// + /// This file is automatically generated by Swagger Codegen. + /// Please update the test case below to test the API endpoint. + /// + [TestFixture] + public class FakeClassnameTags123ApiTests + { + private FakeClassnameTags123Api instance; + + /// + /// Setup before each unit test + /// + [SetUp] + public void Init() + { + instance = new FakeClassnameTags123Api(); + } + + /// + /// Clean up after each unit test + /// + [TearDown] + public void Cleanup() + { + + } + + /// + /// Test an instance of FakeClassnameTags123Api + /// + [Test] + public void InstanceTest() + { + // TODO uncomment below to test 'IsInstanceOfType' FakeClassnameTags123Api + //Assert.IsInstanceOfType(typeof(FakeClassnameTags123Api), instance, "instance is a FakeClassnameTags123Api"); + } + + + /// + /// Test TestClassname + /// + [Test] + public void TestClassnameTest() + { + // TODO uncomment below to test the method and replace null with proper value + //ModelClient body = null; + //var response = instance.TestClassname(body); + //Assert.IsInstanceOf (response, "response is ModelClient"); + } + + } + +} diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/Api/AnotherFakeApi.cs b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/Api/AnotherFakeApi.cs new file mode 100644 index 00000000000..815cfe4cfb6 --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/Api/AnotherFakeApi.cs @@ -0,0 +1,321 @@ +/* + * Swagger Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using RestSharp; +using IO.Swagger.Client; +using IO.Swagger.Model; + +namespace IO.Swagger.Api +{ + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public interface IAnotherFakeApi : IApiAccessor + { + #region Synchronous Operations + /// + /// To test special tags + /// + /// + /// To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// ModelClient + ModelClient TestSpecialTags (ModelClient body); + + /// + /// To test special tags + /// + /// + /// To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// ApiResponse of ModelClient + ApiResponse TestSpecialTagsWithHttpInfo (ModelClient body); + #endregion Synchronous Operations + #region Asynchronous Operations + /// + /// To test special tags + /// + /// + /// To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// Task of ModelClient + System.Threading.Tasks.Task TestSpecialTagsAsync (ModelClient body); + + /// + /// To test special tags + /// + /// + /// To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// Task of ApiResponse (ModelClient) + System.Threading.Tasks.Task> TestSpecialTagsAsyncWithHttpInfo (ModelClient body); + #endregion Asynchronous Operations + } + + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public partial class AnotherFakeApi : IAnotherFakeApi + { + private IO.Swagger.Client.ExceptionFactory _exceptionFactory = (name, response) => null; + + /// + /// Initializes a new instance of the class. + /// + /// + public AnotherFakeApi(String basePath) + { + this.Configuration = new Configuration { BasePath = basePath }; + + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + } + + /// + /// Initializes a new instance of the class + /// using Configuration object + /// + /// An instance of Configuration + /// + public AnotherFakeApi(Configuration configuration = null) + { + if (configuration == null) // use the default one in Configuration + this.Configuration = Configuration.Default; + else + this.Configuration = configuration; + + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + } + + /// + /// Gets the base path of the API client. + /// + /// The base path + public String GetBasePath() + { + return this.Configuration.ApiClient.RestClient.BaseUrl.ToString(); + } + + /// + /// Sets the base path of the API client. + /// + /// The base path + [Obsolete("SetBasePath is deprecated, please do 'Configuration.ApiClient = new ApiClient(\"http://new-path\")' instead.")] + public void SetBasePath(String basePath) + { + // do nothing + } + + /// + /// Gets or sets the configuration object + /// + /// An instance of the Configuration + public Configuration Configuration {get; set;} + + /// + /// Provides a factory method hook for the creation of exceptions. + /// + public IO.Swagger.Client.ExceptionFactory ExceptionFactory + { + get + { + if (_exceptionFactory != null && _exceptionFactory.GetInvocationList().Length > 1) + { + throw new InvalidOperationException("Multicast delegate for ExceptionFactory is unsupported."); + } + return _exceptionFactory; + } + set { _exceptionFactory = value; } + } + + /// + /// Gets the default header. + /// + /// Dictionary of HTTP header + [Obsolete("DefaultHeader is deprecated, please use Configuration.DefaultHeader instead.")] + public IDictionary DefaultHeader() + { + return new ReadOnlyDictionary(this.Configuration.DefaultHeader); + } + + /// + /// Add default header. + /// + /// Header field name. + /// Header field value. + /// + [Obsolete("AddDefaultHeader is deprecated, please use Configuration.AddDefaultHeader instead.")] + public void AddDefaultHeader(string key, string value) + { + this.Configuration.AddDefaultHeader(key, value); + } + + /// + /// To test special tags To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// ModelClient + public ModelClient TestSpecialTags (ModelClient body) + { + ApiResponse localVarResponse = TestSpecialTagsWithHttpInfo(body); + return localVarResponse.Data; + } + + /// + /// To test special tags To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// ApiResponse of ModelClient + public ApiResponse< ModelClient > TestSpecialTagsWithHttpInfo (ModelClient body) + { + // verify the required parameter 'body' is set + if (body == null) + throw new ApiException(400, "Missing required parameter 'body' when calling AnotherFakeApi->TestSpecialTags"); + + var localVarPath = "/another-fake/dummy"; + var localVarPathParams = new Dictionary(); + var localVarQueryParams = new List>(); + var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); + var localVarFormParams = new Dictionary(); + var localVarFileParams = new Dictionary(); + Object localVarPostBody = null; + + // to determine the Content-Type header + String[] localVarHttpContentTypes = new String[] { + "application/json" + }; + String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); + + // to determine the Accept header + String[] localVarHttpHeaderAccepts = new String[] { + "application/json" + }; + String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); + if (localVarHttpHeaderAccept != null) + localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); + + if (body != null && body.GetType() != typeof(byte[])) + { + localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter + } + else + { + localVarPostBody = body; // byte array + } + + + // make the HTTP request + IRestResponse localVarResponse = (IRestResponse) Configuration.ApiClient.CallApi(localVarPath, + Method.PATCH, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + localVarPathParams, localVarHttpContentType); + + int localVarStatusCode = (int) localVarResponse.StatusCode; + + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestSpecialTags", localVarResponse); + if (exception != null) throw exception; + } + + return new ApiResponse(localVarStatusCode, + localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), + (ModelClient) Configuration.ApiClient.Deserialize(localVarResponse, typeof(ModelClient))); + } + + /// + /// To test special tags To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// Task of ModelClient + public async System.Threading.Tasks.Task TestSpecialTagsAsync (ModelClient body) + { + ApiResponse localVarResponse = await TestSpecialTagsAsyncWithHttpInfo(body); + return localVarResponse.Data; + + } + + /// + /// To test special tags To test special tags + /// + /// Thrown when fails to make API call + /// client model + /// Task of ApiResponse (ModelClient) + public async System.Threading.Tasks.Task> TestSpecialTagsAsyncWithHttpInfo (ModelClient body) + { + // verify the required parameter 'body' is set + if (body == null) + throw new ApiException(400, "Missing required parameter 'body' when calling AnotherFakeApi->TestSpecialTags"); + + var localVarPath = "/another-fake/dummy"; + var localVarPathParams = new Dictionary(); + var localVarQueryParams = new List>(); + var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); + var localVarFormParams = new Dictionary(); + var localVarFileParams = new Dictionary(); + Object localVarPostBody = null; + + // to determine the Content-Type header + String[] localVarHttpContentTypes = new String[] { + "application/json" + }; + String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); + + // to determine the Accept header + String[] localVarHttpHeaderAccepts = new String[] { + "application/json" + }; + String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); + if (localVarHttpHeaderAccept != null) + localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); + + if (body != null && body.GetType() != typeof(byte[])) + { + localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter + } + else + { + localVarPostBody = body; // byte array + } + + + // make the HTTP request + IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, + Method.PATCH, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + localVarPathParams, localVarHttpContentType); + + int localVarStatusCode = (int) localVarResponse.StatusCode; + + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestSpecialTags", localVarResponse); + if (exception != null) throw exception; + } + + return new ApiResponse(localVarStatusCode, + localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), + (ModelClient) Configuration.ApiClient.Deserialize(localVarResponse, typeof(ModelClient))); + } + + } +} diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/Api/FakeApi.cs b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/Api/FakeApi.cs index d74183aa9ee..06c068c026a 100644 --- a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/Api/FakeApi.cs @@ -212,6 +212,27 @@ public interface IFakeApi : IApiAccessor /// ApiResponse of Object(void) ApiResponse TestEnumParametersWithHttpInfo (List enumFormStringArray = null, string enumFormString = null, List enumHeaderStringArray = null, string enumHeaderString = null, List enumQueryStringArray = null, string enumQueryString = null, int? enumQueryInteger = null, double? enumQueryDouble = null); /// + /// test inline additionalProperties + /// + /// + /// + /// + /// Thrown when fails to make API call + /// request body + /// + void TestInlineAdditionalProperties (Object param); + + /// + /// test inline additionalProperties + /// + /// + /// + /// + /// Thrown when fails to make API call + /// request body + /// ApiResponse of Object(void) + ApiResponse TestInlineAdditionalPropertiesWithHttpInfo (Object param); + /// /// test json serialization of form data /// /// @@ -424,6 +445,27 @@ public interface IFakeApi : IApiAccessor /// Task of ApiResponse System.Threading.Tasks.Task> TestEnumParametersAsyncWithHttpInfo (List enumFormStringArray = null, string enumFormString = null, List enumHeaderStringArray = null, string enumHeaderString = null, List enumQueryStringArray = null, string enumQueryString = null, int? enumQueryInteger = null, double? enumQueryDouble = null); /// + /// test inline additionalProperties + /// + /// + /// + /// + /// Thrown when fails to make API call + /// request body + /// Task of void + System.Threading.Tasks.Task TestInlineAdditionalPropertiesAsync (Object param); + + /// + /// test inline additionalProperties + /// + /// + /// + /// + /// Thrown when fails to make API call + /// request body + /// Task of ApiResponse + System.Threading.Tasks.Task> TestInlineAdditionalPropertiesAsyncWithHttpInfo (Object param); + /// /// test json serialization of form data /// /// @@ -1665,6 +1707,151 @@ public async System.Threading.Tasks.Task> TestEnumParameters null); } + /// + /// test inline additionalProperties + /// + /// Thrown when fails to make API call + /// request body + /// + public void TestInlineAdditionalProperties (Object param) + { + TestInlineAdditionalPropertiesWithHttpInfo(param); + } + + /// + /// test inline additionalProperties + /// + /// Thrown when fails to make API call + /// request body + /// ApiResponse of Object(void) + public ApiResponse TestInlineAdditionalPropertiesWithHttpInfo (Object param) + { + // verify the required parameter 'param' is set + if (param == null) + throw new ApiException(400, "Missing required parameter 'param' when calling FakeApi->TestInlineAdditionalProperties"); + + var localVarPath = "/fake/inline-additionalProperties"; + var localVarPathParams = new Dictionary(); + var localVarQueryParams = new List>(); + var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); + var localVarFormParams = new Dictionary(); + var localVarFileParams = new Dictionary(); + Object localVarPostBody = null; + + // to determine the Content-Type header + String[] localVarHttpContentTypes = new String[] { + "application/json" + }; + String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); + + // to determine the Accept header + String[] localVarHttpHeaderAccepts = new String[] { + }; + String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); + if (localVarHttpHeaderAccept != null) + localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); + + if (param != null && param.GetType() != typeof(byte[])) + { + localVarPostBody = Configuration.ApiClient.Serialize(param); // http body (model) parameter + } + else + { + localVarPostBody = param; // byte array + } + + + // make the HTTP request + IRestResponse localVarResponse = (IRestResponse) Configuration.ApiClient.CallApi(localVarPath, + Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + localVarPathParams, localVarHttpContentType); + + int localVarStatusCode = (int) localVarResponse.StatusCode; + + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestInlineAdditionalProperties", localVarResponse); + if (exception != null) throw exception; + } + + return new ApiResponse(localVarStatusCode, + localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), + null); + } + + /// + /// test inline additionalProperties + /// + /// Thrown when fails to make API call + /// request body + /// Task of void + public async System.Threading.Tasks.Task TestInlineAdditionalPropertiesAsync (Object param) + { + await TestInlineAdditionalPropertiesAsyncWithHttpInfo(param); + + } + + /// + /// test inline additionalProperties + /// + /// Thrown when fails to make API call + /// request body + /// Task of ApiResponse + public async System.Threading.Tasks.Task> TestInlineAdditionalPropertiesAsyncWithHttpInfo (Object param) + { + // verify the required parameter 'param' is set + if (param == null) + throw new ApiException(400, "Missing required parameter 'param' when calling FakeApi->TestInlineAdditionalProperties"); + + var localVarPath = "/fake/inline-additionalProperties"; + var localVarPathParams = new Dictionary(); + var localVarQueryParams = new List>(); + var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); + var localVarFormParams = new Dictionary(); + var localVarFileParams = new Dictionary(); + Object localVarPostBody = null; + + // to determine the Content-Type header + String[] localVarHttpContentTypes = new String[] { + "application/json" + }; + String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); + + // to determine the Accept header + String[] localVarHttpHeaderAccepts = new String[] { + }; + String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); + if (localVarHttpHeaderAccept != null) + localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); + + if (param != null && param.GetType() != typeof(byte[])) + { + localVarPostBody = Configuration.ApiClient.Serialize(param); // http body (model) parameter + } + else + { + localVarPostBody = param; // byte array + } + + + // make the HTTP request + IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, + Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + localVarPathParams, localVarHttpContentType); + + int localVarStatusCode = (int) localVarResponse.StatusCode; + + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestInlineAdditionalProperties", localVarResponse); + if (exception != null) throw exception; + } + + return new ApiResponse(localVarStatusCode, + localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), + null); + } + /// /// test json serialization of form data /// diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/Api/FakeClassnameTags123Api.cs b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/Api/FakeClassnameTags123Api.cs new file mode 100644 index 00000000000..264994669de --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/Api/FakeClassnameTags123Api.cs @@ -0,0 +1,331 @@ +/* + * Swagger Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using RestSharp; +using IO.Swagger.Client; +using IO.Swagger.Model; + +namespace IO.Swagger.Api +{ + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public interface IFakeClassnameTags123Api : IApiAccessor + { + #region Synchronous Operations + /// + /// To test class name in snake case + /// + /// + /// + /// + /// Thrown when fails to make API call + /// client model + /// ModelClient + ModelClient TestClassname (ModelClient body); + + /// + /// To test class name in snake case + /// + /// + /// + /// + /// Thrown when fails to make API call + /// client model + /// ApiResponse of ModelClient + ApiResponse TestClassnameWithHttpInfo (ModelClient body); + #endregion Synchronous Operations + #region Asynchronous Operations + /// + /// To test class name in snake case + /// + /// + /// + /// + /// Thrown when fails to make API call + /// client model + /// Task of ModelClient + System.Threading.Tasks.Task TestClassnameAsync (ModelClient body); + + /// + /// To test class name in snake case + /// + /// + /// + /// + /// Thrown when fails to make API call + /// client model + /// Task of ApiResponse (ModelClient) + System.Threading.Tasks.Task> TestClassnameAsyncWithHttpInfo (ModelClient body); + #endregion Asynchronous Operations + } + + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public partial class FakeClassnameTags123Api : IFakeClassnameTags123Api + { + private IO.Swagger.Client.ExceptionFactory _exceptionFactory = (name, response) => null; + + /// + /// Initializes a new instance of the class. + /// + /// + public FakeClassnameTags123Api(String basePath) + { + this.Configuration = new Configuration { BasePath = basePath }; + + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + } + + /// + /// Initializes a new instance of the class + /// using Configuration object + /// + /// An instance of Configuration + /// + public FakeClassnameTags123Api(Configuration configuration = null) + { + if (configuration == null) // use the default one in Configuration + this.Configuration = Configuration.Default; + else + this.Configuration = configuration; + + ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory; + } + + /// + /// Gets the base path of the API client. + /// + /// The base path + public String GetBasePath() + { + return this.Configuration.ApiClient.RestClient.BaseUrl.ToString(); + } + + /// + /// Sets the base path of the API client. + /// + /// The base path + [Obsolete("SetBasePath is deprecated, please do 'Configuration.ApiClient = new ApiClient(\"http://new-path\")' instead.")] + public void SetBasePath(String basePath) + { + // do nothing + } + + /// + /// Gets or sets the configuration object + /// + /// An instance of the Configuration + public Configuration Configuration {get; set;} + + /// + /// Provides a factory method hook for the creation of exceptions. + /// + public IO.Swagger.Client.ExceptionFactory ExceptionFactory + { + get + { + if (_exceptionFactory != null && _exceptionFactory.GetInvocationList().Length > 1) + { + throw new InvalidOperationException("Multicast delegate for ExceptionFactory is unsupported."); + } + return _exceptionFactory; + } + set { _exceptionFactory = value; } + } + + /// + /// Gets the default header. + /// + /// Dictionary of HTTP header + [Obsolete("DefaultHeader is deprecated, please use Configuration.DefaultHeader instead.")] + public IDictionary DefaultHeader() + { + return new ReadOnlyDictionary(this.Configuration.DefaultHeader); + } + + /// + /// Add default header. + /// + /// Header field name. + /// Header field value. + /// + [Obsolete("AddDefaultHeader is deprecated, please use Configuration.AddDefaultHeader instead.")] + public void AddDefaultHeader(string key, string value) + { + this.Configuration.AddDefaultHeader(key, value); + } + + /// + /// To test class name in snake case + /// + /// Thrown when fails to make API call + /// client model + /// ModelClient + public ModelClient TestClassname (ModelClient body) + { + ApiResponse localVarResponse = TestClassnameWithHttpInfo(body); + return localVarResponse.Data; + } + + /// + /// To test class name in snake case + /// + /// Thrown when fails to make API call + /// client model + /// ApiResponse of ModelClient + public ApiResponse< ModelClient > TestClassnameWithHttpInfo (ModelClient body) + { + // verify the required parameter 'body' is set + if (body == null) + throw new ApiException(400, "Missing required parameter 'body' when calling FakeClassnameTags123Api->TestClassname"); + + var localVarPath = "/fake_classname_test"; + var localVarPathParams = new Dictionary(); + var localVarQueryParams = new List>(); + var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); + var localVarFormParams = new Dictionary(); + var localVarFileParams = new Dictionary(); + Object localVarPostBody = null; + + // to determine the Content-Type header + String[] localVarHttpContentTypes = new String[] { + "application/json" + }; + String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); + + // to determine the Accept header + String[] localVarHttpHeaderAccepts = new String[] { + "application/json" + }; + String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); + if (localVarHttpHeaderAccept != null) + localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); + + if (body != null && body.GetType() != typeof(byte[])) + { + localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter + } + else + { + localVarPostBody = body; // byte array + } + + // authentication (api_key_query) required + if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key_query"))) + { + localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "api_key_query", Configuration.GetApiKeyWithPrefix("api_key_query"))); + } + + // make the HTTP request + IRestResponse localVarResponse = (IRestResponse) Configuration.ApiClient.CallApi(localVarPath, + Method.PATCH, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + localVarPathParams, localVarHttpContentType); + + int localVarStatusCode = (int) localVarResponse.StatusCode; + + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestClassname", localVarResponse); + if (exception != null) throw exception; + } + + return new ApiResponse(localVarStatusCode, + localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), + (ModelClient) Configuration.ApiClient.Deserialize(localVarResponse, typeof(ModelClient))); + } + + /// + /// To test class name in snake case + /// + /// Thrown when fails to make API call + /// client model + /// Task of ModelClient + public async System.Threading.Tasks.Task TestClassnameAsync (ModelClient body) + { + ApiResponse localVarResponse = await TestClassnameAsyncWithHttpInfo(body); + return localVarResponse.Data; + + } + + /// + /// To test class name in snake case + /// + /// Thrown when fails to make API call + /// client model + /// Task of ApiResponse (ModelClient) + public async System.Threading.Tasks.Task> TestClassnameAsyncWithHttpInfo (ModelClient body) + { + // verify the required parameter 'body' is set + if (body == null) + throw new ApiException(400, "Missing required parameter 'body' when calling FakeClassnameTags123Api->TestClassname"); + + var localVarPath = "/fake_classname_test"; + var localVarPathParams = new Dictionary(); + var localVarQueryParams = new List>(); + var localVarHeaderParams = new Dictionary(Configuration.DefaultHeader); + var localVarFormParams = new Dictionary(); + var localVarFileParams = new Dictionary(); + Object localVarPostBody = null; + + // to determine the Content-Type header + String[] localVarHttpContentTypes = new String[] { + "application/json" + }; + String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); + + // to determine the Accept header + String[] localVarHttpHeaderAccepts = new String[] { + "application/json" + }; + String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); + if (localVarHttpHeaderAccept != null) + localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); + + if (body != null && body.GetType() != typeof(byte[])) + { + localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter + } + else + { + localVarPostBody = body; // byte array + } + + // authentication (api_key_query) required + if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key_query"))) + { + localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "api_key_query", Configuration.GetApiKeyWithPrefix("api_key_query"))); + } + + // make the HTTP request + IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, + Method.PATCH, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + localVarPathParams, localVarHttpContentType); + + int localVarStatusCode = (int) localVarResponse.StatusCode; + + if (ExceptionFactory != null) + { + Exception exception = ExceptionFactory("TestClassname", localVarResponse); + if (exception != null) throw exception; + } + + return new ApiResponse(localVarStatusCode, + localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), + (ModelClient) Configuration.ApiClient.Deserialize(localVarResponse, typeof(ModelClient))); + } + + } +} diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/Client/ApiClient.cs b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/Client/ApiClient.cs index f4c961cc61a..da0d7101975 100644 --- a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/Client/ApiClient.cs @@ -139,14 +139,7 @@ private RestRequest PrepareRequest( if (postBody != null) // http body (model or byte[]) parameter { - if (postBody.GetType() == typeof(String)) - { - request.AddParameter("application/json", postBody, ParameterType.RequestBody); - } - else if (postBody.GetType() == typeof(byte[])) - { - request.AddParameter(contentType, postBody, ParameterType.RequestBody); - } + request.AddParameter(contentType, postBody, ParameterType.RequestBody); } return request; @@ -351,9 +344,25 @@ public String Serialize(object obj) } } + /// + ///Check if the given MIME is a JSON MIME. + ///JSON MIME examples: + /// application/json + /// application/json; charset=UTF8 + /// APPLICATION/JSON + /// application/vnd.company+json + /// + /// MIME + /// Returns True if MIME type is json. + public bool IsJsonMime(String mime) + { + var jsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"); + return mime != null && (jsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json")); + } + /// /// Select the Content-Type header's value from the given content-type array: - /// if JSON exists in the given array, use it; + /// if JSON type exists in the given array, use it; /// otherwise use the first one defined in 'consumes' /// /// The Content-Type array to select from. @@ -361,11 +370,14 @@ public String Serialize(object obj) public String SelectHeaderContentType(String[] contentTypes) { if (contentTypes.Length == 0) - return null; - - if (contentTypes.Contains("application/json", StringComparer.OrdinalIgnoreCase)) return "application/json"; + foreach (var contentType in contentTypes) + { + if (IsJsonMime(contentType.ToLower())) + return contentType; + } + return contentTypes[0]; // use the first content type specified in 'consumes' }