forked from loafle/openapi-generator-original
[csharp] Support inheritance instead of duplicating parent properties in derived classes (#5922)
* [csharp] Explicitly set supportsInheritance * [csharp] set supportsInheritance for client This includes supportsInheritance only for the client codegen at the moment, because setting in AbstractCSharpCodegen would require the change to be tested in all derived generators, possibly including similar template changes to this commit's. * include nice improvement of https://github.com/jimschubert/swagger-codegen/tree/csharp/3829 and leverage https://github.com/manuc66/JsonSubTypes for subtype deserialization * remove duplicate base validations * remove useless tests * restore documentation for properties coming from parent * launch bin/security/csharp-petstore.sh * it's impossible to call an explicitly implemented interface-method on the base class (https://stackoverflow.com/questions/5976216/how-to-call-an-explicitly-implemented-interface-method-on-the-base-class) * restore portion of code that was lost * regenerate more * fix missing using * take the multi .net compatible revision * keep generated model simple when no hierarchy involved * regenerate with: - bin/csharp-petstore-all.sh && bin/security/csharp-petstore.sh - bin/csharp-dotnet2-petstore.sh && bin/csharp-petstore.sh && bin/csharp-petstore-netcore-project.sh && bin/csharp-petstore-net-standard.sh && bin/csharp-property-changed-petstore.sh * fix sln indentation and the missing windows runner for dotnet2 * fix inheritance GetHashCode and Equals * override instead of hiding the base method + fix the csharp-property-changed-petstore.bat * By default the value of the discriminator property must be the name of the current schema * Add test for subtype deserialisation from parent type * add missing '.bat' and use the 'call' template from javascript-petstore-all.bat add missing file to trigger it on windows * fix default value bug * cleanup copyright information * formatting after merge * fix merge * applying bin/csharp-petstore-all.sh * applying bin/security/csharp-petstore.sh
This commit is contained in:
parent
b8183fbd09
commit
a41e8bed97
0
bin/csharp-dotnet2-petstore.sh
Executable file → Normal file
0
bin/csharp-dotnet2-petstore.sh
Executable file → Normal file
10
bin/security/windows/csharp-petstore.bat
Normal file
10
bin/security/windows/csharp-petstore.bat
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
|
||||||
|
|
||||||
|
If Not Exist %executable% (
|
||||||
|
mvn clean package
|
||||||
|
)
|
||||||
|
|
||||||
|
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||||
|
set ags=generate -i modules/swagger-codegen/src/test/resources/2_0/petstore-security-test.yaml -l csharp -o samples/client/petstore-security-test/csharp/SwaggerClient --additional-properties packageGuid={8CE139DF-64BC-4591-85F8-8506C2B67514}
|
||||||
|
|
||||||
|
java %JAVA_OPTS% -jar %executable% %ags%
|
10
bin/windows/csharp-dotnet2-petstore.bat
Executable file
10
bin/windows/csharp-dotnet2-petstore.bat
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
|
||||||
|
|
||||||
|
If Not Exist %executable% (
|
||||||
|
mvn clean package
|
||||||
|
)
|
||||||
|
|
||||||
|
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||||
|
set ags=generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l CsharpDotNet2 -o samples/client/petstore/csharp-dotnet2/SwaggerClientTest/Lib/SwaggerClient --additional-properties hideGenerationTimestamp=true
|
||||||
|
|
||||||
|
java %JAVA_OPTS% -jar %executable% %ags%
|
@ -1,8 +1,14 @@
|
|||||||
REM C# Petstore API client
|
REM C# Petstore API client
|
||||||
.\bin\windows\csharp-petstore.bat
|
call .\bin\windows\csharp-petstore.bat
|
||||||
|
|
||||||
REM C# Petstore API client with PropertyChanged
|
REM C# Petstore API client with PropertyChanged
|
||||||
.\bin\windows\csharp-property-changed-petstore.bat
|
call .\bin\windows\csharp-property-changed-petstore.bat
|
||||||
|
|
||||||
REM C# Petstore API client (v5.0 for .net standarnd 1.3+)
|
REM C# Petstore API client (v5.0 for .net standarnd 1.3+)
|
||||||
.\bin\windows\csharp-petstore-netstandard.bat
|
call .\bin\windows\csharp-petstore-netstandard.bat
|
||||||
|
|
||||||
|
call .\bin\windows\csharp-dotnet2-petstore.bat
|
||||||
|
|
||||||
|
call .\bin\windows\csharp-petstore-netcore-project.bat
|
||||||
|
|
||||||
|
call .\bin\windows\csharp-property-changed-petstore.bat
|
@ -5,6 +5,6 @@ If Not Exist %executable% (
|
|||||||
)
|
)
|
||||||
|
|
||||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||||
set 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\SwaggerClientNetStandard --additional-properties targetFramework=v5.0,packageGuid={3AB1F259-1769-484B-9411-84505FCCBD55}
|
set 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\SwaggerClientWithPropertyChanged --additional-properties=generatePropertyChanged=true,packageGuid={5CD900DE-8266-412F-A758-28E1F9C623D5}
|
||||||
|
|
||||||
java %JAVA_OPTS% -jar %executable% %ags%
|
java %JAVA_OPTS% -jar %executable% %ags%
|
||||||
|
@ -3159,6 +3159,7 @@ public class DefaultCodegen {
|
|||||||
if (Boolean.TRUE.equals(cp.isReadOnly)) {
|
if (Boolean.TRUE.equals(cp.isReadOnly)) {
|
||||||
m.readOnlyVars.add(cp);
|
m.readOnlyVars.add(cp);
|
||||||
} else { // else add to readWriteVars (list of properties)
|
} else { // else add to readWriteVars (list of properties)
|
||||||
|
// FIXME: readWriteVars can contain duplicated properties. Debug/breakpoint here while running C# generator (Dog and Cat models)
|
||||||
m.readWriteVars.add(cp);
|
m.readWriteVars.add(cp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,23 @@
|
|||||||
package io.swagger.codegen.languages;
|
package io.swagger.codegen.languages;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.swagger.codegen.*;
|
||||||
import com.sun.org.apache.bcel.internal.classfile.Code;
|
|
||||||
|
|
||||||
import io.swagger.codegen.CodegenConstants;
|
|
||||||
import io.swagger.codegen.CodegenType;
|
|
||||||
import io.swagger.codegen.CodegenModel;
|
|
||||||
import io.swagger.codegen.CodegenParameter;
|
|
||||||
import io.swagger.codegen.SupportingFile;
|
|
||||||
import io.swagger.codegen.CodegenProperty;
|
|
||||||
import io.swagger.codegen.CodegenOperation;
|
|
||||||
import io.swagger.codegen.CliOption;
|
|
||||||
import io.swagger.models.Model;
|
import io.swagger.models.Model;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||||
|
|
||||||
public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||||
@SuppressWarnings({"unused", "hiding"})
|
@SuppressWarnings({"hiding"})
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(CSharpClientCodegen.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(CSharpClientCodegen.class);
|
||||||
private static final String NET45 = "v4.5";
|
private static final String NET45 = "v4.5";
|
||||||
private static final String NET35 = "v3.5";
|
private static final String NET35 = "v3.5";
|
||||||
private static final String NETSTANDARD = "v5.0";
|
private static final String NETSTANDARD = "v5.0";
|
||||||
private static final String UWP = "uwp";
|
private static final String UWP = "uwp";
|
||||||
private static final String DATA_TYPE_WITH_ENUM_EXTENSION = "plainDatatypeWithEnum";
|
|
||||||
|
|
||||||
protected String packageGuid = "{" + java.util.UUID.randomUUID().toString().toUpperCase() + "}";
|
protected String packageGuid = "{" + java.util.UUID.randomUUID().toString().toUpperCase() + "}";
|
||||||
protected String clientPackage = "IO.Swagger.Client";
|
protected String clientPackage = "IO.Swagger.Client";
|
||||||
@ -55,6 +39,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
|
|
||||||
public CSharpClientCodegen() {
|
public CSharpClientCodegen() {
|
||||||
super();
|
super();
|
||||||
|
supportsInheritance = true;
|
||||||
modelTemplateFiles.put("model.mustache", ".cs");
|
modelTemplateFiles.put("model.mustache", ".cs");
|
||||||
apiTemplateFiles.put("api.mustache", ".cs");
|
apiTemplateFiles.put("api.mustache", ".cs");
|
||||||
|
|
||||||
@ -181,16 +166,16 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
Boolean.valueOf(additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
|
Boolean.valueOf(additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isEmpty(apiPackage)) {
|
if (isEmpty(apiPackage)) {
|
||||||
apiPackage = "Api";
|
apiPackage = "Api";
|
||||||
}
|
}
|
||||||
if(isEmpty(modelPackage)) {
|
if (isEmpty(modelPackage)) {
|
||||||
modelPackage = "Model";
|
modelPackage = "Model";
|
||||||
}
|
}
|
||||||
clientPackage = "Client";
|
clientPackage = "Client";
|
||||||
|
|
||||||
Boolean excludeTests = false;
|
Boolean excludeTests = false;
|
||||||
if(additionalProperties.containsKey(CodegenConstants.EXCLUDE_TESTS)) {
|
if (additionalProperties.containsKey(CodegenConstants.EXCLUDE_TESTS)) {
|
||||||
excludeTests = Boolean.valueOf(additionalProperties.get(CodegenConstants.EXCLUDE_TESTS).toString());
|
excludeTests = Boolean.valueOf(additionalProperties.get(CodegenConstants.EXCLUDE_TESTS).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,12 +200,12 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
if (NET35.equals(this.targetFramework)) {
|
if (NET35.equals(this.targetFramework)) {
|
||||||
setTargetFrameworkNuget("net35");
|
setTargetFrameworkNuget("net35");
|
||||||
setSupportsAsync(Boolean.FALSE);
|
setSupportsAsync(Boolean.FALSE);
|
||||||
if(additionalProperties.containsKey("supportsAsync")){
|
if (additionalProperties.containsKey("supportsAsync")) {
|
||||||
additionalProperties.remove("supportsAsync");
|
additionalProperties.remove("supportsAsync");
|
||||||
}
|
}
|
||||||
additionalProperties.put("validatable", false);
|
additionalProperties.put("validatable", false);
|
||||||
additionalProperties.put("net35", true);
|
additionalProperties.put("net35", true);
|
||||||
} else if (NETSTANDARD.equals(this.targetFramework)){
|
} else if (NETSTANDARD.equals(this.targetFramework)) {
|
||||||
setTargetFrameworkNuget("netstandard1.3");
|
setTargetFrameworkNuget("netstandard1.3");
|
||||||
setSupportsAsync(Boolean.TRUE);
|
setSupportsAsync(Boolean.TRUE);
|
||||||
setSupportsUWP(Boolean.FALSE);
|
setSupportsUWP(Boolean.FALSE);
|
||||||
@ -232,11 +217,11 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
//Tests not yet implemented for .NET Standard codegen
|
//Tests not yet implemented for .NET Standard codegen
|
||||||
//Todo implement it
|
//Todo implement it
|
||||||
excludeTests = true;
|
excludeTests = true;
|
||||||
if(additionalProperties.containsKey(CodegenConstants.EXCLUDE_TESTS)){
|
if (additionalProperties.containsKey(CodegenConstants.EXCLUDE_TESTS)) {
|
||||||
additionalProperties.remove(CodegenConstants.EXCLUDE_TESTS);
|
additionalProperties.remove(CodegenConstants.EXCLUDE_TESTS);
|
||||||
}
|
}
|
||||||
additionalProperties.put(CodegenConstants.EXCLUDE_TESTS, excludeTests);
|
additionalProperties.put(CodegenConstants.EXCLUDE_TESTS, excludeTests);
|
||||||
} else if (UWP.equals(this.targetFramework)){
|
} else if (UWP.equals(this.targetFramework)) {
|
||||||
setTargetFrameworkNuget("uwp");
|
setTargetFrameworkNuget("uwp");
|
||||||
setSupportsAsync(Boolean.TRUE);
|
setSupportsAsync(Boolean.TRUE);
|
||||||
setSupportsUWP(Boolean.TRUE);
|
setSupportsUWP(Boolean.TRUE);
|
||||||
@ -249,18 +234,18 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
additionalProperties.put("supportsAsync", this.supportsAsync);
|
additionalProperties.put("supportsAsync", this.supportsAsync);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(additionalProperties.containsKey(CodegenConstants.GENERATE_PROPERTY_CHANGED)) {
|
if (additionalProperties.containsKey(CodegenConstants.GENERATE_PROPERTY_CHANGED)) {
|
||||||
if(NET35.equals(targetFramework)) {
|
if (NET35.equals(targetFramework)) {
|
||||||
LOGGER.warn(CodegenConstants.GENERATE_PROPERTY_CHANGED + " is only supported by generated code for .NET 4+.");
|
LOGGER.warn(CodegenConstants.GENERATE_PROPERTY_CHANGED + " is only supported by generated code for .NET 4+.");
|
||||||
} else if(NETSTANDARD.equals(targetFramework)) {
|
} else if (NETSTANDARD.equals(targetFramework)) {
|
||||||
LOGGER.warn(CodegenConstants.GENERATE_PROPERTY_CHANGED + " is not supported in .NET Standard generated code.");
|
LOGGER.warn(CodegenConstants.GENERATE_PROPERTY_CHANGED + " is not supported in .NET Standard generated code.");
|
||||||
} else if(Boolean.TRUE.equals(netCoreProjectFileFlag)) {
|
} else if (Boolean.TRUE.equals(netCoreProjectFileFlag)) {
|
||||||
LOGGER.warn(CodegenConstants.GENERATE_PROPERTY_CHANGED + " is not supported in .NET Core csproj project format.");
|
LOGGER.warn(CodegenConstants.GENERATE_PROPERTY_CHANGED + " is not supported in .NET Core csproj project format.");
|
||||||
} else {
|
} else {
|
||||||
setGeneratePropertyChanged(Boolean.valueOf(additionalProperties.get(CodegenConstants.GENERATE_PROPERTY_CHANGED).toString()));
|
setGeneratePropertyChanged(Boolean.valueOf(additionalProperties.get(CodegenConstants.GENERATE_PROPERTY_CHANGED).toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Boolean.FALSE.equals(this.generatePropertyChanged)) {
|
if (Boolean.FALSE.equals(this.generatePropertyChanged)) {
|
||||||
additionalProperties.remove(CodegenConstants.GENERATE_PROPERTY_CHANGED);
|
additionalProperties.remove(CodegenConstants.GENERATE_PROPERTY_CHANGED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -322,8 +307,10 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
clientPackageDir, "ExceptionFactory.cs"));
|
clientPackageDir, "ExceptionFactory.cs"));
|
||||||
supportingFiles.add(new SupportingFile("SwaggerDateConverter.mustache",
|
supportingFiles.add(new SupportingFile("SwaggerDateConverter.mustache",
|
||||||
clientPackageDir, "SwaggerDateConverter.cs"));
|
clientPackageDir, "SwaggerDateConverter.cs"));
|
||||||
|
supportingFiles.add(new SupportingFile("JsonSubTypes.mustache",
|
||||||
|
clientPackageDir, "JsonSubTypes.cs"));
|
||||||
|
|
||||||
if(Boolean.FALSE.equals(this.netStandard) && Boolean.FALSE.equals(this.netCoreProjectFileFlag)) {
|
if (Boolean.FALSE.equals(this.netStandard) && Boolean.FALSE.equals(this.netCoreProjectFileFlag)) {
|
||||||
supportingFiles.add(new SupportingFile("compile.mustache", "", "build.bat"));
|
supportingFiles.add(new SupportingFile("compile.mustache", "", "build.bat"));
|
||||||
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "build.sh"));
|
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "build.sh"));
|
||||||
|
|
||||||
@ -331,7 +318,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
supportingFiles.add(new SupportingFile("packages.config.mustache", packageFolder + File.separator, "packages.config"));
|
supportingFiles.add(new SupportingFile("packages.config.mustache", packageFolder + File.separator, "packages.config"));
|
||||||
// .travis.yml for travis-ci.org CI
|
// .travis.yml for travis-ci.org CI
|
||||||
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));
|
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));
|
||||||
} else if(Boolean.FALSE.equals(this.netCoreProjectFileFlag)) {
|
} else if (Boolean.FALSE.equals(this.netCoreProjectFileFlag)) {
|
||||||
supportingFiles.add(new SupportingFile("project.json.mustache", packageFolder + File.separator, "project.json"));
|
supportingFiles.add(new SupportingFile("project.json.mustache", packageFolder + File.separator, "project.json"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,7 +328,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
clientPackageDir, "GlobalConfiguration.cs"));
|
clientPackageDir, "GlobalConfiguration.cs"));
|
||||||
|
|
||||||
// Only write out test related files if excludeTests is unset or explicitly set to false (see start of this method)
|
// Only write out test related files if excludeTests is unset or explicitly set to false (see start of this method)
|
||||||
if(Boolean.FALSE.equals(excludeTests)) {
|
if (Boolean.FALSE.equals(excludeTests)) {
|
||||||
// shell script to run the nunit test
|
// shell script to run the nunit test
|
||||||
supportingFiles.add(new SupportingFile("mono_nunit_test.mustache", "", "mono_nunit_test.sh"));
|
supportingFiles.add(new SupportingFile("mono_nunit_test.mustache", "", "mono_nunit_test.sh"));
|
||||||
|
|
||||||
@ -353,7 +340,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Boolean.TRUE.equals(generatePropertyChanged)) {
|
if (Boolean.TRUE.equals(generatePropertyChanged)) {
|
||||||
supportingFiles.add(new SupportingFile("FodyWeavers.xml", packageFolder, "FodyWeavers.xml"));
|
supportingFiles.add(new SupportingFile("FodyWeavers.xml", packageFolder, "FodyWeavers.xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,19 +356,19 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
}
|
}
|
||||||
if (optionalProjectFileFlag) {
|
if (optionalProjectFileFlag) {
|
||||||
supportingFiles.add(new SupportingFile("Solution.mustache", "", packageName + ".sln"));
|
supportingFiles.add(new SupportingFile("Solution.mustache", "", packageName + ".sln"));
|
||||||
|
|
||||||
if(Boolean.TRUE.equals(this.netCoreProjectFileFlag)) {
|
if (Boolean.TRUE.equals(this.netCoreProjectFileFlag)) {
|
||||||
supportingFiles.add(new SupportingFile("netcore_project.mustache", packageFolder, packageName + ".csproj"));
|
supportingFiles.add(new SupportingFile("netcore_project.mustache", packageFolder, packageName + ".csproj"));
|
||||||
} else {
|
} else {
|
||||||
supportingFiles.add(new SupportingFile("Project.mustache", packageFolder, packageName + ".csproj"));
|
supportingFiles.add(new SupportingFile("Project.mustache", packageFolder, packageName + ".csproj"));
|
||||||
if(Boolean.FALSE.equals(this.netStandard)) {
|
if (Boolean.FALSE.equals(this.netStandard)) {
|
||||||
supportingFiles.add(new SupportingFile("nuspec.mustache", packageFolder, packageName + ".nuspec"));
|
supportingFiles.add(new SupportingFile("nuspec.mustache", packageFolder, packageName + ".nuspec"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Boolean.FALSE.equals(excludeTests)) {
|
if (Boolean.FALSE.equals(excludeTests)) {
|
||||||
// NOTE: This exists here rather than previous excludeTests block because the test project is considered an optional project file.
|
// NOTE: This exists here rather than previous excludeTests block because the test project is considered an optional project file.
|
||||||
if(Boolean.TRUE.equals(this.netCoreProjectFileFlag)) {
|
if (Boolean.TRUE.equals(this.netCoreProjectFileFlag)) {
|
||||||
supportingFiles.add(new SupportingFile("netcore_testproject.mustache", testPackageFolder, testPackageName + ".csproj"));
|
supportingFiles.add(new SupportingFile("netcore_testproject.mustache", testPackageFolder, testPackageName + ".csproj"));
|
||||||
} else {
|
} else {
|
||||||
supportingFiles.add(new SupportingFile("TestProject.mustache", testPackageFolder, testPackageName + ".csproj"));
|
supportingFiles.add(new SupportingFile("TestProject.mustache", testPackageFolder, testPackageName + ".csproj"));
|
||||||
@ -457,10 +444,54 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) {
|
public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) {
|
||||||
CodegenModel codegenModel = super.fromModel(name, model, allDefinitions);
|
CodegenModel codegenModel = super.fromModel(name, model, allDefinitions);
|
||||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
|
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null) {
|
||||||
final Model parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
final Model parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
||||||
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
if (parentModel != null) {
|
||||||
codegenModel = this.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
||||||
|
if (codegenModel.hasEnums) {
|
||||||
|
codegenModel = this.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, CodegenProperty> propertyHash = new HashMap<>(codegenModel.vars.size());
|
||||||
|
for (final CodegenProperty property : codegenModel.vars) {
|
||||||
|
propertyHash.put(property.name, property);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final CodegenProperty property : codegenModel.readWriteVars) {
|
||||||
|
if (property.defaultValue == null && property.baseName.equals(parentCodegenModel.discriminator)) {
|
||||||
|
property.defaultValue = "\"" + name + "\"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CodegenProperty last = null;
|
||||||
|
for (final CodegenProperty property : parentCodegenModel.vars) {
|
||||||
|
// helper list of parentVars simplifies templating
|
||||||
|
if (!propertyHash.containsKey(property.name)) {
|
||||||
|
final CodegenProperty parentVar = property.clone();
|
||||||
|
parentVar.isInherited = true;
|
||||||
|
parentVar.hasMore = true;
|
||||||
|
last = parentVar;
|
||||||
|
LOGGER.info("adding parent variable {}", property.name);
|
||||||
|
codegenModel.parentVars.add(parentVar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (last != null) {
|
||||||
|
last.hasMore = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup possible duplicates. Currently, readWriteVars can contain the same property twice. May or may not be isolated to C#.
|
||||||
|
if (codegenModel != null && codegenModel.readWriteVars != null && codegenModel.readWriteVars.size() > 1) {
|
||||||
|
int length = codegenModel.readWriteVars.size() - 1;
|
||||||
|
for (int i = length; i > (length / 2); i--) {
|
||||||
|
final CodegenProperty codegenProperty = codegenModel.readWriteVars.get(i);
|
||||||
|
// If the property at current index is found earlier in the list, remove this last instance.
|
||||||
|
if (codegenModel.readWriteVars.indexOf(codegenProperty) < i) {
|
||||||
|
codegenModel.readWriteVars.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return codegenModel;
|
return codegenModel;
|
||||||
@ -500,13 +531,13 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
* See https://github.com/swagger-api/swagger-codegen/pull/2794 for Python's initial implementation from which this is copied.
|
* See https://github.com/swagger-api/swagger-codegen/pull/2794 for Python's initial implementation from which this is copied.
|
||||||
*/
|
*/
|
||||||
public void postProcessPattern(String pattern, Map<String, Object> vendorExtensions) {
|
public void postProcessPattern(String pattern, Map<String, Object> vendorExtensions) {
|
||||||
if(pattern != null) {
|
if (pattern != null) {
|
||||||
int i = pattern.lastIndexOf('/');
|
int i = pattern.lastIndexOf('/');
|
||||||
|
|
||||||
//Must follow Perl /pattern/modifiers convention
|
//Must follow Perl /pattern/modifiers convention
|
||||||
if(pattern.charAt(0) != '/' || i < 2) {
|
if (pattern.charAt(0) != '/' || i < 2) {
|
||||||
throw new IllegalArgumentException("Pattern must follow the Perl "
|
throw new IllegalArgumentException("Pattern must follow the Perl "
|
||||||
+ "/pattern/modifiers convention. "+pattern+" is not valid.");
|
+ "/pattern/modifiers convention. " + pattern + " is not valid.");
|
||||||
}
|
}
|
||||||
|
|
||||||
String regex = pattern.substring(1, i).replace("'", "\'");
|
String regex = pattern.substring(1, i).replace("'", "\'");
|
||||||
@ -515,8 +546,8 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
// perl requires an explicit modifier to be culture specific and .NET is the reverse.
|
// perl requires an explicit modifier to be culture specific and .NET is the reverse.
|
||||||
modifiers.add("CultureInvariant");
|
modifiers.add("CultureInvariant");
|
||||||
|
|
||||||
for(char c : pattern.substring(i).toCharArray()) {
|
for (char c : pattern.substring(i).toCharArray()) {
|
||||||
if(regexModifiers.containsKey(c)) {
|
if (regexModifiers.containsKey(c)) {
|
||||||
String modifier = regexModifiers.get(c);
|
String modifier = regexModifiers.get(c);
|
||||||
modifiers.add(modifier);
|
modifiers.add(modifier);
|
||||||
} else if (c == 'l') {
|
} else if (c == 'l') {
|
||||||
@ -530,7 +561,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setTargetFramework(String dotnetFramework) {
|
public void setTargetFramework(String dotnetFramework) {
|
||||||
if(!frameworks.containsKey(dotnetFramework)){
|
if (!frameworks.containsKey(dotnetFramework)) {
|
||||||
LOGGER.warn("Invalid .NET framework version, defaulting to " + this.targetFramework);
|
LOGGER.warn("Invalid .NET framework version, defaulting to " + this.targetFramework);
|
||||||
} else {
|
} else {
|
||||||
this.targetFramework = dotnetFramework;
|
this.targetFramework = dotnetFramework;
|
||||||
@ -572,10 +603,10 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(removedChildEnum) {
|
if (removedChildEnum) {
|
||||||
// If we removed an entry from this model's vars, we need to ensure hasMore is updated
|
// If we removed an entry from this model's vars, we need to ensure hasMore is updated
|
||||||
int count = 0, numVars = codegenProperties.size();
|
int count = 0, numVars = codegenProperties.size();
|
||||||
for(CodegenProperty codegenProperty : codegenProperties) {
|
for (CodegenProperty codegenProperty : codegenProperties) {
|
||||||
count += 1;
|
count += 1;
|
||||||
codegenProperty.hasMore = count < numVars;
|
codegenProperty.hasMore = count < numVars;
|
||||||
}
|
}
|
||||||
@ -589,7 +620,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public String toEnumValue(String value, String datatype) {
|
public String toEnumValue(String value, String datatype) {
|
||||||
if ("int?".equalsIgnoreCase(datatype) || "long?".equalsIgnoreCase(datatype) ||
|
if ("int?".equalsIgnoreCase(datatype) || "long?".equalsIgnoreCase(datatype) ||
|
||||||
"double?".equalsIgnoreCase(datatype) || "float?".equalsIgnoreCase(datatype)) {
|
"double?".equalsIgnoreCase(datatype) || "float?".equalsIgnoreCase(datatype)) {
|
||||||
return value;
|
return value;
|
||||||
} else if ("float?".equalsIgnoreCase(datatype)) {
|
} else if ("float?".equalsIgnoreCase(datatype)) {
|
||||||
// for float in C#, append "f". e.g. 3.14 => 3.14f
|
// for float in C#, append "f". e.g. 3.14 => 3.14f
|
||||||
@ -611,8 +642,8 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// number
|
// number
|
||||||
if ("int?".equals(datatype) || "long?".equals(datatype) ||
|
if ("int?".equals(datatype) || "long?".equals(datatype) ||
|
||||||
"double?".equals(datatype) || "float?".equals(datatype)) {
|
"double?".equals(datatype) || "float?".equals(datatype)) {
|
||||||
String varName = "NUMBER_" + value;
|
String varName = "NUMBER_" + value;
|
||||||
varName = varName.replaceAll("-", "MINUS_");
|
varName = varName.replaceAll("-", "MINUS_");
|
||||||
varName = varName.replaceAll("\\+", "PLUS_");
|
varName = varName.replaceAll("\\+", "PLUS_");
|
||||||
@ -678,19 +709,19 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
|||||||
this.targetFrameworkNuget = targetFrameworkNuget;
|
this.targetFrameworkNuget = targetFrameworkNuget;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSupportsAsync(Boolean supportsAsync){
|
public void setSupportsAsync(Boolean supportsAsync) {
|
||||||
this.supportsAsync = supportsAsync;
|
this.supportsAsync = supportsAsync;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSupportsUWP(Boolean supportsUWP){
|
public void setSupportsUWP(Boolean supportsUWP) {
|
||||||
this.supportsUWP = supportsUWP;
|
this.supportsUWP = supportsUWP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNetStandard(Boolean netStandard){
|
public void setNetStandard(Boolean netStandard) {
|
||||||
this.netStandard = netStandard;
|
this.netStandard = netStandard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGeneratePropertyChanged(final Boolean generatePropertyChanged){
|
public void setGeneratePropertyChanged(final Boolean generatePropertyChanged) {
|
||||||
this.generatePropertyChanged = generatePropertyChanged;
|
this.generatePropertyChanged = generatePropertyChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,272 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace JsonSubTypes
|
||||||
|
{
|
||||||
|
// Copied from project https://github.com/manuc66/JsonSubTypes
|
||||||
|
// https://raw.githubusercontent.com/manuc66/JsonSubTypes/07403192ea3f4959f6d42f5966ac56ceb0d6095b/JsonSubTypes/JsonSubtypes.cs
|
||||||
|
|
||||||
|
public class JsonSubtypes : JsonConverter
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
|
||||||
|
public class KnownSubTypeAttribute : Attribute
|
||||||
|
{
|
||||||
|
public Type SubType { get; private set; }
|
||||||
|
public object AssociatedValue { get; private set; }
|
||||||
|
|
||||||
|
public KnownSubTypeAttribute(Type subType, object associatedValue)
|
||||||
|
{
|
||||||
|
SubType = subType;
|
||||||
|
AssociatedValue = associatedValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
|
||||||
|
public class KnownSubTypeWithPropertyAttribute : Attribute
|
||||||
|
{
|
||||||
|
public Type SubType { get; private set; }
|
||||||
|
public string PropertyName { get; private set; }
|
||||||
|
|
||||||
|
public KnownSubTypeWithPropertyAttribute(Type subType, string propertyName)
|
||||||
|
{
|
||||||
|
SubType = subType;
|
||||||
|
PropertyName = propertyName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _typeMappingPropertyName;
|
||||||
|
|
||||||
|
private bool _isInsideRead;
|
||||||
|
private JsonReader _reader;
|
||||||
|
|
||||||
|
public override bool CanRead
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!_isInsideRead)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return !string.IsNullOrEmpty(_reader.Path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed override bool CanWrite
|
||||||
|
{
|
||||||
|
get { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonSubtypes()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonSubtypes(string typeMappingPropertyName)
|
||||||
|
{
|
||||||
|
_typeMappingPropertyName = typeMappingPropertyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanConvert(Type objectType)
|
||||||
|
{
|
||||||
|
return _typeMappingPropertyName != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
if (reader.TokenType == JsonToken.Comment)
|
||||||
|
reader.Read();
|
||||||
|
|
||||||
|
switch (reader.TokenType)
|
||||||
|
{
|
||||||
|
case JsonToken.Null:
|
||||||
|
return null;
|
||||||
|
case JsonToken.StartArray:
|
||||||
|
return ReadArray(reader, objectType, serializer);
|
||||||
|
case JsonToken.StartObject:
|
||||||
|
return ReadObject(reader, objectType, serializer);
|
||||||
|
default:
|
||||||
|
throw new Exception("Array: Unrecognized token: " + reader.TokenType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IList ReadArray(JsonReader reader, Type targetType, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
var elementType = GetElementType(targetType);
|
||||||
|
|
||||||
|
var list = CreateCompatibleList(targetType, elementType);
|
||||||
|
|
||||||
|
while (reader.TokenType != JsonToken.EndArray && reader.Read())
|
||||||
|
{
|
||||||
|
switch (reader.TokenType)
|
||||||
|
{
|
||||||
|
case JsonToken.Null:
|
||||||
|
list.Add(reader.Value);
|
||||||
|
break;
|
||||||
|
case JsonToken.Comment:
|
||||||
|
break;
|
||||||
|
case JsonToken.StartObject:
|
||||||
|
list.Add(ReadObject(reader, elementType, serializer));
|
||||||
|
break;
|
||||||
|
case JsonToken.EndArray:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("Array: Unrecognized token: " + reader.TokenType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (targetType.IsArray)
|
||||||
|
{
|
||||||
|
var array = Array.CreateInstance(targetType.GetElementType(), list.Count);
|
||||||
|
list.CopyTo(array, 0);
|
||||||
|
list = array;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IList CreateCompatibleList(Type targetContainerType, Type elementType)
|
||||||
|
{
|
||||||
|
IList list;
|
||||||
|
if (targetContainerType.IsArray || targetContainerType.GetTypeInfo().IsAbstract)
|
||||||
|
{
|
||||||
|
list = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list = (IList)Activator.CreateInstance(targetContainerType);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetElementType(Type arrayOrGenericContainer)
|
||||||
|
{
|
||||||
|
Type elementType;
|
||||||
|
if (arrayOrGenericContainer.IsArray)
|
||||||
|
{
|
||||||
|
elementType = arrayOrGenericContainer.GetElementType();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
elementType = arrayOrGenericContainer.GenericTypeArguments[0];
|
||||||
|
}
|
||||||
|
return elementType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private object ReadObject(JsonReader reader, Type objectType, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
var jObject = JObject.Load(reader);
|
||||||
|
|
||||||
|
var targetType = GetType(jObject, objectType) ?? objectType;
|
||||||
|
|
||||||
|
return _ReadJson(CreateAnotherReader(jObject, reader), targetType, null, serializer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonReader CreateAnotherReader(JObject jObject, JsonReader reader)
|
||||||
|
{
|
||||||
|
var jObjectReader = jObject.CreateReader();
|
||||||
|
jObjectReader.Culture = reader.Culture;
|
||||||
|
jObjectReader.CloseInput = reader.CloseInput;
|
||||||
|
jObjectReader.SupportMultipleContent = reader.SupportMultipleContent;
|
||||||
|
jObjectReader.DateTimeZoneHandling = reader.DateTimeZoneHandling;
|
||||||
|
jObjectReader.FloatParseHandling = reader.FloatParseHandling;
|
||||||
|
jObjectReader.DateFormatString = reader.DateFormatString;
|
||||||
|
jObjectReader.DateParseHandling = reader.DateParseHandling;
|
||||||
|
return jObjectReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type GetType(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
if (_typeMappingPropertyName == null)
|
||||||
|
{
|
||||||
|
return GetTypeByPropertyPresence(jObject, parentType);
|
||||||
|
}
|
||||||
|
return GetTypeFromDiscriminatorValue(jObject, parentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeByPropertyPresence(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
foreach (var type in parentType.GetTypeInfo().GetCustomAttributes<KnownSubTypeWithPropertyAttribute>())
|
||||||
|
{
|
||||||
|
JToken ignore;
|
||||||
|
if (jObject.TryGetValue(type.PropertyName, out ignore))
|
||||||
|
{
|
||||||
|
return type.SubType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Type GetTypeFromDiscriminatorValue(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
JToken jToken;
|
||||||
|
if (!jObject.TryGetValue(_typeMappingPropertyName, out jToken)) return null;
|
||||||
|
|
||||||
|
var discriminatorValue = jToken.ToObject<object>();
|
||||||
|
if (discriminatorValue == null) return null;
|
||||||
|
|
||||||
|
var typeMapping = GetSubTypeMapping(parentType);
|
||||||
|
if (typeMapping.Any())
|
||||||
|
{
|
||||||
|
return GetTypeFromMapping(typeMapping, discriminatorValue);
|
||||||
|
}
|
||||||
|
return GetTypeByName(discriminatorValue as string, parentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeByName(string typeName, Type parentType)
|
||||||
|
{
|
||||||
|
if (typeName == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var insideAssembly = parentType.GetTypeInfo().Assembly;
|
||||||
|
|
||||||
|
var typeByName = insideAssembly.GetType(typeName);
|
||||||
|
if (typeByName == null)
|
||||||
|
{
|
||||||
|
var searchLocation = parentType.FullName.Substring(0, parentType.FullName.Length - parentType.Name.Length);
|
||||||
|
typeByName = insideAssembly.GetType(searchLocation + typeName, false, true);
|
||||||
|
}
|
||||||
|
return typeByName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeFromMapping(IReadOnlyDictionary<object, Type> typeMapping, object discriminatorValue)
|
||||||
|
{
|
||||||
|
var targetlookupValueType = typeMapping.First().Key.GetType();
|
||||||
|
var lookupValue = ConvertJsonValueToType(discriminatorValue, targetlookupValueType);
|
||||||
|
|
||||||
|
Type targetType;
|
||||||
|
return typeMapping.TryGetValue(lookupValue, out targetType) ? targetType : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Dictionary<object, Type> GetSubTypeMapping(Type type)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().GetCustomAttributes<KnownSubTypeAttribute>().ToDictionary(x => x.AssociatedValue, x => x.SubType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static object ConvertJsonValueToType(object objectType, Type targetlookupValueType)
|
||||||
|
{
|
||||||
|
if (targetlookupValueType.GetTypeInfo().IsEnum)
|
||||||
|
return Enum.ToObject(targetlookupValueType, objectType);
|
||||||
|
|
||||||
|
return Convert.ChangeType(objectType, targetlookupValueType);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected object _ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
_reader = reader;
|
||||||
|
_isInsideRead = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return serializer.Deserialize(reader, objectType);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isInsideRead = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,21 +7,21 @@ EndProject
|
|||||||
{{^excludeTests}}Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "{{testPackageName}}", "src\{{testPackageName}}\{{testPackageName}}.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"
|
{{^excludeTests}}Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "{{testPackageName}}", "src\{{testPackageName}}\{{testPackageName}}.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"
|
||||||
EndProject
|
EndProject
|
||||||
{{/excludeTests}}Global
|
{{/excludeTests}}Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{{packageGuid}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{{packageGuid}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{{packageGuid}}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{{packageGuid}}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{{packageGuid}}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{{packageGuid}}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{{packageGuid}}.Release|Any CPU.Build.0 = Release|Any CPU
|
{{packageGuid}}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.Build.0 = Release|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
@ -12,6 +12,13 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
{{#models}}
|
||||||
|
{{#model}}
|
||||||
|
{{#discriminator}}
|
||||||
|
using JsonSubTypes;
|
||||||
|
{{/discriminator}}
|
||||||
|
{{/model}}
|
||||||
|
{{/models}}
|
||||||
{{^netStandard}}
|
{{^netStandard}}
|
||||||
{{#generatePropertyChanged}}
|
{{#generatePropertyChanged}}
|
||||||
using PropertyChanged;
|
using PropertyChanged;
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
/// {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
|
/// {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataContract]
|
[DataContract]
|
||||||
|
{{#discriminator}}
|
||||||
|
[JsonConverter(typeof(JsonSubtypes), "{{discriminator}}")]{{#children}}
|
||||||
|
[JsonSubtypes.KnownSubType(typeof({{classname}}), "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}")]{{/children}}
|
||||||
|
{{/discriminator}}
|
||||||
{{#generatePropertyChanged}}
|
{{#generatePropertyChanged}}
|
||||||
[ImplementPropertyChanged]
|
[ImplementPropertyChanged]
|
||||||
{{/generatePropertyChanged}}
|
{{/generatePropertyChanged}}
|
||||||
@ -49,9 +53,10 @@
|
|||||||
{{#hasOnlyReadOnly}}
|
{{#hasOnlyReadOnly}}
|
||||||
[JsonConstructorAttribute]
|
[JsonConstructorAttribute]
|
||||||
{{/hasOnlyReadOnly}}
|
{{/hasOnlyReadOnly}}
|
||||||
public {{classname}}({{#readWriteVars}}{{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}} {{name}} = {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}default({{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}}){{/defaultValue}}{{^-last}}, {{/-last}}{{/readWriteVars}})
|
public {{classname}}({{#readWriteVars}}{{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}} {{name}} = {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}default({{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}}){{/defaultValue}}{{^-last}}, {{/-last}}{{/readWriteVars}}){{#parent}} : base({{#parentVars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/parentVars}}){{/parent}}
|
||||||
{
|
{
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
|
{{^isInherited}}
|
||||||
{{^isReadOnly}}
|
{{^isReadOnly}}
|
||||||
{{#required}}
|
{{#required}}
|
||||||
// to ensure "{{name}}" is required (not null)
|
// to ensure "{{name}}" is required (not null)
|
||||||
@ -65,8 +70,10 @@
|
|||||||
}
|
}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{/isReadOnly}}
|
{{/isReadOnly}}
|
||||||
|
{{/isInherited}}
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
|
{{^isInherited}}
|
||||||
{{^isReadOnly}}
|
{{^isReadOnly}}
|
||||||
{{^required}}
|
{{^required}}
|
||||||
{{#defaultValue}}// use default value if no "{{name}}" provided
|
{{#defaultValue}}// use default value if no "{{name}}" provided
|
||||||
@ -84,10 +91,12 @@ this.{{name}} = {{name}};
|
|||||||
{{/defaultValue}}
|
{{/defaultValue}}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{/isReadOnly}}
|
{{/isReadOnly}}
|
||||||
|
{{/isInherited}}
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
|
{{^isInherited}}
|
||||||
{{^isEnum}}
|
{{^isEnum}}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
|
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
|
||||||
@ -97,6 +106,7 @@ this.{{name}} = {{name}};
|
|||||||
[JsonConverter(typeof(SwaggerDateConverter))]{{/isDate}}
|
[JsonConverter(typeof(SwaggerDateConverter))]{{/isDate}}
|
||||||
public {{{datatype}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; }
|
public {{{datatype}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; }
|
||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
|
{{/isInherited}}
|
||||||
|
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -107,6 +117,9 @@ this.{{name}} = {{name}};
|
|||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class {{classname}} {\n");
|
sb.Append("class {{classname}} {\n");
|
||||||
|
{{#parent}}
|
||||||
|
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
|
||||||
|
{{/parent}}
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
sb.Append(" {{name}}: ").Append({{name}}).Append("\n");
|
sb.Append(" {{name}}: ").Append({{name}}).Append("\n");
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
@ -118,7 +131,7 @@ this.{{name}} = {{name}};
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public {{#parent}} new {{/parent}}string ToJson()
|
public {{#parent}}{{^isArrayModel}}override {{/isArrayModel}}{{/parent}}{{^parent}}{{#discriminator}}virtual {{/discriminator}}{{/parent}}string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -143,7 +156,7 @@ this.{{name}} = {{name}};
|
|||||||
if (input == null)
|
if (input == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return {{#vars}}{{#isNotContainer}}
|
return {{#vars}}{{#parent}}base.Equals(input) && {{/parent}}{{#isNotContainer}}
|
||||||
(
|
(
|
||||||
this.{{name}} == input.{{name}} ||
|
this.{{name}} == input.{{name}} ||
|
||||||
(this.{{name}} != null &&
|
(this.{{name}} != null &&
|
||||||
@ -151,9 +164,9 @@ this.{{name}} = {{name}};
|
|||||||
){{#hasMore}} && {{/hasMore}}{{/isNotContainer}}{{^isNotContainer}}
|
){{#hasMore}} && {{/hasMore}}{{/isNotContainer}}{{^isNotContainer}}
|
||||||
(
|
(
|
||||||
this.{{name}} == input.{{name}} ||
|
this.{{name}} == input.{{name}} ||
|
||||||
(this.{{name}} != null &&
|
this.{{name}} != null &&
|
||||||
this.{{name}}.SequenceEqual(input.{{name}}))
|
this.{{name}}.SequenceEqual(input.{{name}})
|
||||||
){{#hasMore}} && {{/hasMore}}{{/isNotContainer}}{{/vars}}{{^vars}}false{{/vars}};
|
){{#hasMore}} && {{/hasMore}}{{/isNotContainer}}{{/vars}}{{^vars}}{{#parent}}base.Equals(input){{/parent}}{{^parent}}false{{/parent}}{{/vars}};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -164,7 +177,12 @@ this.{{name}} = {{name}};
|
|||||||
{
|
{
|
||||||
unchecked // Overflow is fine, just wrap
|
unchecked // Overflow is fine, just wrap
|
||||||
{
|
{
|
||||||
|
{{#parent}}
|
||||||
|
int hashCode = base.GetHashCode();
|
||||||
|
{{/parent}}
|
||||||
|
{{^parent}}
|
||||||
int hashCode = 41;
|
int hashCode = 41;
|
||||||
|
{{/parent}}
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
if (this.{{name}} != null)
|
if (this.{{name}} != null)
|
||||||
hashCode = hashCode * 59 + this.{{name}}.GetHashCode();
|
hashCode = hashCode * 59 + this.{{name}}.GetHashCode();
|
||||||
@ -197,6 +215,7 @@ this.{{name}} = {{name}};
|
|||||||
|
|
||||||
{{/generatePropertyChanged}}
|
{{/generatePropertyChanged}}
|
||||||
{{#validatable}}
|
{{#validatable}}
|
||||||
|
{{#discriminator}}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// To validate all properties of the instance
|
/// To validate all properties of the instance
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -204,6 +223,31 @@ this.{{name}} = {{name}};
|
|||||||
/// <returns>Validation Result</returns>
|
/// <returns>Validation Result</returns>
|
||||||
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
||||||
{
|
{
|
||||||
|
return this.BaseValidate(validationContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// To validate all properties of the instance
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext">Validation context</param>
|
||||||
|
/// <returns>Validation Result</returns>
|
||||||
|
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
|
||||||
|
{
|
||||||
|
{{/discriminator}}
|
||||||
|
{{^discriminator}}
|
||||||
|
/// <summary>
|
||||||
|
/// To validate all properties of the instance
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext">Validation context</param>
|
||||||
|
/// <returns>Validation Result</returns>
|
||||||
|
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
||||||
|
{
|
||||||
|
{{/discriminator}}
|
||||||
|
{{#parent}}
|
||||||
|
{{^isArrayModel}}
|
||||||
|
foreach(var x in BaseValidate(validationContext)) yield return x;
|
||||||
|
{{/isArrayModel}}
|
||||||
|
{{/parent}}
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
{{#hasValidation}}
|
{{#hasValidation}}
|
||||||
{{#maxLength}}
|
{{#maxLength}}
|
||||||
|
@ -5,6 +5,11 @@
|
|||||||
|
|
||||||
Name | Type | Description | Notes
|
Name | Type | Description | Notes
|
||||||
------------ | ------------- | ------------- | -------------
|
------------ | ------------- | ------------- | -------------
|
||||||
|
{{#parent}}
|
||||||
|
{{#parentVars}}
|
||||||
|
**{{name}}** | {{#isPrimitiveType}}**{{datatype}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{datatype}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{{.}}}]{{/defaultValue}}
|
||||||
|
{{/parentVars}}
|
||||||
|
{{/parent}}
|
||||||
{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{datatype}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{datatype}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{{.}}}]{{/defaultValue}}
|
{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{datatype}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{datatype}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{{.}}}]{{/defaultValue}}
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ using {{packageName}}.{{apiPackage}};
|
|||||||
using {{packageName}}.{{modelPackage}};
|
using {{packageName}}.{{modelPackage}};
|
||||||
using {{packageName}}.Client;
|
using {{packageName}}.Client;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
{{#models}}
|
{{#models}}
|
||||||
{{#model}}
|
{{#model}}
|
||||||
@ -57,6 +58,20 @@ namespace {{packageName}}.Test
|
|||||||
//Assert.IsInstanceOfType<{{classname}}> (instance, "variable 'instance' is a {{classname}}");
|
//Assert.IsInstanceOfType<{{classname}}> (instance, "variable 'instance' is a {{classname}}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{{#discriminator}}
|
||||||
|
{{#children}}
|
||||||
|
/// <summary>
|
||||||
|
/// Test deserialize a {{classname}} from type {{parent}}
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void {{classname}}DeserializeFrom{{parent}}Test()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to test deserialize a {{classname}} from type {{parent}}
|
||||||
|
//Assert.IsInstanceOf<{{parent}}>(JsonConvert.DeserializeObject<{{parent}}>(new {{classname}}().ToJson()));
|
||||||
|
}
|
||||||
|
{{/children}}
|
||||||
|
{{/discriminator}}
|
||||||
|
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test the property '{{name}}'
|
/// Test the property '{{name}}'
|
||||||
|
@ -1 +1 @@
|
|||||||
2.2.3-SNAPSHOT
|
2.3.0-SNAPSHOT
|
@ -7,21 +7,21 @@ EndProject
|
|||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger.Test", "src\IO.Swagger.Test\IO.Swagger.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger.Test", "src\IO.Swagger.Test\IO.Swagger.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{8CE139DF-64BC-4591-85F8-8506C2B67514}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{8CE139DF-64BC-4591-85F8-8506C2B67514}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{8CE139DF-64BC-4591-85F8-8506C2B67514}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{8CE139DF-64BC-4591-85F8-8506C2B67514}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{8CE139DF-64BC-4591-85F8-8506C2B67514}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{8CE139DF-64BC-4591-85F8-8506C2B67514}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{8CE139DF-64BC-4591-85F8-8506C2B67514}.Release|Any CPU.Build.0 = Release|Any CPU
|
{8CE139DF-64BC-4591-85F8-8506C2B67514}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.Build.0 = Release|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
@ -83,15 +83,9 @@ namespace IO.Swagger.Api
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public FakeApi(String basePath)
|
public FakeApi(String basePath)
|
||||||
{
|
{
|
||||||
this.Configuration = new Configuration(new ApiClient(basePath));
|
this.Configuration = new Configuration { BasePath = basePath };
|
||||||
|
|
||||||
ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory;
|
ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory;
|
||||||
|
|
||||||
// ensure API client has configuration ready
|
|
||||||
if (Configuration.ApiClient.Configuration == null)
|
|
||||||
{
|
|
||||||
this.Configuration.ApiClient.Configuration = this.Configuration;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -108,12 +102,6 @@ namespace IO.Swagger.Api
|
|||||||
this.Configuration = configuration;
|
this.Configuration = configuration;
|
||||||
|
|
||||||
ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory;
|
ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory;
|
||||||
|
|
||||||
// ensure API client has configuration ready
|
|
||||||
if (Configuration.ApiClient.Configuration == null)
|
|
||||||
{
|
|
||||||
this.Configuration.ApiClient.Configuration = this.Configuration;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -162,9 +150,9 @@ namespace IO.Swagger.Api
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Dictionary of HTTP header</returns>
|
/// <returns>Dictionary of HTTP header</returns>
|
||||||
[Obsolete("DefaultHeader is deprecated, please use Configuration.DefaultHeader instead.")]
|
[Obsolete("DefaultHeader is deprecated, please use Configuration.DefaultHeader instead.")]
|
||||||
public Dictionary<String, String> DefaultHeader()
|
public IDictionary<String, String> DefaultHeader()
|
||||||
{
|
{
|
||||||
return this.Configuration.DefaultHeader;
|
return new ReadOnlyDictionary<string, string>(this.Configuration.DefaultHeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -201,7 +189,7 @@ namespace IO.Swagger.Api
|
|||||||
|
|
||||||
var localVarPath = "/fake";
|
var localVarPath = "/fake";
|
||||||
var localVarPathParams = new Dictionary<String, String>();
|
var localVarPathParams = new Dictionary<String, String>();
|
||||||
var localVarQueryParams = new Dictionary<String, String>();
|
var localVarQueryParams = new List<KeyValuePair<String, String>>();
|
||||||
var localVarHeaderParams = new Dictionary<String, String>(Configuration.DefaultHeader);
|
var localVarHeaderParams = new Dictionary<String, String>(Configuration.DefaultHeader);
|
||||||
var localVarFormParams = new Dictionary<String, String>();
|
var localVarFormParams = new Dictionary<String, String>();
|
||||||
var localVarFileParams = new Dictionary<String, FileParameter>();
|
var localVarFileParams = new Dictionary<String, FileParameter>();
|
||||||
@ -267,7 +255,7 @@ namespace IO.Swagger.Api
|
|||||||
|
|
||||||
var localVarPath = "/fake";
|
var localVarPath = "/fake";
|
||||||
var localVarPathParams = new Dictionary<String, String>();
|
var localVarPathParams = new Dictionary<String, String>();
|
||||||
var localVarQueryParams = new Dictionary<String, String>();
|
var localVarQueryParams = new List<KeyValuePair<String, String>>();
|
||||||
var localVarHeaderParams = new Dictionary<String, String>(Configuration.DefaultHeader);
|
var localVarHeaderParams = new Dictionary<String, String>(Configuration.DefaultHeader);
|
||||||
var localVarFormParams = new Dictionary<String, String>();
|
var localVarFormParams = new Dictionary<String, String>();
|
||||||
var localVarFileParams = new Dictionary<String, FileParameter>();
|
var localVarFileParams = new Dictionary<String, FileParameter>();
|
||||||
|
@ -48,11 +48,11 @@ namespace IO.Swagger.Client
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ApiClient" /> class
|
/// Initializes a new instance of the <see cref="ApiClient" /> class
|
||||||
/// with default configuration and base path (https://petstore.swagger.io *_/ ' \" =end - - \\r\\n \\n \\r/v2 *_/ ' \" =end - - \\r\\n \\n \\r).
|
/// with default configuration.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ApiClient()
|
public ApiClient()
|
||||||
{
|
{
|
||||||
Configuration = Configuration.Default;
|
Configuration = IO.Swagger.Client.Configuration.Default;
|
||||||
RestClient = new RestClient("https://petstore.swagger.io *_/ ' \" =end - - \\r\\n \\n \\r/v2 *_/ ' \" =end - - \\r\\n \\n \\r");
|
RestClient = new RestClient("https://petstore.swagger.io *_/ ' \" =end - - \\r\\n \\n \\r/v2 *_/ ' \" =end - - \\r\\n \\n \\r");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,14 +61,11 @@ namespace IO.Swagger.Client
|
|||||||
/// with default base path (https://petstore.swagger.io *_/ ' \" =end - - \\r\\n \\n \\r/v2 *_/ ' \" =end - - \\r\\n \\n \\r).
|
/// with default base path (https://petstore.swagger.io *_/ ' \" =end - - \\r\\n \\n \\r/v2 *_/ ' \" =end - - \\r\\n \\n \\r).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="config">An instance of Configuration.</param>
|
/// <param name="config">An instance of Configuration.</param>
|
||||||
public ApiClient(Configuration config = null)
|
public ApiClient(Configuration config)
|
||||||
{
|
{
|
||||||
if (config == null)
|
Configuration = config ?? IO.Swagger.Client.Configuration.Default;
|
||||||
Configuration = Configuration.Default;
|
|
||||||
else
|
|
||||||
Configuration = config;
|
|
||||||
|
|
||||||
RestClient = new RestClient("https://petstore.swagger.io *_/ ' \" =end - - \\r\\n \\n \\r/v2 *_/ ' \" =end - - \\r\\n \\n \\r");
|
RestClient = new RestClient(Configuration.BasePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -82,7 +79,7 @@ namespace IO.Swagger.Client
|
|||||||
throw new ArgumentException("basePath cannot be empty");
|
throw new ArgumentException("basePath cannot be empty");
|
||||||
|
|
||||||
RestClient = new RestClient(basePath);
|
RestClient = new RestClient(basePath);
|
||||||
Configuration = Configuration.Default;
|
Configuration = Client.Configuration.Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -93,10 +90,15 @@ namespace IO.Swagger.Client
|
|||||||
public static ApiClient Default;
|
public static ApiClient Default;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Configuration.
|
/// Gets or sets an instance of the IReadableConfiguration.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>An instance of the Configuration.</value>
|
/// <value>An instance of the IReadableConfiguration.</value>
|
||||||
public Configuration Configuration { get; set; }
|
/// <remarks>
|
||||||
|
/// <see cref="IReadableConfiguration"/> helps us to avoid modifying possibly global
|
||||||
|
/// configuration values from within a given client. It does not gaurantee thread-safety
|
||||||
|
/// of the <see cref="Configuration"/> instance in any way.
|
||||||
|
/// </remarks>
|
||||||
|
public IReadableConfiguration Configuration { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the RestClient.
|
/// Gets or sets the RestClient.
|
||||||
@ -106,7 +108,7 @@ namespace IO.Swagger.Client
|
|||||||
|
|
||||||
// Creates and sets up a RestRequest prior to a call.
|
// Creates and sets up a RestRequest prior to a call.
|
||||||
private RestRequest PrepareRequest(
|
private RestRequest PrepareRequest(
|
||||||
String path, RestSharp.Method method, Dictionary<String, String> queryParams, Object postBody,
|
String path, RestSharp.Method method, List<KeyValuePair<String, String>> queryParams, Object postBody,
|
||||||
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
||||||
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams,
|
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams,
|
||||||
String contentType)
|
String contentType)
|
||||||
@ -164,7 +166,7 @@ namespace IO.Swagger.Client
|
|||||||
/// <param name="contentType">Content Type of the request</param>
|
/// <param name="contentType">Content Type of the request</param>
|
||||||
/// <returns>Object</returns>
|
/// <returns>Object</returns>
|
||||||
public Object CallApi(
|
public Object CallApi(
|
||||||
String path, RestSharp.Method method, Dictionary<String, String> queryParams, Object postBody,
|
String path, RestSharp.Method method, List<KeyValuePair<String, String>> queryParams, Object postBody,
|
||||||
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
||||||
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams,
|
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams,
|
||||||
String contentType)
|
String contentType)
|
||||||
@ -174,6 +176,7 @@ namespace IO.Swagger.Client
|
|||||||
pathParams, contentType);
|
pathParams, contentType);
|
||||||
|
|
||||||
// set timeout
|
// set timeout
|
||||||
|
|
||||||
RestClient.Timeout = Configuration.Timeout;
|
RestClient.Timeout = Configuration.Timeout;
|
||||||
// set user agent
|
// set user agent
|
||||||
RestClient.UserAgent = Configuration.UserAgent;
|
RestClient.UserAgent = Configuration.UserAgent;
|
||||||
@ -198,7 +201,7 @@ namespace IO.Swagger.Client
|
|||||||
/// <param name="contentType">Content type.</param>
|
/// <param name="contentType">Content type.</param>
|
||||||
/// <returns>The Task instance.</returns>
|
/// <returns>The Task instance.</returns>
|
||||||
public async System.Threading.Tasks.Task<Object> CallApiAsync(
|
public async System.Threading.Tasks.Task<Object> CallApiAsync(
|
||||||
String path, RestSharp.Method method, Dictionary<String, String> queryParams, Object postBody,
|
String path, RestSharp.Method method, List<KeyValuePair<String, String>> queryParams, Object postBody,
|
||||||
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
||||||
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams,
|
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams,
|
||||||
String contentType)
|
String contentType)
|
||||||
@ -286,6 +289,7 @@ namespace IO.Swagger.Client
|
|||||||
return response.RawBytes;
|
return response.RawBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: ? if (type.IsAssignableFrom(typeof(Stream)))
|
||||||
if (type == typeof(Stream))
|
if (type == typeof(Stream))
|
||||||
{
|
{
|
||||||
if (headers != null)
|
if (headers != null)
|
||||||
@ -395,31 +399,29 @@ namespace IO.Swagger.Client
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dynamically cast the object into target type.
|
/// Dynamically cast the object into target type.
|
||||||
/// Ref: http://stackoverflow.com/questions/4925718/c-dynamic-runtime-cast
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">Object to be casted</param>
|
/// <param name="fromObject">Object to be casted</param>
|
||||||
/// <param name="dest">Target type</param>
|
/// <param name="toObject">Target type</param>
|
||||||
/// <returns>Casted object</returns>
|
/// <returns>Casted object</returns>
|
||||||
public static dynamic ConvertType(dynamic source, Type dest)
|
public static dynamic ConvertType(dynamic fromObject, Type toObject)
|
||||||
{
|
{
|
||||||
return Convert.ChangeType(source, dest);
|
return Convert.ChangeType(fromObject, toObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert stream to byte array
|
/// Convert stream to byte array
|
||||||
/// Credit/Ref: http://stackoverflow.com/a/221941/677735
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">Input stream to be converted</param>
|
/// <param name="inputStream">Input stream to be converted</param>
|
||||||
/// <returns>Byte array</returns>
|
/// <returns>Byte array</returns>
|
||||||
public static byte[] ReadAsBytes(Stream input)
|
public static byte[] ReadAsBytes(Stream inputStream)
|
||||||
{
|
{
|
||||||
byte[] buffer = new byte[16*1024];
|
byte[] buf = new byte[16*1024];
|
||||||
using (MemoryStream ms = new MemoryStream())
|
using (MemoryStream ms = new MemoryStream())
|
||||||
{
|
{
|
||||||
int read;
|
int count;
|
||||||
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
|
while ((count = inputStream.Read(buf, 0, buf.Length)) > 0)
|
||||||
{
|
{
|
||||||
ms.Write(buffer, 0, read);
|
ms.Write(buf, 0, count);
|
||||||
}
|
}
|
||||||
return ms.ToArray();
|
return ms.ToArray();
|
||||||
}
|
}
|
||||||
@ -478,5 +480,39 @@ namespace IO.Swagger.Client
|
|||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert params to key/value pairs.
|
||||||
|
/// Use collectionFormat to properly format lists and collections.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Key name.</param>
|
||||||
|
/// <param name="value">Value object.</param>
|
||||||
|
/// <returns>A list of KeyValuePairs</returns>
|
||||||
|
public IEnumerable<KeyValuePair<string, string>> ParameterToKeyValuePairs(string collectionFormat, string name, object value)
|
||||||
|
{
|
||||||
|
var parameters = new List<KeyValuePair<string, string>>();
|
||||||
|
|
||||||
|
if (IsCollection(value) && collectionFormat == "multi")
|
||||||
|
{
|
||||||
|
var valueCollection = value as IEnumerable;
|
||||||
|
parameters.AddRange(from object item in valueCollection select new KeyValuePair<string, string>(name, ParameterToString(item)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parameters.Add(new KeyValuePair<string, string>(name, ParameterToString(value)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if generic object is a collection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns>True if object is a collection type</returns>
|
||||||
|
private static bool IsCollection(object value)
|
||||||
|
{
|
||||||
|
return value is IList || value is ICollection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -20,10 +21,147 @@ namespace IO.Swagger.Client
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a set of configuration settings
|
/// Represents a set of configuration settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Configuration
|
public class Configuration : IReadableConfiguration
|
||||||
{
|
{
|
||||||
|
#region Constants
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the Configuration class with different settings
|
/// Version of the package.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Version of the package.</value>
|
||||||
|
public const string Version = "1.0.0";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Identifier for ISO 8601 DateTime Format
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>See https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8 for more information.</remarks>
|
||||||
|
// ReSharper disable once InconsistentNaming
|
||||||
|
public const string ISO8601_DATETIME_FORMAT = "o";
|
||||||
|
|
||||||
|
#endregion Constants
|
||||||
|
|
||||||
|
#region Static Members
|
||||||
|
|
||||||
|
private static readonly object GlobalConfigSync = new { };
|
||||||
|
private static Configuration _globalConfiguration;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default creation of exceptions for a given method name and response object
|
||||||
|
/// </summary>
|
||||||
|
public static readonly ExceptionFactory DefaultExceptionFactory = (methodName, response) =>
|
||||||
|
{
|
||||||
|
var status = (int)response.StatusCode;
|
||||||
|
if (status >= 400)
|
||||||
|
{
|
||||||
|
return new ApiException(status,
|
||||||
|
string.Format("Error calling {0}: {1}", methodName, response.Content),
|
||||||
|
response.Content);
|
||||||
|
}
|
||||||
|
if (status == 0)
|
||||||
|
{
|
||||||
|
return new ApiException(status,
|
||||||
|
string.Format("Error calling {0}: {1}", methodName, response.ErrorMessage), response.ErrorMessage);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the default Configuration.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Configuration.</value>
|
||||||
|
public static Configuration Default
|
||||||
|
{
|
||||||
|
get { return _globalConfiguration; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
lock (GlobalConfigSync)
|
||||||
|
{
|
||||||
|
_globalConfiguration = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Static Members
|
||||||
|
|
||||||
|
#region Private Members
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the API key based on the authentication name.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The API key.</value>
|
||||||
|
private IDictionary<string, string> _apiKey = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The prefix of the API key.</value>
|
||||||
|
private IDictionary<string, string> _apiKeyPrefix = null;
|
||||||
|
|
||||||
|
private string _dateTimeFormat = ISO8601_DATETIME_FORMAT;
|
||||||
|
private string _tempFolderPath = Path.GetTempPath();
|
||||||
|
|
||||||
|
#endregion Private Members
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
static Configuration()
|
||||||
|
{
|
||||||
|
_globalConfiguration = new GlobalConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Configuration" /> class
|
||||||
|
/// </summary>
|
||||||
|
public Configuration()
|
||||||
|
{
|
||||||
|
UserAgent = "Swagger-Codegen/1.0.0/csharp";
|
||||||
|
BasePath = "https://petstore.swagger.io *_/ ' \" =end - - \\r\\n \\n \\r/v2 *_/ ' \" =end - - \\r\\n \\n \\r";
|
||||||
|
DefaultHeader = new ConcurrentDictionary<string, string>();
|
||||||
|
ApiKey = new ConcurrentDictionary<string, string>();
|
||||||
|
ApiKeyPrefix = new ConcurrentDictionary<string, string>();
|
||||||
|
|
||||||
|
// Setting Timeout has side effects (forces ApiClient creation).
|
||||||
|
Timeout = 100000;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Configuration" /> class
|
||||||
|
/// </summary>
|
||||||
|
public Configuration(
|
||||||
|
IDictionary<string, string> defaultHeader,
|
||||||
|
IDictionary<string, string> apiKey,
|
||||||
|
IDictionary<string, string> apiKeyPrefix,
|
||||||
|
string basePath = "https://petstore.swagger.io *_/ ' \" =end - - \\r\\n \\n \\r/v2 *_/ ' \" =end - - \\r\\n \\n \\r") : this()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(basePath))
|
||||||
|
throw new ArgumentException("The provided basePath is invalid.", "basePath");
|
||||||
|
if (defaultHeader == null)
|
||||||
|
throw new ArgumentNullException("defaultHeader");
|
||||||
|
if (apiKey == null)
|
||||||
|
throw new ArgumentNullException("apiKey");
|
||||||
|
if (apiKeyPrefix == null)
|
||||||
|
throw new ArgumentNullException("apiKeyPrefix");
|
||||||
|
|
||||||
|
BasePath = basePath;
|
||||||
|
|
||||||
|
foreach (var keyValuePair in defaultHeader)
|
||||||
|
{
|
||||||
|
DefaultHeader.Add(keyValuePair);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var keyValuePair in apiKey)
|
||||||
|
{
|
||||||
|
ApiKey.Add(keyValuePair);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var keyValuePair in apiKeyPrefix)
|
||||||
|
{
|
||||||
|
ApiKeyPrefix.Add(keyValuePair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Configuration" /> class with different settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="apiClient">Api client</param>
|
/// <param name="apiClient">Api client</param>
|
||||||
/// <param name="defaultHeader">Dictionary of default HTTP header</param>
|
/// <param name="defaultHeader">Dictionary of default HTTP header</param>
|
||||||
@ -36,129 +174,224 @@ namespace IO.Swagger.Client
|
|||||||
/// <param name="dateTimeFormat">DateTime format string</param>
|
/// <param name="dateTimeFormat">DateTime format string</param>
|
||||||
/// <param name="timeout">HTTP connection timeout (in milliseconds)</param>
|
/// <param name="timeout">HTTP connection timeout (in milliseconds)</param>
|
||||||
/// <param name="userAgent">HTTP user agent</param>
|
/// <param name="userAgent">HTTP user agent</param>
|
||||||
public Configuration(ApiClient apiClient = null,
|
[Obsolete("Use explicit object construction and setting of properties.", true)]
|
||||||
Dictionary<String, String> defaultHeader = null,
|
public Configuration(
|
||||||
string username = null,
|
// ReSharper disable UnusedParameter.Local
|
||||||
string password = null,
|
ApiClient apiClient = null,
|
||||||
string accessToken = null,
|
IDictionary<string, string> defaultHeader = null,
|
||||||
Dictionary<String, String> apiKey = null,
|
string username = null,
|
||||||
Dictionary<String, String> apiKeyPrefix = null,
|
string password = null,
|
||||||
string tempFolderPath = null,
|
string accessToken = null,
|
||||||
string dateTimeFormat = null,
|
IDictionary<string, string> apiKey = null,
|
||||||
int timeout = 100000,
|
IDictionary<string, string> apiKeyPrefix = null,
|
||||||
string userAgent = "Swagger-Codegen/1.0.0/csharp"
|
string tempFolderPath = null,
|
||||||
)
|
string dateTimeFormat = null,
|
||||||
|
int timeout = 100000,
|
||||||
|
string userAgent = "Swagger-Codegen/1.0.0/csharp"
|
||||||
|
// ReSharper restore UnusedParameter.Local
|
||||||
|
)
|
||||||
{
|
{
|
||||||
setApiClientUsingDefault(apiClient);
|
|
||||||
|
|
||||||
Username = username;
|
|
||||||
Password = password;
|
|
||||||
AccessToken = accessToken;
|
|
||||||
UserAgent = userAgent;
|
|
||||||
|
|
||||||
if (defaultHeader != null)
|
|
||||||
DefaultHeader = defaultHeader;
|
|
||||||
if (apiKey != null)
|
|
||||||
ApiKey = apiKey;
|
|
||||||
if (apiKeyPrefix != null)
|
|
||||||
ApiKeyPrefix = apiKeyPrefix;
|
|
||||||
|
|
||||||
TempFolderPath = tempFolderPath;
|
|
||||||
DateTimeFormat = dateTimeFormat;
|
|
||||||
Timeout = timeout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the Configuration class.
|
/// Initializes a new instance of the Configuration class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="apiClient">Api client.</param>
|
/// <param name="apiClient">Api client.</param>
|
||||||
|
[Obsolete("This constructor caused unexpected sharing of static data. It is no longer supported.", true)]
|
||||||
|
// ReSharper disable once UnusedParameter.Local
|
||||||
public Configuration(ApiClient apiClient)
|
public Configuration(ApiClient apiClient)
|
||||||
{
|
{
|
||||||
setApiClientUsingDefault(apiClient);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
#endregion Constructors
|
||||||
/// Version of the package.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>Version of the package.</value>
|
|
||||||
public const string Version = "1.0.0";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the default Configuration.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>Configuration.</value>
|
|
||||||
public static Configuration Default = new Configuration();
|
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
private ApiClient _apiClient = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default creation of exceptions for a given method name and response object
|
/// Gets an instance of an ApiClient for this configuration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly ExceptionFactory DefaultExceptionFactory = (methodName, response) =>
|
public virtual ApiClient ApiClient
|
||||||
{
|
{
|
||||||
int status = (int) response.StatusCode;
|
get
|
||||||
if (status >= 400) return new ApiException(status, String.Format("Error calling {0}: {1}", methodName, response.Content), response.Content);
|
|
||||||
if (status == 0) return new ApiException(status, String.Format("Error calling {0}: {1}", methodName, response.ErrorMessage), response.ErrorMessage);
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>Timeout.</value>
|
|
||||||
public int Timeout
|
|
||||||
{
|
|
||||||
get { return ApiClient.RestClient.Timeout; }
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
{
|
||||||
if (ApiClient != null)
|
if (_apiClient == null) _apiClient = CreateApiClient();
|
||||||
ApiClient.RestClient.Timeout = value;
|
return _apiClient;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String _basePath = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the default API client for making HTTP calls.
|
/// Gets or sets the base path for API access.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The API client.</value>
|
public virtual string BasePath {
|
||||||
public ApiClient ApiClient;
|
get { return _basePath; }
|
||||||
|
set {
|
||||||
/// <summary>
|
_basePath = value;
|
||||||
/// Set the ApiClient using Default or ApiClient instance.
|
// pass-through to ApiClient if it's set.
|
||||||
/// </summary>
|
if(_apiClient != null) {
|
||||||
/// <param name="apiClient">An instance of ApiClient.</param>
|
_apiClient.RestClient.BaseUrl = new Uri(_basePath);
|
||||||
/// <returns></returns>
|
}
|
||||||
public void setApiClientUsingDefault (ApiClient apiClient = null)
|
|
||||||
{
|
|
||||||
if (apiClient == null)
|
|
||||||
{
|
|
||||||
if (Default != null && Default.ApiClient == null)
|
|
||||||
Default.ApiClient = new ApiClient();
|
|
||||||
|
|
||||||
ApiClient = Default != null ? Default.ApiClient : new ApiClient();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Default != null && Default.ApiClient == null)
|
|
||||||
Default.ApiClient = apiClient;
|
|
||||||
|
|
||||||
ApiClient = apiClient;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the default header.
|
/// Gets or sets the default header.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<String, String> DefaultHeader
|
public virtual IDictionary<string, string> DefaultHeader { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds.
|
||||||
|
/// </summary>
|
||||||
|
public virtual int Timeout
|
||||||
{
|
{
|
||||||
get { return _defaultHeaderMap; }
|
|
||||||
|
get { return ApiClient.RestClient.Timeout; }
|
||||||
|
set { ApiClient.RestClient.Timeout = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the HTTP user agent.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Http user agent.</value>
|
||||||
|
public virtual string UserAgent { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the username (HTTP basic authentication).
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The username.</value>
|
||||||
|
public virtual string Username { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the password (HTTP basic authentication).
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The password.</value>
|
||||||
|
public virtual string Password { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the API key with prefix.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiKeyIdentifier">API key identifier (authentication scheme).</param>
|
||||||
|
/// <returns>API key with prefix.</returns>
|
||||||
|
public string GetApiKeyWithPrefix(string apiKeyIdentifier)
|
||||||
|
{
|
||||||
|
var apiKeyValue = "";
|
||||||
|
ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue);
|
||||||
|
var apiKeyPrefix = "";
|
||||||
|
if (ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix))
|
||||||
|
return apiKeyPrefix + " " + apiKeyValue;
|
||||||
|
else
|
||||||
|
return apiKeyValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the access token for OAuth2 authentication.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The access token.</value>
|
||||||
|
public virtual string AccessToken { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the temporary folder path to store the files downloaded from the server.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Folder path.</value>
|
||||||
|
public virtual string TempFolderPath
|
||||||
|
{
|
||||||
|
get { return _tempFolderPath; }
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_defaultHeaderMap = value;
|
if (string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
// Possible breaking change since swagger-codegen 2.2.1, enforce a valid temporary path on set.
|
||||||
|
_tempFolderPath = Path.GetTempPath();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the directory if it does not exist
|
||||||
|
if (!Directory.Exists(value))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if the path contains directory separator at the end
|
||||||
|
if (value[value.Length - 1] == Path.DirectorySeparatorChar)
|
||||||
|
{
|
||||||
|
_tempFolderPath = value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_tempFolderPath = value + Path.DirectorySeparatorChar;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the the date time format used when serializing in the ApiClient
|
||||||
|
/// By default, it's set to ISO 8601 - "o", for others see:
|
||||||
|
/// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx
|
||||||
|
/// and https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
|
||||||
|
/// No validation is done to ensure that the string you're providing is valid
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The DateTimeFormat string</value>
|
||||||
|
public virtual string DateTimeFormat
|
||||||
|
{
|
||||||
|
get { return _dateTimeFormat; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
// Never allow a blank or null string, go back to the default
|
||||||
|
_dateTimeFormat = ISO8601_DATETIME_FORMAT;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Caution, no validation when you choose date time format other than ISO 8601
|
||||||
|
// Take a look at the above links
|
||||||
|
_dateTimeFormat = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The prefix of the API key.</value>
|
||||||
|
public virtual IDictionary<string, string> ApiKeyPrefix
|
||||||
|
{
|
||||||
|
get { return _apiKeyPrefix; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("ApiKeyPrefix collection may not be null.");
|
||||||
|
}
|
||||||
|
_apiKeyPrefix = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the API key based on the authentication name.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The API key.</value>
|
||||||
|
public virtual IDictionary<string, string> ApiKey
|
||||||
|
{
|
||||||
|
get { return _apiKey; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("ApiKey collection may not be null.");
|
||||||
|
}
|
||||||
|
_apiKey = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Properties
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add default header.
|
/// Add default header.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -167,7 +400,31 @@ namespace IO.Swagger.Client
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public void AddDefaultHeader(string key, string value)
|
public void AddDefaultHeader(string key, string value)
|
||||||
{
|
{
|
||||||
_defaultHeaderMap[key] = value;
|
DefaultHeader[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="ApiClient" /> based on this <see cref="Configuration" /> instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ApiClient CreateApiClient()
|
||||||
|
{
|
||||||
|
return new ApiClient(BasePath) { Configuration = this };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a string with essential information for debugging.
|
||||||
|
/// </summary>
|
||||||
|
public static String ToDebugReport()
|
||||||
|
{
|
||||||
|
String report = "C# SDK (IO.Swagger) Debug Report:\n";
|
||||||
|
report += " OS: " + System.Environment.OSVersion + "\n";
|
||||||
|
report += " .NET Framework Version: " + System.Environment.Version + "\n";
|
||||||
|
report += " Version of the API: 1.0.0 *_/ ' \" =end - - \\r\\n \\n \\r\n";
|
||||||
|
report += " SDK Package Version: 1.0.0\n";
|
||||||
|
|
||||||
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -191,144 +448,6 @@ namespace IO.Swagger.Client
|
|||||||
ApiKeyPrefix[key] = value;
|
ApiKeyPrefix[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
#endregion Methods
|
||||||
/// Gets or sets the HTTP user agent.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>Http user agent.</value>
|
|
||||||
public String UserAgent { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the username (HTTP basic authentication).
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The username.</value>
|
|
||||||
public String Username { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the password (HTTP basic authentication).
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The password.</value>
|
|
||||||
public String Password { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the access token for OAuth2 authentication.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The access token.</value>
|
|
||||||
public String AccessToken { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the API key based on the authentication name.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The API key.</value>
|
|
||||||
public Dictionary<String, String> ApiKey = new Dictionary<String, String>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The prefix of the API key.</value>
|
|
||||||
public Dictionary<String, String> ApiKeyPrefix = new Dictionary<String, String>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the API key with prefix.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="apiKeyIdentifier">API key identifier (authentication scheme).</param>
|
|
||||||
/// <returns>API key with prefix.</returns>
|
|
||||||
public string GetApiKeyWithPrefix (string apiKeyIdentifier)
|
|
||||||
{
|
|
||||||
var apiKeyValue = "";
|
|
||||||
ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue);
|
|
||||||
var apiKeyPrefix = "";
|
|
||||||
if (ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix))
|
|
||||||
return apiKeyPrefix + " " + apiKeyValue;
|
|
||||||
else
|
|
||||||
return apiKeyValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string _tempFolderPath;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the temporary folder path to store the files downloaded from the server.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>Folder path.</value>
|
|
||||||
public String TempFolderPath
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
// default to Path.GetTempPath() if _tempFolderPath is not set
|
|
||||||
if (String.IsNullOrEmpty(_tempFolderPath))
|
|
||||||
{
|
|
||||||
_tempFolderPath = Path.GetTempPath();
|
|
||||||
}
|
|
||||||
return _tempFolderPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (String.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
_tempFolderPath = value;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the directory if it does not exist
|
|
||||||
if (!Directory.Exists(value))
|
|
||||||
Directory.CreateDirectory(value);
|
|
||||||
|
|
||||||
// check if the path contains directory separator at the end
|
|
||||||
if (value[value.Length - 1] == Path.DirectorySeparatorChar)
|
|
||||||
_tempFolderPath = value;
|
|
||||||
else
|
|
||||||
_tempFolderPath = value + Path.DirectorySeparatorChar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private const string ISO8601_DATETIME_FORMAT = "o";
|
|
||||||
|
|
||||||
private string _dateTimeFormat = ISO8601_DATETIME_FORMAT;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the the date time format used when serializing in the ApiClient
|
|
||||||
/// By default, it's set to ISO 8601 - "o", for others see:
|
|
||||||
/// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx
|
|
||||||
/// and https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
|
|
||||||
/// No validation is done to ensure that the string you're providing is valid
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The DateTimeFormat string</value>
|
|
||||||
public String DateTimeFormat
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _dateTimeFormat;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
// Never allow a blank or null string, go back to the default
|
|
||||||
_dateTimeFormat = ISO8601_DATETIME_FORMAT;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Caution, no validation when you choose date time format other than ISO 8601
|
|
||||||
// Take a look at the above links
|
|
||||||
_dateTimeFormat = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a string with essential information for debugging.
|
|
||||||
/// </summary>
|
|
||||||
public static String ToDebugReport()
|
|
||||||
{
|
|
||||||
String report = "C# SDK (IO.Swagger) Debug Report:\n";
|
|
||||||
report += " OS: " + Environment.OSVersion + "\n";
|
|
||||||
report += " .NET Framework Version: " + Assembly
|
|
||||||
.GetExecutingAssembly()
|
|
||||||
.GetReferencedAssemblies()
|
|
||||||
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
|
|
||||||
report += " Version of the API: 1.0.0 *_/ ' \" =end - - \\r\\n \\n \\r\n";
|
|
||||||
report += " SDK Package Version: 1.0.0\n";
|
|
||||||
|
|
||||||
return report;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Swagger Petstore *_/ ' \" =end - - \\r\\n \\n \\r
|
||||||
|
*
|
||||||
|
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end - -
|
||||||
|
*
|
||||||
|
* OpenAPI spec version: 1.0.0 *_/ ' \" =end - - \\r\\n \\n \\r
|
||||||
|
* Contact: apiteam@swagger.io *_/ ' \" =end - - \\r\\n \\n \\r
|
||||||
|
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace IO.Swagger.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <see cref="GlobalConfiguration"/> provides a compile-time extension point for globally configuring
|
||||||
|
/// API Clients.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// A customized implementation via partial class may reside in another file and may
|
||||||
|
/// be excluded from automatic generation via a .swagger-codegen-ignore file.
|
||||||
|
/// </remarks>
|
||||||
|
public partial class GlobalConfiguration : Configuration
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* Swagger Petstore *_/ ' \" =end - - \\r\\n \\n \\r
|
||||||
|
*
|
||||||
|
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end - -
|
||||||
|
*
|
||||||
|
* OpenAPI spec version: 1.0.0 *_/ ' \" =end - - \\r\\n \\n \\r
|
||||||
|
* Contact: apiteam@swagger.io *_/ ' \" =end - - \\r\\n \\n \\r
|
||||||
|
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace IO.Swagger.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a readable-only configuration contract.
|
||||||
|
/// </summary>
|
||||||
|
public interface IReadableConfiguration
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the access token.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Access token.</value>
|
||||||
|
string AccessToken { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the API key.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>API key.</value>
|
||||||
|
IDictionary<string, string> ApiKey { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the API key prefix.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>API key prefix.</value>
|
||||||
|
IDictionary<string, string> ApiKeyPrefix { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the base path.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Base path.</value>
|
||||||
|
string BasePath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the date time format.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Date time foramt.</value>
|
||||||
|
string DateTimeFormat { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the default header.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Default header.</value>
|
||||||
|
IDictionary<string, string> DefaultHeader { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the temp folder path.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Temp folder path.</value>
|
||||||
|
string TempFolderPath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the HTTP connection timeout (in milliseconds)
|
||||||
|
/// </summary>
|
||||||
|
/// <value>HTTP connection timeout.</value>
|
||||||
|
int Timeout { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the user agent.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>User agent.</value>
|
||||||
|
string UserAgent { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the username.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Username.</value>
|
||||||
|
string Username { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the password.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Password.</value>
|
||||||
|
string Password { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the API key with prefix.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiKeyIdentifier">API key identifier (authentication scheme).</param>
|
||||||
|
/// <returns>API key with prefix.</returns>
|
||||||
|
string GetApiKeyWithPrefix(string apiKeyIdentifier);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,272 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace JsonSubTypes
|
||||||
|
{
|
||||||
|
// Copied from project https://github.com/manuc66/JsonSubTypes
|
||||||
|
// https://raw.githubusercontent.com/manuc66/JsonSubTypes/07403192ea3f4959f6d42f5966ac56ceb0d6095b/JsonSubTypes/JsonSubtypes.cs
|
||||||
|
|
||||||
|
public class JsonSubtypes : JsonConverter
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
|
||||||
|
public class KnownSubTypeAttribute : Attribute
|
||||||
|
{
|
||||||
|
public Type SubType { get; private set; }
|
||||||
|
public object AssociatedValue { get; private set; }
|
||||||
|
|
||||||
|
public KnownSubTypeAttribute(Type subType, object associatedValue)
|
||||||
|
{
|
||||||
|
SubType = subType;
|
||||||
|
AssociatedValue = associatedValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
|
||||||
|
public class KnownSubTypeWithPropertyAttribute : Attribute
|
||||||
|
{
|
||||||
|
public Type SubType { get; private set; }
|
||||||
|
public string PropertyName { get; private set; }
|
||||||
|
|
||||||
|
public KnownSubTypeWithPropertyAttribute(Type subType, string propertyName)
|
||||||
|
{
|
||||||
|
SubType = subType;
|
||||||
|
PropertyName = propertyName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _typeMappingPropertyName;
|
||||||
|
|
||||||
|
private bool _isInsideRead;
|
||||||
|
private JsonReader _reader;
|
||||||
|
|
||||||
|
public override bool CanRead
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!_isInsideRead)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return !string.IsNullOrEmpty(_reader.Path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed override bool CanWrite
|
||||||
|
{
|
||||||
|
get { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonSubtypes()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonSubtypes(string typeMappingPropertyName)
|
||||||
|
{
|
||||||
|
_typeMappingPropertyName = typeMappingPropertyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanConvert(Type objectType)
|
||||||
|
{
|
||||||
|
return _typeMappingPropertyName != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
if (reader.TokenType == JsonToken.Comment)
|
||||||
|
reader.Read();
|
||||||
|
|
||||||
|
switch (reader.TokenType)
|
||||||
|
{
|
||||||
|
case JsonToken.Null:
|
||||||
|
return null;
|
||||||
|
case JsonToken.StartArray:
|
||||||
|
return ReadArray(reader, objectType, serializer);
|
||||||
|
case JsonToken.StartObject:
|
||||||
|
return ReadObject(reader, objectType, serializer);
|
||||||
|
default:
|
||||||
|
throw new Exception("Array: Unrecognized token: " + reader.TokenType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IList ReadArray(JsonReader reader, Type targetType, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
var elementType = GetElementType(targetType);
|
||||||
|
|
||||||
|
var list = CreateCompatibleList(targetType, elementType);
|
||||||
|
|
||||||
|
while (reader.TokenType != JsonToken.EndArray && reader.Read())
|
||||||
|
{
|
||||||
|
switch (reader.TokenType)
|
||||||
|
{
|
||||||
|
case JsonToken.Null:
|
||||||
|
list.Add(reader.Value);
|
||||||
|
break;
|
||||||
|
case JsonToken.Comment:
|
||||||
|
break;
|
||||||
|
case JsonToken.StartObject:
|
||||||
|
list.Add(ReadObject(reader, elementType, serializer));
|
||||||
|
break;
|
||||||
|
case JsonToken.EndArray:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("Array: Unrecognized token: " + reader.TokenType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (targetType.IsArray)
|
||||||
|
{
|
||||||
|
var array = Array.CreateInstance(targetType.GetElementType(), list.Count);
|
||||||
|
list.CopyTo(array, 0);
|
||||||
|
list = array;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IList CreateCompatibleList(Type targetContainerType, Type elementType)
|
||||||
|
{
|
||||||
|
IList list;
|
||||||
|
if (targetContainerType.IsArray || targetContainerType.GetTypeInfo().IsAbstract)
|
||||||
|
{
|
||||||
|
list = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list = (IList)Activator.CreateInstance(targetContainerType);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetElementType(Type arrayOrGenericContainer)
|
||||||
|
{
|
||||||
|
Type elementType;
|
||||||
|
if (arrayOrGenericContainer.IsArray)
|
||||||
|
{
|
||||||
|
elementType = arrayOrGenericContainer.GetElementType();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
elementType = arrayOrGenericContainer.GenericTypeArguments[0];
|
||||||
|
}
|
||||||
|
return elementType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private object ReadObject(JsonReader reader, Type objectType, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
var jObject = JObject.Load(reader);
|
||||||
|
|
||||||
|
var targetType = GetType(jObject, objectType) ?? objectType;
|
||||||
|
|
||||||
|
return _ReadJson(CreateAnotherReader(jObject, reader), targetType, null, serializer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonReader CreateAnotherReader(JObject jObject, JsonReader reader)
|
||||||
|
{
|
||||||
|
var jObjectReader = jObject.CreateReader();
|
||||||
|
jObjectReader.Culture = reader.Culture;
|
||||||
|
jObjectReader.CloseInput = reader.CloseInput;
|
||||||
|
jObjectReader.SupportMultipleContent = reader.SupportMultipleContent;
|
||||||
|
jObjectReader.DateTimeZoneHandling = reader.DateTimeZoneHandling;
|
||||||
|
jObjectReader.FloatParseHandling = reader.FloatParseHandling;
|
||||||
|
jObjectReader.DateFormatString = reader.DateFormatString;
|
||||||
|
jObjectReader.DateParseHandling = reader.DateParseHandling;
|
||||||
|
return jObjectReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type GetType(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
if (_typeMappingPropertyName == null)
|
||||||
|
{
|
||||||
|
return GetTypeByPropertyPresence(jObject, parentType);
|
||||||
|
}
|
||||||
|
return GetTypeFromDiscriminatorValue(jObject, parentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeByPropertyPresence(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
foreach (var type in parentType.GetTypeInfo().GetCustomAttributes<KnownSubTypeWithPropertyAttribute>())
|
||||||
|
{
|
||||||
|
JToken ignore;
|
||||||
|
if (jObject.TryGetValue(type.PropertyName, out ignore))
|
||||||
|
{
|
||||||
|
return type.SubType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Type GetTypeFromDiscriminatorValue(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
JToken jToken;
|
||||||
|
if (!jObject.TryGetValue(_typeMappingPropertyName, out jToken)) return null;
|
||||||
|
|
||||||
|
var discriminatorValue = jToken.ToObject<object>();
|
||||||
|
if (discriminatorValue == null) return null;
|
||||||
|
|
||||||
|
var typeMapping = GetSubTypeMapping(parentType);
|
||||||
|
if (typeMapping.Any())
|
||||||
|
{
|
||||||
|
return GetTypeFromMapping(typeMapping, discriminatorValue);
|
||||||
|
}
|
||||||
|
return GetTypeByName(discriminatorValue as string, parentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeByName(string typeName, Type parentType)
|
||||||
|
{
|
||||||
|
if (typeName == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var insideAssembly = parentType.GetTypeInfo().Assembly;
|
||||||
|
|
||||||
|
var typeByName = insideAssembly.GetType(typeName);
|
||||||
|
if (typeByName == null)
|
||||||
|
{
|
||||||
|
var searchLocation = parentType.FullName.Substring(0, parentType.FullName.Length - parentType.Name.Length);
|
||||||
|
typeByName = insideAssembly.GetType(searchLocation + typeName, false, true);
|
||||||
|
}
|
||||||
|
return typeByName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeFromMapping(IReadOnlyDictionary<object, Type> typeMapping, object discriminatorValue)
|
||||||
|
{
|
||||||
|
var targetlookupValueType = typeMapping.First().Key.GetType();
|
||||||
|
var lookupValue = ConvertJsonValueToType(discriminatorValue, targetlookupValueType);
|
||||||
|
|
||||||
|
Type targetType;
|
||||||
|
return typeMapping.TryGetValue(lookupValue, out targetType) ? targetType : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Dictionary<object, Type> GetSubTypeMapping(Type type)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().GetCustomAttributes<KnownSubTypeAttribute>().ToDictionary(x => x.AssociatedValue, x => x.SubType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static object ConvertJsonValueToType(object objectType, Type targetlookupValueType)
|
||||||
|
{
|
||||||
|
if (targetlookupValueType.GetTypeInfo().IsEnum)
|
||||||
|
return Enum.ToObject(targetlookupValueType, objectType);
|
||||||
|
|
||||||
|
return Convert.ChangeType(objectType, targetlookupValueType);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected object _ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
_reader = reader;
|
||||||
|
_isInsideRead = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return serializer.Deserialize(reader, objectType);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isInsideRead = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -71,30 +71,28 @@ namespace IO.Swagger.Model
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns true if objects are equal
|
/// Returns true if objects are equal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj">Object to be compared</param>
|
/// <param name="input">Object to be compared</param>
|
||||||
/// <returns>Boolean</returns>
|
/// <returns>Boolean</returns>
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object input)
|
||||||
{
|
{
|
||||||
// credit: http://stackoverflow.com/a/10454552/677735
|
return this.Equals(input as ModelReturn);
|
||||||
return this.Equals(obj as ModelReturn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns true if ModelReturn instances are equal
|
/// Returns true if ModelReturn instances are equal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="other">Instance of ModelReturn to be compared</param>
|
/// <param name="input">Instance of ModelReturn to be compared</param>
|
||||||
/// <returns>Boolean</returns>
|
/// <returns>Boolean</returns>
|
||||||
public bool Equals(ModelReturn other)
|
public bool Equals(ModelReturn input)
|
||||||
{
|
{
|
||||||
// credit: http://stackoverflow.com/a/10454552/677735
|
if (input == null)
|
||||||
if (other == null)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return
|
return
|
||||||
(
|
(
|
||||||
this._Return == other._Return ||
|
this._Return == input._Return ||
|
||||||
this._Return != null &&
|
(this._Return != null &&
|
||||||
this._Return.Equals(other._Return)
|
this._Return.Equals(input._Return))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,14 +102,12 @@ namespace IO.Swagger.Model
|
|||||||
/// <returns>Hash code</returns>
|
/// <returns>Hash code</returns>
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
// credit: http://stackoverflow.com/a/263416/677735
|
|
||||||
unchecked // Overflow is fine, just wrap
|
unchecked // Overflow is fine, just wrap
|
||||||
{
|
{
|
||||||
int hash = 41;
|
int hashCode = 41;
|
||||||
// Suitable nullity checks etc, of course :)
|
|
||||||
if (this._Return != null)
|
if (this._Return != null)
|
||||||
hash = hash * 59 + this._Return.GetHashCode();
|
hashCode = hashCode * 59 + this._Return.GetHashCode();
|
||||||
return hash;
|
return hashCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,21 +7,21 @@ EndProject
|
|||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger.Test", "src\IO.Swagger.Test\IO.Swagger.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger.Test", "src\IO.Swagger.Test\IO.Swagger.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Release|Any CPU.Build.0 = Release|Any CPU
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.Build.0 = Release|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
@ -8,6 +8,7 @@ using IO.Swagger.Api;
|
|||||||
using IO.Swagger.Model;
|
using IO.Swagger.Model;
|
||||||
using IO.Swagger.Client;
|
using IO.Swagger.Client;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace IO.Swagger.Test
|
namespace IO.Swagger.Test
|
||||||
{
|
{
|
||||||
@ -50,6 +51,25 @@ namespace IO.Swagger.Test
|
|||||||
Assert.IsInstanceOfType(typeof(Animal), instance, "instance is a Animal");
|
Assert.IsInstanceOfType(typeof(Animal), instance, "instance is a Animal");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test deserialize a Dog from type Animal
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void DogDeserializeFromAnimalTest()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to test deserialize a Dog from type Animal
|
||||||
|
//Assert.IsInstanceOf<Animal>(JsonConvert.DeserializeObject<Animal>(new Dog().ToJson()));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Test deserialize a Cat from type Animal
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void CatDeserializeFromAnimalTest()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to test deserialize a Cat from type Animal
|
||||||
|
//Assert.IsInstanceOf<Animal>(JsonConvert.DeserializeObject<Animal>(new Cat().ToJson()));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test the property 'ClassName'
|
/// Test the property 'ClassName'
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -0,0 +1,272 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace JsonSubTypes
|
||||||
|
{
|
||||||
|
// Copied from project https://github.com/manuc66/JsonSubTypes
|
||||||
|
// https://raw.githubusercontent.com/manuc66/JsonSubTypes/07403192ea3f4959f6d42f5966ac56ceb0d6095b/JsonSubTypes/JsonSubtypes.cs
|
||||||
|
|
||||||
|
public class JsonSubtypes : JsonConverter
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
|
||||||
|
public class KnownSubTypeAttribute : Attribute
|
||||||
|
{
|
||||||
|
public Type SubType { get; private set; }
|
||||||
|
public object AssociatedValue { get; private set; }
|
||||||
|
|
||||||
|
public KnownSubTypeAttribute(Type subType, object associatedValue)
|
||||||
|
{
|
||||||
|
SubType = subType;
|
||||||
|
AssociatedValue = associatedValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
|
||||||
|
public class KnownSubTypeWithPropertyAttribute : Attribute
|
||||||
|
{
|
||||||
|
public Type SubType { get; private set; }
|
||||||
|
public string PropertyName { get; private set; }
|
||||||
|
|
||||||
|
public KnownSubTypeWithPropertyAttribute(Type subType, string propertyName)
|
||||||
|
{
|
||||||
|
SubType = subType;
|
||||||
|
PropertyName = propertyName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _typeMappingPropertyName;
|
||||||
|
|
||||||
|
private bool _isInsideRead;
|
||||||
|
private JsonReader _reader;
|
||||||
|
|
||||||
|
public override bool CanRead
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!_isInsideRead)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return !string.IsNullOrEmpty(_reader.Path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed override bool CanWrite
|
||||||
|
{
|
||||||
|
get { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonSubtypes()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonSubtypes(string typeMappingPropertyName)
|
||||||
|
{
|
||||||
|
_typeMappingPropertyName = typeMappingPropertyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanConvert(Type objectType)
|
||||||
|
{
|
||||||
|
return _typeMappingPropertyName != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
if (reader.TokenType == JsonToken.Comment)
|
||||||
|
reader.Read();
|
||||||
|
|
||||||
|
switch (reader.TokenType)
|
||||||
|
{
|
||||||
|
case JsonToken.Null:
|
||||||
|
return null;
|
||||||
|
case JsonToken.StartArray:
|
||||||
|
return ReadArray(reader, objectType, serializer);
|
||||||
|
case JsonToken.StartObject:
|
||||||
|
return ReadObject(reader, objectType, serializer);
|
||||||
|
default:
|
||||||
|
throw new Exception("Array: Unrecognized token: " + reader.TokenType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IList ReadArray(JsonReader reader, Type targetType, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
var elementType = GetElementType(targetType);
|
||||||
|
|
||||||
|
var list = CreateCompatibleList(targetType, elementType);
|
||||||
|
|
||||||
|
while (reader.TokenType != JsonToken.EndArray && reader.Read())
|
||||||
|
{
|
||||||
|
switch (reader.TokenType)
|
||||||
|
{
|
||||||
|
case JsonToken.Null:
|
||||||
|
list.Add(reader.Value);
|
||||||
|
break;
|
||||||
|
case JsonToken.Comment:
|
||||||
|
break;
|
||||||
|
case JsonToken.StartObject:
|
||||||
|
list.Add(ReadObject(reader, elementType, serializer));
|
||||||
|
break;
|
||||||
|
case JsonToken.EndArray:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("Array: Unrecognized token: " + reader.TokenType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (targetType.IsArray)
|
||||||
|
{
|
||||||
|
var array = Array.CreateInstance(targetType.GetElementType(), list.Count);
|
||||||
|
list.CopyTo(array, 0);
|
||||||
|
list = array;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IList CreateCompatibleList(Type targetContainerType, Type elementType)
|
||||||
|
{
|
||||||
|
IList list;
|
||||||
|
if (targetContainerType.IsArray || targetContainerType.GetTypeInfo().IsAbstract)
|
||||||
|
{
|
||||||
|
list = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list = (IList)Activator.CreateInstance(targetContainerType);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetElementType(Type arrayOrGenericContainer)
|
||||||
|
{
|
||||||
|
Type elementType;
|
||||||
|
if (arrayOrGenericContainer.IsArray)
|
||||||
|
{
|
||||||
|
elementType = arrayOrGenericContainer.GetElementType();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
elementType = arrayOrGenericContainer.GenericTypeArguments[0];
|
||||||
|
}
|
||||||
|
return elementType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private object ReadObject(JsonReader reader, Type objectType, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
var jObject = JObject.Load(reader);
|
||||||
|
|
||||||
|
var targetType = GetType(jObject, objectType) ?? objectType;
|
||||||
|
|
||||||
|
return _ReadJson(CreateAnotherReader(jObject, reader), targetType, null, serializer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonReader CreateAnotherReader(JObject jObject, JsonReader reader)
|
||||||
|
{
|
||||||
|
var jObjectReader = jObject.CreateReader();
|
||||||
|
jObjectReader.Culture = reader.Culture;
|
||||||
|
jObjectReader.CloseInput = reader.CloseInput;
|
||||||
|
jObjectReader.SupportMultipleContent = reader.SupportMultipleContent;
|
||||||
|
jObjectReader.DateTimeZoneHandling = reader.DateTimeZoneHandling;
|
||||||
|
jObjectReader.FloatParseHandling = reader.FloatParseHandling;
|
||||||
|
jObjectReader.DateFormatString = reader.DateFormatString;
|
||||||
|
jObjectReader.DateParseHandling = reader.DateParseHandling;
|
||||||
|
return jObjectReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type GetType(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
if (_typeMappingPropertyName == null)
|
||||||
|
{
|
||||||
|
return GetTypeByPropertyPresence(jObject, parentType);
|
||||||
|
}
|
||||||
|
return GetTypeFromDiscriminatorValue(jObject, parentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeByPropertyPresence(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
foreach (var type in parentType.GetTypeInfo().GetCustomAttributes<KnownSubTypeWithPropertyAttribute>())
|
||||||
|
{
|
||||||
|
JToken ignore;
|
||||||
|
if (jObject.TryGetValue(type.PropertyName, out ignore))
|
||||||
|
{
|
||||||
|
return type.SubType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Type GetTypeFromDiscriminatorValue(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
JToken jToken;
|
||||||
|
if (!jObject.TryGetValue(_typeMappingPropertyName, out jToken)) return null;
|
||||||
|
|
||||||
|
var discriminatorValue = jToken.ToObject<object>();
|
||||||
|
if (discriminatorValue == null) return null;
|
||||||
|
|
||||||
|
var typeMapping = GetSubTypeMapping(parentType);
|
||||||
|
if (typeMapping.Any())
|
||||||
|
{
|
||||||
|
return GetTypeFromMapping(typeMapping, discriminatorValue);
|
||||||
|
}
|
||||||
|
return GetTypeByName(discriminatorValue as string, parentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeByName(string typeName, Type parentType)
|
||||||
|
{
|
||||||
|
if (typeName == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var insideAssembly = parentType.GetTypeInfo().Assembly;
|
||||||
|
|
||||||
|
var typeByName = insideAssembly.GetType(typeName);
|
||||||
|
if (typeByName == null)
|
||||||
|
{
|
||||||
|
var searchLocation = parentType.FullName.Substring(0, parentType.FullName.Length - parentType.Name.Length);
|
||||||
|
typeByName = insideAssembly.GetType(searchLocation + typeName, false, true);
|
||||||
|
}
|
||||||
|
return typeByName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeFromMapping(IReadOnlyDictionary<object, Type> typeMapping, object discriminatorValue)
|
||||||
|
{
|
||||||
|
var targetlookupValueType = typeMapping.First().Key.GetType();
|
||||||
|
var lookupValue = ConvertJsonValueToType(discriminatorValue, targetlookupValueType);
|
||||||
|
|
||||||
|
Type targetType;
|
||||||
|
return typeMapping.TryGetValue(lookupValue, out targetType) ? targetType : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Dictionary<object, Type> GetSubTypeMapping(Type type)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().GetCustomAttributes<KnownSubTypeAttribute>().ToDictionary(x => x.AssociatedValue, x => x.SubType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static object ConvertJsonValueToType(object objectType, Type targetlookupValueType)
|
||||||
|
{
|
||||||
|
if (targetlookupValueType.GetTypeInfo().IsEnum)
|
||||||
|
return Enum.ToObject(targetlookupValueType, objectType);
|
||||||
|
|
||||||
|
return Convert.ChangeType(objectType, targetlookupValueType);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected object _ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
_reader = reader;
|
||||||
|
_isInsideRead = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return serializer.Deserialize(reader, objectType);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isInsideRead = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -99,13 +99,13 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.MapProperty == input.MapProperty ||
|
this.MapProperty == input.MapProperty ||
|
||||||
(this.MapProperty != null &&
|
this.MapProperty != null &&
|
||||||
this.MapProperty.SequenceEqual(input.MapProperty))
|
this.MapProperty.SequenceEqual(input.MapProperty)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.MapOfMapProperty == input.MapOfMapProperty ||
|
this.MapOfMapProperty == input.MapOfMapProperty ||
|
||||||
(this.MapOfMapProperty != null &&
|
this.MapOfMapProperty != null &&
|
||||||
this.MapOfMapProperty.SequenceEqual(input.MapOfMapProperty))
|
this.MapOfMapProperty.SequenceEqual(input.MapOfMapProperty)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
using JsonSubTypes;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using SwaggerDateConverter = IO.Swagger.Client.SwaggerDateConverter;
|
using SwaggerDateConverter = IO.Swagger.Client.SwaggerDateConverter;
|
||||||
|
|
||||||
@ -28,6 +29,9 @@ namespace IO.Swagger.Model
|
|||||||
/// Animal
|
/// Animal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataContract]
|
[DataContract]
|
||||||
|
[JsonConverter(typeof(JsonSubtypes), "className")]
|
||||||
|
[JsonSubtypes.KnownSubType(typeof(Dog), "Dog")]
|
||||||
|
[JsonSubtypes.KnownSubType(typeof(Cat), "Cat")]
|
||||||
public partial class Animal : IEquatable<Animal>, IValidatableObject
|
public partial class Animal : IEquatable<Animal>, IValidatableObject
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -92,7 +96,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public string ToJson()
|
public virtual string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -153,6 +157,16 @@ namespace IO.Swagger.Model
|
|||||||
/// <param name="validationContext">Validation context</param>
|
/// <param name="validationContext">Validation context</param>
|
||||||
/// <returns>Validation Result</returns>
|
/// <returns>Validation Result</returns>
|
||||||
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
||||||
|
{
|
||||||
|
return this.BaseValidate(validationContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// To validate all properties of the instance
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext">Validation context</param>
|
||||||
|
/// <returns>Validation Result</returns>
|
||||||
|
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
|
||||||
{
|
{
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Initializes a new instance of the <see cref="AnimalFarm" /> class.
|
/// Initializes a new instance of the <see cref="AnimalFarm" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonConstructorAttribute]
|
[JsonConstructorAttribute]
|
||||||
public AnimalFarm()
|
public AnimalFarm() : base()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +46,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class AnimalFarm {\n");
|
sb.Append("class AnimalFarm {\n");
|
||||||
|
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
|
||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
@ -54,7 +55,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public new string ToJson()
|
public string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -79,7 +80,7 @@ namespace IO.Swagger.Model
|
|||||||
if (input == null)
|
if (input == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return false;
|
return base.Equals(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -90,7 +91,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
unchecked // Overflow is fine, just wrap
|
unchecked // Overflow is fine, just wrap
|
||||||
{
|
{
|
||||||
int hashCode = 41;
|
int hashCode = base.GetHashCode();
|
||||||
return hashCode;
|
return hashCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,8 +90,8 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.ArrayArrayNumber == input.ArrayArrayNumber ||
|
this.ArrayArrayNumber == input.ArrayArrayNumber ||
|
||||||
(this.ArrayArrayNumber != null &&
|
this.ArrayArrayNumber != null &&
|
||||||
this.ArrayArrayNumber.SequenceEqual(input.ArrayArrayNumber))
|
this.ArrayArrayNumber.SequenceEqual(input.ArrayArrayNumber)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,8 +90,8 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.ArrayNumber == input.ArrayNumber ||
|
this.ArrayNumber == input.ArrayNumber ||
|
||||||
(this.ArrayNumber != null &&
|
this.ArrayNumber != null &&
|
||||||
this.ArrayNumber.SequenceEqual(input.ArrayNumber))
|
this.ArrayNumber.SequenceEqual(input.ArrayNumber)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,18 +108,18 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.ArrayOfString == input.ArrayOfString ||
|
this.ArrayOfString == input.ArrayOfString ||
|
||||||
(this.ArrayOfString != null &&
|
this.ArrayOfString != null &&
|
||||||
this.ArrayOfString.SequenceEqual(input.ArrayOfString))
|
this.ArrayOfString.SequenceEqual(input.ArrayOfString)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.ArrayArrayOfInteger == input.ArrayArrayOfInteger ||
|
this.ArrayArrayOfInteger == input.ArrayArrayOfInteger ||
|
||||||
(this.ArrayArrayOfInteger != null &&
|
this.ArrayArrayOfInteger != null &&
|
||||||
this.ArrayArrayOfInteger.SequenceEqual(input.ArrayArrayOfInteger))
|
this.ArrayArrayOfInteger.SequenceEqual(input.ArrayArrayOfInteger)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.ArrayArrayOfModel == input.ArrayArrayOfModel ||
|
this.ArrayArrayOfModel == input.ArrayArrayOfModel ||
|
||||||
(this.ArrayArrayOfModel != null &&
|
this.ArrayArrayOfModel != null &&
|
||||||
this.ArrayArrayOfModel.SequenceEqual(input.ArrayArrayOfModel))
|
this.ArrayArrayOfModel.SequenceEqual(input.ArrayArrayOfModel)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,44 +38,12 @@ namespace IO.Swagger.Model
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Cat" /> class.
|
/// Initializes a new instance of the <see cref="Cat" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ClassName">ClassName (required).</param>
|
|
||||||
/// <param name="Color">Color (default to "red").</param>
|
|
||||||
/// <param name="Declawed">Declawed.</param>
|
/// <param name="Declawed">Declawed.</param>
|
||||||
public Cat(string ClassName = default(string), string Color = "red", bool? Declawed = default(bool?))
|
public Cat(bool? Declawed = default(bool?), string ClassName = "Cat", string Color = "red") : base(ClassName, Color)
|
||||||
{
|
{
|
||||||
// to ensure "ClassName" is required (not null)
|
|
||||||
if (ClassName == null)
|
|
||||||
{
|
|
||||||
throw new InvalidDataException("ClassName is a required property for Cat and cannot be null");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.ClassName = ClassName;
|
|
||||||
}
|
|
||||||
// use default value if no "Color" provided
|
|
||||||
if (Color == null)
|
|
||||||
{
|
|
||||||
this.Color = "red";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Color = Color;
|
|
||||||
}
|
|
||||||
this.Declawed = Declawed;
|
this.Declawed = Declawed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets ClassName
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="className", EmitDefaultValue=false)]
|
|
||||||
public string ClassName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets Color
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="color", EmitDefaultValue=false)]
|
|
||||||
public string Color { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Declawed
|
/// Gets or Sets Declawed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -90,8 +58,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class Cat {\n");
|
sb.Append("class Cat {\n");
|
||||||
sb.Append(" ClassName: ").Append(ClassName).Append("\n");
|
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
|
||||||
sb.Append(" Color: ").Append(Color).Append("\n");
|
|
||||||
sb.Append(" Declawed: ").Append(Declawed).Append("\n");
|
sb.Append(" Declawed: ").Append(Declawed).Append("\n");
|
||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
@ -101,7 +68,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public new string ToJson()
|
public override string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -126,17 +93,7 @@ namespace IO.Swagger.Model
|
|||||||
if (input == null)
|
if (input == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return
|
return base.Equals(input) &&
|
||||||
(
|
|
||||||
this.ClassName == input.ClassName ||
|
|
||||||
(this.ClassName != null &&
|
|
||||||
this.ClassName.Equals(input.ClassName))
|
|
||||||
) &&
|
|
||||||
(
|
|
||||||
this.Color == input.Color ||
|
|
||||||
(this.Color != null &&
|
|
||||||
this.Color.Equals(input.Color))
|
|
||||||
) &&
|
|
||||||
(
|
(
|
||||||
this.Declawed == input.Declawed ||
|
this.Declawed == input.Declawed ||
|
||||||
(this.Declawed != null &&
|
(this.Declawed != null &&
|
||||||
@ -152,11 +109,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
unchecked // Overflow is fine, just wrap
|
unchecked // Overflow is fine, just wrap
|
||||||
{
|
{
|
||||||
int hashCode = 41;
|
int hashCode = base.GetHashCode();
|
||||||
if (this.ClassName != null)
|
|
||||||
hashCode = hashCode * 59 + this.ClassName.GetHashCode();
|
|
||||||
if (this.Color != null)
|
|
||||||
hashCode = hashCode * 59 + this.Color.GetHashCode();
|
|
||||||
if (this.Declawed != null)
|
if (this.Declawed != null)
|
||||||
hashCode = hashCode * 59 + this.Declawed.GetHashCode();
|
hashCode = hashCode * 59 + this.Declawed.GetHashCode();
|
||||||
return hashCode;
|
return hashCode;
|
||||||
@ -170,6 +123,7 @@ namespace IO.Swagger.Model
|
|||||||
/// <returns>Validation Result</returns>
|
/// <returns>Validation Result</returns>
|
||||||
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
||||||
{
|
{
|
||||||
|
foreach(var x in BaseValidate(validationContext)) yield return x;
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,44 +38,12 @@ namespace IO.Swagger.Model
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Dog" /> class.
|
/// Initializes a new instance of the <see cref="Dog" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ClassName">ClassName (required).</param>
|
|
||||||
/// <param name="Color">Color (default to "red").</param>
|
|
||||||
/// <param name="Breed">Breed.</param>
|
/// <param name="Breed">Breed.</param>
|
||||||
public Dog(string ClassName = default(string), string Color = "red", string Breed = default(string))
|
public Dog(string Breed = default(string), string ClassName = "Dog", string Color = "red") : base(ClassName, Color)
|
||||||
{
|
{
|
||||||
// to ensure "ClassName" is required (not null)
|
|
||||||
if (ClassName == null)
|
|
||||||
{
|
|
||||||
throw new InvalidDataException("ClassName is a required property for Dog and cannot be null");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.ClassName = ClassName;
|
|
||||||
}
|
|
||||||
// use default value if no "Color" provided
|
|
||||||
if (Color == null)
|
|
||||||
{
|
|
||||||
this.Color = "red";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Color = Color;
|
|
||||||
}
|
|
||||||
this.Breed = Breed;
|
this.Breed = Breed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets ClassName
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="className", EmitDefaultValue=false)]
|
|
||||||
public string ClassName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets Color
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="color", EmitDefaultValue=false)]
|
|
||||||
public string Color { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Breed
|
/// Gets or Sets Breed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -90,8 +58,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class Dog {\n");
|
sb.Append("class Dog {\n");
|
||||||
sb.Append(" ClassName: ").Append(ClassName).Append("\n");
|
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
|
||||||
sb.Append(" Color: ").Append(Color).Append("\n");
|
|
||||||
sb.Append(" Breed: ").Append(Breed).Append("\n");
|
sb.Append(" Breed: ").Append(Breed).Append("\n");
|
||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
@ -101,7 +68,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public new string ToJson()
|
public override string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -126,17 +93,7 @@ namespace IO.Swagger.Model
|
|||||||
if (input == null)
|
if (input == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return
|
return base.Equals(input) &&
|
||||||
(
|
|
||||||
this.ClassName == input.ClassName ||
|
|
||||||
(this.ClassName != null &&
|
|
||||||
this.ClassName.Equals(input.ClassName))
|
|
||||||
) &&
|
|
||||||
(
|
|
||||||
this.Color == input.Color ||
|
|
||||||
(this.Color != null &&
|
|
||||||
this.Color.Equals(input.Color))
|
|
||||||
) &&
|
|
||||||
(
|
(
|
||||||
this.Breed == input.Breed ||
|
this.Breed == input.Breed ||
|
||||||
(this.Breed != null &&
|
(this.Breed != null &&
|
||||||
@ -152,11 +109,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
unchecked // Overflow is fine, just wrap
|
unchecked // Overflow is fine, just wrap
|
||||||
{
|
{
|
||||||
int hashCode = 41;
|
int hashCode = base.GetHashCode();
|
||||||
if (this.ClassName != null)
|
|
||||||
hashCode = hashCode * 59 + this.ClassName.GetHashCode();
|
|
||||||
if (this.Color != null)
|
|
||||||
hashCode = hashCode * 59 + this.Color.GetHashCode();
|
|
||||||
if (this.Breed != null)
|
if (this.Breed != null)
|
||||||
hashCode = hashCode * 59 + this.Breed.GetHashCode();
|
hashCode = hashCode * 59 + this.Breed.GetHashCode();
|
||||||
return hashCode;
|
return hashCode;
|
||||||
@ -170,6 +123,7 @@ namespace IO.Swagger.Model
|
|||||||
/// <returns>Validation Result</returns>
|
/// <returns>Validation Result</returns>
|
||||||
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
||||||
{
|
{
|
||||||
|
foreach(var x in BaseValidate(validationContext)) yield return x;
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,8 +145,8 @@ namespace IO.Swagger.Model
|
|||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.ArrayEnum == input.ArrayEnum ||
|
this.ArrayEnum == input.ArrayEnum ||
|
||||||
(this.ArrayEnum != null &&
|
this.ArrayEnum != null &&
|
||||||
this.ArrayEnum.SequenceEqual(input.ArrayEnum))
|
this.ArrayEnum.SequenceEqual(input.ArrayEnum)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,13 +120,13 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.MapMapOfString == input.MapMapOfString ||
|
this.MapMapOfString == input.MapMapOfString ||
|
||||||
(this.MapMapOfString != null &&
|
this.MapMapOfString != null &&
|
||||||
this.MapMapOfString.SequenceEqual(input.MapMapOfString))
|
this.MapMapOfString.SequenceEqual(input.MapMapOfString)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.MapOfEnumString == input.MapOfEnumString ||
|
this.MapOfEnumString == input.MapOfEnumString ||
|
||||||
(this.MapOfEnumString != null &&
|
this.MapOfEnumString != null &&
|
||||||
this.MapOfEnumString.SequenceEqual(input.MapOfEnumString))
|
this.MapOfEnumString.SequenceEqual(input.MapOfEnumString)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,8 +118,8 @@ namespace IO.Swagger.Model
|
|||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.Map == input.Map ||
|
this.Map == input.Map ||
|
||||||
(this.Map != null &&
|
this.Map != null &&
|
||||||
this.Map.SequenceEqual(input.Map))
|
this.Map.SequenceEqual(input.Map)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,13 +199,13 @@ namespace IO.Swagger.Model
|
|||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.PhotoUrls == input.PhotoUrls ||
|
this.PhotoUrls == input.PhotoUrls ||
|
||||||
(this.PhotoUrls != null &&
|
this.PhotoUrls != null &&
|
||||||
this.PhotoUrls.SequenceEqual(input.PhotoUrls))
|
this.PhotoUrls.SequenceEqual(input.PhotoUrls)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.Tags == input.Tags ||
|
this.Tags == input.Tags ||
|
||||||
(this.Tags != null &&
|
this.Tags != null &&
|
||||||
this.Tags.SequenceEqual(input.Tags))
|
this.Tags.SequenceEqual(input.Tags)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.Status == input.Status ||
|
this.Status == input.Status ||
|
||||||
|
@ -5,21 +5,21 @@ MinimumVisualStudioVersion = 10.0.40219.1
|
|||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{67035b31-f8e5-41a4-9673-954035084f7d}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{67035b31-f8e5-41a4-9673-954035084f7d}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{67035b31-f8e5-41a4-9673-954035084f7d}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{67035b31-f8e5-41a4-9673-954035084f7d}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{67035b31-f8e5-41a4-9673-954035084f7d}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{67035b31-f8e5-41a4-9673-954035084f7d}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{67035b31-f8e5-41a4-9673-954035084f7d}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{67035b31-f8e5-41a4-9673-954035084f7d}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{67035b31-f8e5-41a4-9673-954035084f7d}.Release|Any CPU.Build.0 = Release|Any CPU
|
{67035b31-f8e5-41a4-9673-954035084f7d}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.Build.0 = Release|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
@ -0,0 +1,272 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace JsonSubTypes
|
||||||
|
{
|
||||||
|
// Copied from project https://github.com/manuc66/JsonSubTypes
|
||||||
|
// https://raw.githubusercontent.com/manuc66/JsonSubTypes/07403192ea3f4959f6d42f5966ac56ceb0d6095b/JsonSubTypes/JsonSubtypes.cs
|
||||||
|
|
||||||
|
public class JsonSubtypes : JsonConverter
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
|
||||||
|
public class KnownSubTypeAttribute : Attribute
|
||||||
|
{
|
||||||
|
public Type SubType { get; private set; }
|
||||||
|
public object AssociatedValue { get; private set; }
|
||||||
|
|
||||||
|
public KnownSubTypeAttribute(Type subType, object associatedValue)
|
||||||
|
{
|
||||||
|
SubType = subType;
|
||||||
|
AssociatedValue = associatedValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
|
||||||
|
public class KnownSubTypeWithPropertyAttribute : Attribute
|
||||||
|
{
|
||||||
|
public Type SubType { get; private set; }
|
||||||
|
public string PropertyName { get; private set; }
|
||||||
|
|
||||||
|
public KnownSubTypeWithPropertyAttribute(Type subType, string propertyName)
|
||||||
|
{
|
||||||
|
SubType = subType;
|
||||||
|
PropertyName = propertyName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _typeMappingPropertyName;
|
||||||
|
|
||||||
|
private bool _isInsideRead;
|
||||||
|
private JsonReader _reader;
|
||||||
|
|
||||||
|
public override bool CanRead
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!_isInsideRead)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return !string.IsNullOrEmpty(_reader.Path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed override bool CanWrite
|
||||||
|
{
|
||||||
|
get { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonSubtypes()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonSubtypes(string typeMappingPropertyName)
|
||||||
|
{
|
||||||
|
_typeMappingPropertyName = typeMappingPropertyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanConvert(Type objectType)
|
||||||
|
{
|
||||||
|
return _typeMappingPropertyName != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
if (reader.TokenType == JsonToken.Comment)
|
||||||
|
reader.Read();
|
||||||
|
|
||||||
|
switch (reader.TokenType)
|
||||||
|
{
|
||||||
|
case JsonToken.Null:
|
||||||
|
return null;
|
||||||
|
case JsonToken.StartArray:
|
||||||
|
return ReadArray(reader, objectType, serializer);
|
||||||
|
case JsonToken.StartObject:
|
||||||
|
return ReadObject(reader, objectType, serializer);
|
||||||
|
default:
|
||||||
|
throw new Exception("Array: Unrecognized token: " + reader.TokenType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IList ReadArray(JsonReader reader, Type targetType, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
var elementType = GetElementType(targetType);
|
||||||
|
|
||||||
|
var list = CreateCompatibleList(targetType, elementType);
|
||||||
|
|
||||||
|
while (reader.TokenType != JsonToken.EndArray && reader.Read())
|
||||||
|
{
|
||||||
|
switch (reader.TokenType)
|
||||||
|
{
|
||||||
|
case JsonToken.Null:
|
||||||
|
list.Add(reader.Value);
|
||||||
|
break;
|
||||||
|
case JsonToken.Comment:
|
||||||
|
break;
|
||||||
|
case JsonToken.StartObject:
|
||||||
|
list.Add(ReadObject(reader, elementType, serializer));
|
||||||
|
break;
|
||||||
|
case JsonToken.EndArray:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("Array: Unrecognized token: " + reader.TokenType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (targetType.IsArray)
|
||||||
|
{
|
||||||
|
var array = Array.CreateInstance(targetType.GetElementType(), list.Count);
|
||||||
|
list.CopyTo(array, 0);
|
||||||
|
list = array;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IList CreateCompatibleList(Type targetContainerType, Type elementType)
|
||||||
|
{
|
||||||
|
IList list;
|
||||||
|
if (targetContainerType.IsArray || targetContainerType.GetTypeInfo().IsAbstract)
|
||||||
|
{
|
||||||
|
list = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list = (IList)Activator.CreateInstance(targetContainerType);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetElementType(Type arrayOrGenericContainer)
|
||||||
|
{
|
||||||
|
Type elementType;
|
||||||
|
if (arrayOrGenericContainer.IsArray)
|
||||||
|
{
|
||||||
|
elementType = arrayOrGenericContainer.GetElementType();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
elementType = arrayOrGenericContainer.GenericTypeArguments[0];
|
||||||
|
}
|
||||||
|
return elementType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private object ReadObject(JsonReader reader, Type objectType, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
var jObject = JObject.Load(reader);
|
||||||
|
|
||||||
|
var targetType = GetType(jObject, objectType) ?? objectType;
|
||||||
|
|
||||||
|
return _ReadJson(CreateAnotherReader(jObject, reader), targetType, null, serializer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonReader CreateAnotherReader(JObject jObject, JsonReader reader)
|
||||||
|
{
|
||||||
|
var jObjectReader = jObject.CreateReader();
|
||||||
|
jObjectReader.Culture = reader.Culture;
|
||||||
|
jObjectReader.CloseInput = reader.CloseInput;
|
||||||
|
jObjectReader.SupportMultipleContent = reader.SupportMultipleContent;
|
||||||
|
jObjectReader.DateTimeZoneHandling = reader.DateTimeZoneHandling;
|
||||||
|
jObjectReader.FloatParseHandling = reader.FloatParseHandling;
|
||||||
|
jObjectReader.DateFormatString = reader.DateFormatString;
|
||||||
|
jObjectReader.DateParseHandling = reader.DateParseHandling;
|
||||||
|
return jObjectReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type GetType(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
if (_typeMappingPropertyName == null)
|
||||||
|
{
|
||||||
|
return GetTypeByPropertyPresence(jObject, parentType);
|
||||||
|
}
|
||||||
|
return GetTypeFromDiscriminatorValue(jObject, parentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeByPropertyPresence(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
foreach (var type in parentType.GetTypeInfo().GetCustomAttributes<KnownSubTypeWithPropertyAttribute>())
|
||||||
|
{
|
||||||
|
JToken ignore;
|
||||||
|
if (jObject.TryGetValue(type.PropertyName, out ignore))
|
||||||
|
{
|
||||||
|
return type.SubType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Type GetTypeFromDiscriminatorValue(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
JToken jToken;
|
||||||
|
if (!jObject.TryGetValue(_typeMappingPropertyName, out jToken)) return null;
|
||||||
|
|
||||||
|
var discriminatorValue = jToken.ToObject<object>();
|
||||||
|
if (discriminatorValue == null) return null;
|
||||||
|
|
||||||
|
var typeMapping = GetSubTypeMapping(parentType);
|
||||||
|
if (typeMapping.Any())
|
||||||
|
{
|
||||||
|
return GetTypeFromMapping(typeMapping, discriminatorValue);
|
||||||
|
}
|
||||||
|
return GetTypeByName(discriminatorValue as string, parentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeByName(string typeName, Type parentType)
|
||||||
|
{
|
||||||
|
if (typeName == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var insideAssembly = parentType.GetTypeInfo().Assembly;
|
||||||
|
|
||||||
|
var typeByName = insideAssembly.GetType(typeName);
|
||||||
|
if (typeByName == null)
|
||||||
|
{
|
||||||
|
var searchLocation = parentType.FullName.Substring(0, parentType.FullName.Length - parentType.Name.Length);
|
||||||
|
typeByName = insideAssembly.GetType(searchLocation + typeName, false, true);
|
||||||
|
}
|
||||||
|
return typeByName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeFromMapping(IReadOnlyDictionary<object, Type> typeMapping, object discriminatorValue)
|
||||||
|
{
|
||||||
|
var targetlookupValueType = typeMapping.First().Key.GetType();
|
||||||
|
var lookupValue = ConvertJsonValueToType(discriminatorValue, targetlookupValueType);
|
||||||
|
|
||||||
|
Type targetType;
|
||||||
|
return typeMapping.TryGetValue(lookupValue, out targetType) ? targetType : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Dictionary<object, Type> GetSubTypeMapping(Type type)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().GetCustomAttributes<KnownSubTypeAttribute>().ToDictionary(x => x.AssociatedValue, x => x.SubType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static object ConvertJsonValueToType(object objectType, Type targetlookupValueType)
|
||||||
|
{
|
||||||
|
if (targetlookupValueType.GetTypeInfo().IsEnum)
|
||||||
|
return Enum.ToObject(targetlookupValueType, objectType);
|
||||||
|
|
||||||
|
return Convert.ChangeType(objectType, targetlookupValueType);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected object _ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
_reader = reader;
|
||||||
|
_isInsideRead = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return serializer.Deserialize(reader, objectType);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isInsideRead = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
using JsonSubTypes;
|
||||||
using SwaggerDateConverter = IO.Swagger.Client.SwaggerDateConverter;
|
using SwaggerDateConverter = IO.Swagger.Client.SwaggerDateConverter;
|
||||||
|
|
||||||
namespace IO.Swagger.Model
|
namespace IO.Swagger.Model
|
||||||
@ -26,6 +27,9 @@ namespace IO.Swagger.Model
|
|||||||
/// Animal
|
/// Animal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataContract]
|
[DataContract]
|
||||||
|
[JsonConverter(typeof(JsonSubtypes), "className")]
|
||||||
|
[JsonSubtypes.KnownSubType(typeof(Dog), "Dog")]
|
||||||
|
[JsonSubtypes.KnownSubType(typeof(Cat), "Cat")]
|
||||||
public partial class Animal : IEquatable<Animal>
|
public partial class Animal : IEquatable<Animal>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -90,7 +94,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public string ToJson()
|
public virtual string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Initializes a new instance of the <see cref="AnimalFarm" /> class.
|
/// Initializes a new instance of the <see cref="AnimalFarm" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonConstructorAttribute]
|
[JsonConstructorAttribute]
|
||||||
public AnimalFarm()
|
public AnimalFarm() : base()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +44,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class AnimalFarm {\n");
|
sb.Append("class AnimalFarm {\n");
|
||||||
|
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
|
||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
@ -52,7 +53,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public new string ToJson()
|
public string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -79,7 +80,7 @@ namespace IO.Swagger.Model
|
|||||||
if (other == null)
|
if (other == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return false;
|
return base.Equals(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -91,7 +92,7 @@ namespace IO.Swagger.Model
|
|||||||
// credit: http://stackoverflow.com/a/263416/677735
|
// credit: http://stackoverflow.com/a/263416/677735
|
||||||
unchecked // Overflow is fine, just wrap
|
unchecked // Overflow is fine, just wrap
|
||||||
{
|
{
|
||||||
int hash = 41;
|
int hash = base.GetHashCode();
|
||||||
// Suitable nullity checks etc, of course :)
|
// Suitable nullity checks etc, of course :)
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
@ -36,44 +36,12 @@ namespace IO.Swagger.Model
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Cat" /> class.
|
/// Initializes a new instance of the <see cref="Cat" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ClassName">ClassName (required).</param>
|
|
||||||
/// <param name="Color">Color (default to "red").</param>
|
|
||||||
/// <param name="Declawed">Declawed.</param>
|
/// <param name="Declawed">Declawed.</param>
|
||||||
public Cat(string ClassName = default(string), string Color = "red", bool? Declawed = default(bool?))
|
public Cat(bool? Declawed = default(bool?), string ClassName = "Cat", string Color = "red") : base(ClassName, Color)
|
||||||
{
|
{
|
||||||
// to ensure "ClassName" is required (not null)
|
|
||||||
if (ClassName == null)
|
|
||||||
{
|
|
||||||
throw new InvalidDataException("ClassName is a required property for Cat and cannot be null");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.ClassName = ClassName;
|
|
||||||
}
|
|
||||||
// use default value if no "Color" provided
|
|
||||||
if (Color == null)
|
|
||||||
{
|
|
||||||
this.Color = "red";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Color = Color;
|
|
||||||
}
|
|
||||||
this.Declawed = Declawed;
|
this.Declawed = Declawed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets ClassName
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="className", EmitDefaultValue=false)]
|
|
||||||
public string ClassName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets Color
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="color", EmitDefaultValue=false)]
|
|
||||||
public string Color { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Declawed
|
/// Gets or Sets Declawed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -88,8 +56,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class Cat {\n");
|
sb.Append("class Cat {\n");
|
||||||
sb.Append(" ClassName: ").Append(ClassName).Append("\n");
|
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
|
||||||
sb.Append(" Color: ").Append(Color).Append("\n");
|
|
||||||
sb.Append(" Declawed: ").Append(Declawed).Append("\n");
|
sb.Append(" Declawed: ").Append(Declawed).Append("\n");
|
||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
@ -99,7 +66,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public new string ToJson()
|
public override string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -126,17 +93,7 @@ namespace IO.Swagger.Model
|
|||||||
if (other == null)
|
if (other == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return
|
return base.Equals(other) &&
|
||||||
(
|
|
||||||
this.ClassName == other.ClassName ||
|
|
||||||
this.ClassName != null &&
|
|
||||||
this.ClassName.Equals(other.ClassName)
|
|
||||||
) &&
|
|
||||||
(
|
|
||||||
this.Color == other.Color ||
|
|
||||||
this.Color != null &&
|
|
||||||
this.Color.Equals(other.Color)
|
|
||||||
) &&
|
|
||||||
(
|
(
|
||||||
this.Declawed == other.Declawed ||
|
this.Declawed == other.Declawed ||
|
||||||
this.Declawed != null &&
|
this.Declawed != null &&
|
||||||
@ -153,12 +110,8 @@ namespace IO.Swagger.Model
|
|||||||
// credit: http://stackoverflow.com/a/263416/677735
|
// credit: http://stackoverflow.com/a/263416/677735
|
||||||
unchecked // Overflow is fine, just wrap
|
unchecked // Overflow is fine, just wrap
|
||||||
{
|
{
|
||||||
int hash = 41;
|
int hash = base.GetHashCode();
|
||||||
// Suitable nullity checks etc, of course :)
|
// Suitable nullity checks etc, of course :)
|
||||||
if (this.ClassName != null)
|
|
||||||
hash = hash * 59 + this.ClassName.GetHashCode();
|
|
||||||
if (this.Color != null)
|
|
||||||
hash = hash * 59 + this.Color.GetHashCode();
|
|
||||||
if (this.Declawed != null)
|
if (this.Declawed != null)
|
||||||
hash = hash * 59 + this.Declawed.GetHashCode();
|
hash = hash * 59 + this.Declawed.GetHashCode();
|
||||||
return hash;
|
return hash;
|
||||||
|
@ -36,44 +36,12 @@ namespace IO.Swagger.Model
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Dog" /> class.
|
/// Initializes a new instance of the <see cref="Dog" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ClassName">ClassName (required).</param>
|
|
||||||
/// <param name="Color">Color (default to "red").</param>
|
|
||||||
/// <param name="Breed">Breed.</param>
|
/// <param name="Breed">Breed.</param>
|
||||||
public Dog(string ClassName = default(string), string Color = "red", string Breed = default(string))
|
public Dog(string Breed = default(string), string ClassName = "Dog", string Color = "red") : base(ClassName, Color)
|
||||||
{
|
{
|
||||||
// to ensure "ClassName" is required (not null)
|
|
||||||
if (ClassName == null)
|
|
||||||
{
|
|
||||||
throw new InvalidDataException("ClassName is a required property for Dog and cannot be null");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.ClassName = ClassName;
|
|
||||||
}
|
|
||||||
// use default value if no "Color" provided
|
|
||||||
if (Color == null)
|
|
||||||
{
|
|
||||||
this.Color = "red";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Color = Color;
|
|
||||||
}
|
|
||||||
this.Breed = Breed;
|
this.Breed = Breed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets ClassName
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="className", EmitDefaultValue=false)]
|
|
||||||
public string ClassName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets Color
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="color", EmitDefaultValue=false)]
|
|
||||||
public string Color { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Breed
|
/// Gets or Sets Breed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -88,8 +56,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class Dog {\n");
|
sb.Append("class Dog {\n");
|
||||||
sb.Append(" ClassName: ").Append(ClassName).Append("\n");
|
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
|
||||||
sb.Append(" Color: ").Append(Color).Append("\n");
|
|
||||||
sb.Append(" Breed: ").Append(Breed).Append("\n");
|
sb.Append(" Breed: ").Append(Breed).Append("\n");
|
||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
@ -99,7 +66,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public new string ToJson()
|
public override string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -126,17 +93,7 @@ namespace IO.Swagger.Model
|
|||||||
if (other == null)
|
if (other == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return
|
return base.Equals(other) &&
|
||||||
(
|
|
||||||
this.ClassName == other.ClassName ||
|
|
||||||
this.ClassName != null &&
|
|
||||||
this.ClassName.Equals(other.ClassName)
|
|
||||||
) &&
|
|
||||||
(
|
|
||||||
this.Color == other.Color ||
|
|
||||||
this.Color != null &&
|
|
||||||
this.Color.Equals(other.Color)
|
|
||||||
) &&
|
|
||||||
(
|
(
|
||||||
this.Breed == other.Breed ||
|
this.Breed == other.Breed ||
|
||||||
this.Breed != null &&
|
this.Breed != null &&
|
||||||
@ -153,12 +110,8 @@ namespace IO.Swagger.Model
|
|||||||
// credit: http://stackoverflow.com/a/263416/677735
|
// credit: http://stackoverflow.com/a/263416/677735
|
||||||
unchecked // Overflow is fine, just wrap
|
unchecked // Overflow is fine, just wrap
|
||||||
{
|
{
|
||||||
int hash = 41;
|
int hash = base.GetHashCode();
|
||||||
// Suitable nullity checks etc, of course :)
|
// Suitable nullity checks etc, of course :)
|
||||||
if (this.ClassName != null)
|
|
||||||
hash = hash * 59 + this.ClassName.GetHashCode();
|
|
||||||
if (this.Color != null)
|
|
||||||
hash = hash * 59 + this.Color.GetHashCode();
|
|
||||||
if (this.Breed != null)
|
if (this.Breed != null)
|
||||||
hash = hash * 59 + this.Breed.GetHashCode();
|
hash = hash * 59 + this.Breed.GetHashCode();
|
||||||
return hash;
|
return hash;
|
||||||
|
@ -5,21 +5,21 @@ MinimumVisualStudioVersion = 10.0.40219.1
|
|||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{321C8C3F-0156-40C1-AE42-D59761FB9B6C}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{321C8C3F-0156-40C1-AE42-D59761FB9B6C}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Release|Any CPU.Build.0 = Release|Any CPU
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.Build.0 = Release|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
@ -0,0 +1,272 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace JsonSubTypes
|
||||||
|
{
|
||||||
|
// Copied from project https://github.com/manuc66/JsonSubTypes
|
||||||
|
// https://raw.githubusercontent.com/manuc66/JsonSubTypes/07403192ea3f4959f6d42f5966ac56ceb0d6095b/JsonSubTypes/JsonSubtypes.cs
|
||||||
|
|
||||||
|
public class JsonSubtypes : JsonConverter
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
|
||||||
|
public class KnownSubTypeAttribute : Attribute
|
||||||
|
{
|
||||||
|
public Type SubType { get; private set; }
|
||||||
|
public object AssociatedValue { get; private set; }
|
||||||
|
|
||||||
|
public KnownSubTypeAttribute(Type subType, object associatedValue)
|
||||||
|
{
|
||||||
|
SubType = subType;
|
||||||
|
AssociatedValue = associatedValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
|
||||||
|
public class KnownSubTypeWithPropertyAttribute : Attribute
|
||||||
|
{
|
||||||
|
public Type SubType { get; private set; }
|
||||||
|
public string PropertyName { get; private set; }
|
||||||
|
|
||||||
|
public KnownSubTypeWithPropertyAttribute(Type subType, string propertyName)
|
||||||
|
{
|
||||||
|
SubType = subType;
|
||||||
|
PropertyName = propertyName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _typeMappingPropertyName;
|
||||||
|
|
||||||
|
private bool _isInsideRead;
|
||||||
|
private JsonReader _reader;
|
||||||
|
|
||||||
|
public override bool CanRead
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!_isInsideRead)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return !string.IsNullOrEmpty(_reader.Path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed override bool CanWrite
|
||||||
|
{
|
||||||
|
get { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonSubtypes()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonSubtypes(string typeMappingPropertyName)
|
||||||
|
{
|
||||||
|
_typeMappingPropertyName = typeMappingPropertyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanConvert(Type objectType)
|
||||||
|
{
|
||||||
|
return _typeMappingPropertyName != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
if (reader.TokenType == JsonToken.Comment)
|
||||||
|
reader.Read();
|
||||||
|
|
||||||
|
switch (reader.TokenType)
|
||||||
|
{
|
||||||
|
case JsonToken.Null:
|
||||||
|
return null;
|
||||||
|
case JsonToken.StartArray:
|
||||||
|
return ReadArray(reader, objectType, serializer);
|
||||||
|
case JsonToken.StartObject:
|
||||||
|
return ReadObject(reader, objectType, serializer);
|
||||||
|
default:
|
||||||
|
throw new Exception("Array: Unrecognized token: " + reader.TokenType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IList ReadArray(JsonReader reader, Type targetType, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
var elementType = GetElementType(targetType);
|
||||||
|
|
||||||
|
var list = CreateCompatibleList(targetType, elementType);
|
||||||
|
|
||||||
|
while (reader.TokenType != JsonToken.EndArray && reader.Read())
|
||||||
|
{
|
||||||
|
switch (reader.TokenType)
|
||||||
|
{
|
||||||
|
case JsonToken.Null:
|
||||||
|
list.Add(reader.Value);
|
||||||
|
break;
|
||||||
|
case JsonToken.Comment:
|
||||||
|
break;
|
||||||
|
case JsonToken.StartObject:
|
||||||
|
list.Add(ReadObject(reader, elementType, serializer));
|
||||||
|
break;
|
||||||
|
case JsonToken.EndArray:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("Array: Unrecognized token: " + reader.TokenType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (targetType.IsArray)
|
||||||
|
{
|
||||||
|
var array = Array.CreateInstance(targetType.GetElementType(), list.Count);
|
||||||
|
list.CopyTo(array, 0);
|
||||||
|
list = array;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IList CreateCompatibleList(Type targetContainerType, Type elementType)
|
||||||
|
{
|
||||||
|
IList list;
|
||||||
|
if (targetContainerType.IsArray || targetContainerType.GetTypeInfo().IsAbstract)
|
||||||
|
{
|
||||||
|
list = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list = (IList)Activator.CreateInstance(targetContainerType);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetElementType(Type arrayOrGenericContainer)
|
||||||
|
{
|
||||||
|
Type elementType;
|
||||||
|
if (arrayOrGenericContainer.IsArray)
|
||||||
|
{
|
||||||
|
elementType = arrayOrGenericContainer.GetElementType();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
elementType = arrayOrGenericContainer.GenericTypeArguments[0];
|
||||||
|
}
|
||||||
|
return elementType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private object ReadObject(JsonReader reader, Type objectType, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
var jObject = JObject.Load(reader);
|
||||||
|
|
||||||
|
var targetType = GetType(jObject, objectType) ?? objectType;
|
||||||
|
|
||||||
|
return _ReadJson(CreateAnotherReader(jObject, reader), targetType, null, serializer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonReader CreateAnotherReader(JObject jObject, JsonReader reader)
|
||||||
|
{
|
||||||
|
var jObjectReader = jObject.CreateReader();
|
||||||
|
jObjectReader.Culture = reader.Culture;
|
||||||
|
jObjectReader.CloseInput = reader.CloseInput;
|
||||||
|
jObjectReader.SupportMultipleContent = reader.SupportMultipleContent;
|
||||||
|
jObjectReader.DateTimeZoneHandling = reader.DateTimeZoneHandling;
|
||||||
|
jObjectReader.FloatParseHandling = reader.FloatParseHandling;
|
||||||
|
jObjectReader.DateFormatString = reader.DateFormatString;
|
||||||
|
jObjectReader.DateParseHandling = reader.DateParseHandling;
|
||||||
|
return jObjectReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type GetType(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
if (_typeMappingPropertyName == null)
|
||||||
|
{
|
||||||
|
return GetTypeByPropertyPresence(jObject, parentType);
|
||||||
|
}
|
||||||
|
return GetTypeFromDiscriminatorValue(jObject, parentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeByPropertyPresence(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
foreach (var type in parentType.GetTypeInfo().GetCustomAttributes<KnownSubTypeWithPropertyAttribute>())
|
||||||
|
{
|
||||||
|
JToken ignore;
|
||||||
|
if (jObject.TryGetValue(type.PropertyName, out ignore))
|
||||||
|
{
|
||||||
|
return type.SubType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Type GetTypeFromDiscriminatorValue(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
JToken jToken;
|
||||||
|
if (!jObject.TryGetValue(_typeMappingPropertyName, out jToken)) return null;
|
||||||
|
|
||||||
|
var discriminatorValue = jToken.ToObject<object>();
|
||||||
|
if (discriminatorValue == null) return null;
|
||||||
|
|
||||||
|
var typeMapping = GetSubTypeMapping(parentType);
|
||||||
|
if (typeMapping.Any())
|
||||||
|
{
|
||||||
|
return GetTypeFromMapping(typeMapping, discriminatorValue);
|
||||||
|
}
|
||||||
|
return GetTypeByName(discriminatorValue as string, parentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeByName(string typeName, Type parentType)
|
||||||
|
{
|
||||||
|
if (typeName == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var insideAssembly = parentType.GetTypeInfo().Assembly;
|
||||||
|
|
||||||
|
var typeByName = insideAssembly.GetType(typeName);
|
||||||
|
if (typeByName == null)
|
||||||
|
{
|
||||||
|
var searchLocation = parentType.FullName.Substring(0, parentType.FullName.Length - parentType.Name.Length);
|
||||||
|
typeByName = insideAssembly.GetType(searchLocation + typeName, false, true);
|
||||||
|
}
|
||||||
|
return typeByName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeFromMapping(IReadOnlyDictionary<object, Type> typeMapping, object discriminatorValue)
|
||||||
|
{
|
||||||
|
var targetlookupValueType = typeMapping.First().Key.GetType();
|
||||||
|
var lookupValue = ConvertJsonValueToType(discriminatorValue, targetlookupValueType);
|
||||||
|
|
||||||
|
Type targetType;
|
||||||
|
return typeMapping.TryGetValue(lookupValue, out targetType) ? targetType : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Dictionary<object, Type> GetSubTypeMapping(Type type)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().GetCustomAttributes<KnownSubTypeAttribute>().ToDictionary(x => x.AssociatedValue, x => x.SubType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static object ConvertJsonValueToType(object objectType, Type targetlookupValueType)
|
||||||
|
{
|
||||||
|
if (targetlookupValueType.GetTypeInfo().IsEnum)
|
||||||
|
return Enum.ToObject(targetlookupValueType, objectType);
|
||||||
|
|
||||||
|
return Convert.ChangeType(objectType, targetlookupValueType);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected object _ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
_reader = reader;
|
||||||
|
_isInsideRead = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return serializer.Deserialize(reader, objectType);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isInsideRead = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -97,13 +97,13 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.MapProperty == input.MapProperty ||
|
this.MapProperty == input.MapProperty ||
|
||||||
(this.MapProperty != null &&
|
this.MapProperty != null &&
|
||||||
this.MapProperty.SequenceEqual(input.MapProperty))
|
this.MapProperty.SequenceEqual(input.MapProperty)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.MapOfMapProperty == input.MapOfMapProperty ||
|
this.MapOfMapProperty == input.MapOfMapProperty ||
|
||||||
(this.MapOfMapProperty != null &&
|
this.MapOfMapProperty != null &&
|
||||||
this.MapOfMapProperty.SequenceEqual(input.MapOfMapProperty))
|
this.MapOfMapProperty.SequenceEqual(input.MapOfMapProperty)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
using JsonSubTypes;
|
||||||
using SwaggerDateConverter = IO.Swagger.Client.SwaggerDateConverter;
|
using SwaggerDateConverter = IO.Swagger.Client.SwaggerDateConverter;
|
||||||
|
|
||||||
namespace IO.Swagger.Model
|
namespace IO.Swagger.Model
|
||||||
@ -26,6 +27,9 @@ namespace IO.Swagger.Model
|
|||||||
/// Animal
|
/// Animal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataContract]
|
[DataContract]
|
||||||
|
[JsonConverter(typeof(JsonSubtypes), "className")]
|
||||||
|
[JsonSubtypes.KnownSubType(typeof(Dog), "Dog")]
|
||||||
|
[JsonSubtypes.KnownSubType(typeof(Cat), "Cat")]
|
||||||
public partial class Animal : IEquatable<Animal>
|
public partial class Animal : IEquatable<Animal>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -90,7 +94,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public string ToJson()
|
public virtual string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Initializes a new instance of the <see cref="AnimalFarm" /> class.
|
/// Initializes a new instance of the <see cref="AnimalFarm" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonConstructorAttribute]
|
[JsonConstructorAttribute]
|
||||||
public AnimalFarm()
|
public AnimalFarm() : base()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +44,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class AnimalFarm {\n");
|
sb.Append("class AnimalFarm {\n");
|
||||||
|
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
|
||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
@ -52,7 +53,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public new string ToJson()
|
public string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -77,7 +78,7 @@ namespace IO.Swagger.Model
|
|||||||
if (input == null)
|
if (input == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return false;
|
return base.Equals(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -88,7 +89,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
unchecked // Overflow is fine, just wrap
|
unchecked // Overflow is fine, just wrap
|
||||||
{
|
{
|
||||||
int hashCode = 41;
|
int hashCode = base.GetHashCode();
|
||||||
return hashCode;
|
return hashCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,8 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.ArrayArrayNumber == input.ArrayArrayNumber ||
|
this.ArrayArrayNumber == input.ArrayArrayNumber ||
|
||||||
(this.ArrayArrayNumber != null &&
|
this.ArrayArrayNumber != null &&
|
||||||
this.ArrayArrayNumber.SequenceEqual(input.ArrayArrayNumber))
|
this.ArrayArrayNumber.SequenceEqual(input.ArrayArrayNumber)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,8 +88,8 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.ArrayNumber == input.ArrayNumber ||
|
this.ArrayNumber == input.ArrayNumber ||
|
||||||
(this.ArrayNumber != null &&
|
this.ArrayNumber != null &&
|
||||||
this.ArrayNumber.SequenceEqual(input.ArrayNumber))
|
this.ArrayNumber.SequenceEqual(input.ArrayNumber)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,18 +106,18 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.ArrayOfString == input.ArrayOfString ||
|
this.ArrayOfString == input.ArrayOfString ||
|
||||||
(this.ArrayOfString != null &&
|
this.ArrayOfString != null &&
|
||||||
this.ArrayOfString.SequenceEqual(input.ArrayOfString))
|
this.ArrayOfString.SequenceEqual(input.ArrayOfString)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.ArrayArrayOfInteger == input.ArrayArrayOfInteger ||
|
this.ArrayArrayOfInteger == input.ArrayArrayOfInteger ||
|
||||||
(this.ArrayArrayOfInteger != null &&
|
this.ArrayArrayOfInteger != null &&
|
||||||
this.ArrayArrayOfInteger.SequenceEqual(input.ArrayArrayOfInteger))
|
this.ArrayArrayOfInteger.SequenceEqual(input.ArrayArrayOfInteger)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.ArrayArrayOfModel == input.ArrayArrayOfModel ||
|
this.ArrayArrayOfModel == input.ArrayArrayOfModel ||
|
||||||
(this.ArrayArrayOfModel != null &&
|
this.ArrayArrayOfModel != null &&
|
||||||
this.ArrayArrayOfModel.SequenceEqual(input.ArrayArrayOfModel))
|
this.ArrayArrayOfModel.SequenceEqual(input.ArrayArrayOfModel)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,44 +36,12 @@ namespace IO.Swagger.Model
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Cat" /> class.
|
/// Initializes a new instance of the <see cref="Cat" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ClassName">ClassName (required).</param>
|
|
||||||
/// <param name="Color">Color (default to "red").</param>
|
|
||||||
/// <param name="Declawed">Declawed.</param>
|
/// <param name="Declawed">Declawed.</param>
|
||||||
public Cat(string ClassName = default(string), string Color = "red", bool? Declawed = default(bool?))
|
public Cat(bool? Declawed = default(bool?), string ClassName = "Cat", string Color = "red") : base(ClassName, Color)
|
||||||
{
|
{
|
||||||
// to ensure "ClassName" is required (not null)
|
|
||||||
if (ClassName == null)
|
|
||||||
{
|
|
||||||
throw new InvalidDataException("ClassName is a required property for Cat and cannot be null");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.ClassName = ClassName;
|
|
||||||
}
|
|
||||||
// use default value if no "Color" provided
|
|
||||||
if (Color == null)
|
|
||||||
{
|
|
||||||
this.Color = "red";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Color = Color;
|
|
||||||
}
|
|
||||||
this.Declawed = Declawed;
|
this.Declawed = Declawed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets ClassName
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="className", EmitDefaultValue=false)]
|
|
||||||
public string ClassName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets Color
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="color", EmitDefaultValue=false)]
|
|
||||||
public string Color { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Declawed
|
/// Gets or Sets Declawed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -88,8 +56,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class Cat {\n");
|
sb.Append("class Cat {\n");
|
||||||
sb.Append(" ClassName: ").Append(ClassName).Append("\n");
|
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
|
||||||
sb.Append(" Color: ").Append(Color).Append("\n");
|
|
||||||
sb.Append(" Declawed: ").Append(Declawed).Append("\n");
|
sb.Append(" Declawed: ").Append(Declawed).Append("\n");
|
||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
@ -99,7 +66,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public new string ToJson()
|
public override string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -124,17 +91,7 @@ namespace IO.Swagger.Model
|
|||||||
if (input == null)
|
if (input == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return
|
return base.Equals(input) &&
|
||||||
(
|
|
||||||
this.ClassName == input.ClassName ||
|
|
||||||
(this.ClassName != null &&
|
|
||||||
this.ClassName.Equals(input.ClassName))
|
|
||||||
) &&
|
|
||||||
(
|
|
||||||
this.Color == input.Color ||
|
|
||||||
(this.Color != null &&
|
|
||||||
this.Color.Equals(input.Color))
|
|
||||||
) &&
|
|
||||||
(
|
(
|
||||||
this.Declawed == input.Declawed ||
|
this.Declawed == input.Declawed ||
|
||||||
(this.Declawed != null &&
|
(this.Declawed != null &&
|
||||||
@ -150,11 +107,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
unchecked // Overflow is fine, just wrap
|
unchecked // Overflow is fine, just wrap
|
||||||
{
|
{
|
||||||
int hashCode = 41;
|
int hashCode = base.GetHashCode();
|
||||||
if (this.ClassName != null)
|
|
||||||
hashCode = hashCode * 59 + this.ClassName.GetHashCode();
|
|
||||||
if (this.Color != null)
|
|
||||||
hashCode = hashCode * 59 + this.Color.GetHashCode();
|
|
||||||
if (this.Declawed != null)
|
if (this.Declawed != null)
|
||||||
hashCode = hashCode * 59 + this.Declawed.GetHashCode();
|
hashCode = hashCode * 59 + this.Declawed.GetHashCode();
|
||||||
return hashCode;
|
return hashCode;
|
||||||
|
@ -36,44 +36,12 @@ namespace IO.Swagger.Model
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Dog" /> class.
|
/// Initializes a new instance of the <see cref="Dog" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ClassName">ClassName (required).</param>
|
|
||||||
/// <param name="Color">Color (default to "red").</param>
|
|
||||||
/// <param name="Breed">Breed.</param>
|
/// <param name="Breed">Breed.</param>
|
||||||
public Dog(string ClassName = default(string), string Color = "red", string Breed = default(string))
|
public Dog(string Breed = default(string), string ClassName = "Dog", string Color = "red") : base(ClassName, Color)
|
||||||
{
|
{
|
||||||
// to ensure "ClassName" is required (not null)
|
|
||||||
if (ClassName == null)
|
|
||||||
{
|
|
||||||
throw new InvalidDataException("ClassName is a required property for Dog and cannot be null");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.ClassName = ClassName;
|
|
||||||
}
|
|
||||||
// use default value if no "Color" provided
|
|
||||||
if (Color == null)
|
|
||||||
{
|
|
||||||
this.Color = "red";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Color = Color;
|
|
||||||
}
|
|
||||||
this.Breed = Breed;
|
this.Breed = Breed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets ClassName
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="className", EmitDefaultValue=false)]
|
|
||||||
public string ClassName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets Color
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="color", EmitDefaultValue=false)]
|
|
||||||
public string Color { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Breed
|
/// Gets or Sets Breed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -88,8 +56,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class Dog {\n");
|
sb.Append("class Dog {\n");
|
||||||
sb.Append(" ClassName: ").Append(ClassName).Append("\n");
|
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
|
||||||
sb.Append(" Color: ").Append(Color).Append("\n");
|
|
||||||
sb.Append(" Breed: ").Append(Breed).Append("\n");
|
sb.Append(" Breed: ").Append(Breed).Append("\n");
|
||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
@ -99,7 +66,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public new string ToJson()
|
public override string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -124,17 +91,7 @@ namespace IO.Swagger.Model
|
|||||||
if (input == null)
|
if (input == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return
|
return base.Equals(input) &&
|
||||||
(
|
|
||||||
this.ClassName == input.ClassName ||
|
|
||||||
(this.ClassName != null &&
|
|
||||||
this.ClassName.Equals(input.ClassName))
|
|
||||||
) &&
|
|
||||||
(
|
|
||||||
this.Color == input.Color ||
|
|
||||||
(this.Color != null &&
|
|
||||||
this.Color.Equals(input.Color))
|
|
||||||
) &&
|
|
||||||
(
|
(
|
||||||
this.Breed == input.Breed ||
|
this.Breed == input.Breed ||
|
||||||
(this.Breed != null &&
|
(this.Breed != null &&
|
||||||
@ -150,11 +107,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
unchecked // Overflow is fine, just wrap
|
unchecked // Overflow is fine, just wrap
|
||||||
{
|
{
|
||||||
int hashCode = 41;
|
int hashCode = base.GetHashCode();
|
||||||
if (this.ClassName != null)
|
|
||||||
hashCode = hashCode * 59 + this.ClassName.GetHashCode();
|
|
||||||
if (this.Color != null)
|
|
||||||
hashCode = hashCode * 59 + this.Color.GetHashCode();
|
|
||||||
if (this.Breed != null)
|
if (this.Breed != null)
|
||||||
hashCode = hashCode * 59 + this.Breed.GetHashCode();
|
hashCode = hashCode * 59 + this.Breed.GetHashCode();
|
||||||
return hashCode;
|
return hashCode;
|
||||||
|
@ -143,8 +143,8 @@ namespace IO.Swagger.Model
|
|||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.ArrayEnum == input.ArrayEnum ||
|
this.ArrayEnum == input.ArrayEnum ||
|
||||||
(this.ArrayEnum != null &&
|
this.ArrayEnum != null &&
|
||||||
this.ArrayEnum.SequenceEqual(input.ArrayEnum))
|
this.ArrayEnum.SequenceEqual(input.ArrayEnum)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,13 +118,13 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.MapMapOfString == input.MapMapOfString ||
|
this.MapMapOfString == input.MapMapOfString ||
|
||||||
(this.MapMapOfString != null &&
|
this.MapMapOfString != null &&
|
||||||
this.MapMapOfString.SequenceEqual(input.MapMapOfString))
|
this.MapMapOfString.SequenceEqual(input.MapMapOfString)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.MapOfEnumString == input.MapOfEnumString ||
|
this.MapOfEnumString == input.MapOfEnumString ||
|
||||||
(this.MapOfEnumString != null &&
|
this.MapOfEnumString != null &&
|
||||||
this.MapOfEnumString.SequenceEqual(input.MapOfEnumString))
|
this.MapOfEnumString.SequenceEqual(input.MapOfEnumString)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,8 +116,8 @@ namespace IO.Swagger.Model
|
|||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.Map == input.Map ||
|
this.Map == input.Map ||
|
||||||
(this.Map != null &&
|
this.Map != null &&
|
||||||
this.Map.SequenceEqual(input.Map))
|
this.Map.SequenceEqual(input.Map)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,13 +197,13 @@ namespace IO.Swagger.Model
|
|||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.PhotoUrls == input.PhotoUrls ||
|
this.PhotoUrls == input.PhotoUrls ||
|
||||||
(this.PhotoUrls != null &&
|
this.PhotoUrls != null &&
|
||||||
this.PhotoUrls.SequenceEqual(input.PhotoUrls))
|
this.PhotoUrls.SequenceEqual(input.PhotoUrls)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.Tags == input.Tags ||
|
this.Tags == input.Tags ||
|
||||||
(this.Tags != null &&
|
this.Tags != null &&
|
||||||
this.Tags.SequenceEqual(input.Tags))
|
this.Tags.SequenceEqual(input.Tags)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.Status == input.Status ||
|
this.Status == input.Status ||
|
||||||
|
@ -7,21 +7,21 @@ EndProject
|
|||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger.Test", "src\IO.Swagger.Test\IO.Swagger.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger.Test", "src\IO.Swagger.Test\IO.Swagger.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{5CD900DE-8266-412F-A758-28E1F9C623D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{5CD900DE-8266-412F-A758-28E1F9C623D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{5CD900DE-8266-412F-A758-28E1F9C623D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{5CD900DE-8266-412F-A758-28E1F9C623D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{5CD900DE-8266-412F-A758-28E1F9C623D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{5CD900DE-8266-412F-A758-28E1F9C623D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{5CD900DE-8266-412F-A758-28E1F9C623D5}.Release|Any CPU.Build.0 = Release|Any CPU
|
{5CD900DE-8266-412F-A758-28E1F9C623D5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.Build.0 = Release|Any CPU
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
@ -31,6 +31,7 @@ using IO.Swagger.Api;
|
|||||||
using IO.Swagger.Model;
|
using IO.Swagger.Model;
|
||||||
using IO.Swagger.Client;
|
using IO.Swagger.Client;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace IO.Swagger.Test
|
namespace IO.Swagger.Test
|
||||||
{
|
{
|
||||||
@ -76,6 +77,25 @@ namespace IO.Swagger.Test
|
|||||||
//Assert.IsInstanceOfType<Animal> (instance, "variable 'instance' is a Animal");
|
//Assert.IsInstanceOfType<Animal> (instance, "variable 'instance' is a Animal");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test deserialize a Dog from type Animal
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void DogDeserializeFromAnimalTest()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to test deserialize a Dog from type Animal
|
||||||
|
//Assert.IsInstanceOf<Animal>(JsonConvert.DeserializeObject<Animal>(new Dog().ToJson()));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Test deserialize a Cat from type Animal
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void CatDeserializeFromAnimalTest()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to test deserialize a Cat from type Animal
|
||||||
|
//Assert.IsInstanceOf<Animal>(JsonConvert.DeserializeObject<Animal>(new Cat().ToJson()));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test the property 'ClassName'
|
/// Test the property 'ClassName'
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -0,0 +1,272 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace JsonSubTypes
|
||||||
|
{
|
||||||
|
// Copied from project https://github.com/manuc66/JsonSubTypes
|
||||||
|
// https://raw.githubusercontent.com/manuc66/JsonSubTypes/07403192ea3f4959f6d42f5966ac56ceb0d6095b/JsonSubTypes/JsonSubtypes.cs
|
||||||
|
|
||||||
|
public class JsonSubtypes : JsonConverter
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
|
||||||
|
public class KnownSubTypeAttribute : Attribute
|
||||||
|
{
|
||||||
|
public Type SubType { get; private set; }
|
||||||
|
public object AssociatedValue { get; private set; }
|
||||||
|
|
||||||
|
public KnownSubTypeAttribute(Type subType, object associatedValue)
|
||||||
|
{
|
||||||
|
SubType = subType;
|
||||||
|
AssociatedValue = associatedValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
|
||||||
|
public class KnownSubTypeWithPropertyAttribute : Attribute
|
||||||
|
{
|
||||||
|
public Type SubType { get; private set; }
|
||||||
|
public string PropertyName { get; private set; }
|
||||||
|
|
||||||
|
public KnownSubTypeWithPropertyAttribute(Type subType, string propertyName)
|
||||||
|
{
|
||||||
|
SubType = subType;
|
||||||
|
PropertyName = propertyName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _typeMappingPropertyName;
|
||||||
|
|
||||||
|
private bool _isInsideRead;
|
||||||
|
private JsonReader _reader;
|
||||||
|
|
||||||
|
public override bool CanRead
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!_isInsideRead)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return !string.IsNullOrEmpty(_reader.Path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed override bool CanWrite
|
||||||
|
{
|
||||||
|
get { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonSubtypes()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonSubtypes(string typeMappingPropertyName)
|
||||||
|
{
|
||||||
|
_typeMappingPropertyName = typeMappingPropertyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanConvert(Type objectType)
|
||||||
|
{
|
||||||
|
return _typeMappingPropertyName != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
if (reader.TokenType == JsonToken.Comment)
|
||||||
|
reader.Read();
|
||||||
|
|
||||||
|
switch (reader.TokenType)
|
||||||
|
{
|
||||||
|
case JsonToken.Null:
|
||||||
|
return null;
|
||||||
|
case JsonToken.StartArray:
|
||||||
|
return ReadArray(reader, objectType, serializer);
|
||||||
|
case JsonToken.StartObject:
|
||||||
|
return ReadObject(reader, objectType, serializer);
|
||||||
|
default:
|
||||||
|
throw new Exception("Array: Unrecognized token: " + reader.TokenType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IList ReadArray(JsonReader reader, Type targetType, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
var elementType = GetElementType(targetType);
|
||||||
|
|
||||||
|
var list = CreateCompatibleList(targetType, elementType);
|
||||||
|
|
||||||
|
while (reader.TokenType != JsonToken.EndArray && reader.Read())
|
||||||
|
{
|
||||||
|
switch (reader.TokenType)
|
||||||
|
{
|
||||||
|
case JsonToken.Null:
|
||||||
|
list.Add(reader.Value);
|
||||||
|
break;
|
||||||
|
case JsonToken.Comment:
|
||||||
|
break;
|
||||||
|
case JsonToken.StartObject:
|
||||||
|
list.Add(ReadObject(reader, elementType, serializer));
|
||||||
|
break;
|
||||||
|
case JsonToken.EndArray:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("Array: Unrecognized token: " + reader.TokenType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (targetType.IsArray)
|
||||||
|
{
|
||||||
|
var array = Array.CreateInstance(targetType.GetElementType(), list.Count);
|
||||||
|
list.CopyTo(array, 0);
|
||||||
|
list = array;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IList CreateCompatibleList(Type targetContainerType, Type elementType)
|
||||||
|
{
|
||||||
|
IList list;
|
||||||
|
if (targetContainerType.IsArray || targetContainerType.GetTypeInfo().IsAbstract)
|
||||||
|
{
|
||||||
|
list = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list = (IList)Activator.CreateInstance(targetContainerType);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetElementType(Type arrayOrGenericContainer)
|
||||||
|
{
|
||||||
|
Type elementType;
|
||||||
|
if (arrayOrGenericContainer.IsArray)
|
||||||
|
{
|
||||||
|
elementType = arrayOrGenericContainer.GetElementType();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
elementType = arrayOrGenericContainer.GenericTypeArguments[0];
|
||||||
|
}
|
||||||
|
return elementType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private object ReadObject(JsonReader reader, Type objectType, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
var jObject = JObject.Load(reader);
|
||||||
|
|
||||||
|
var targetType = GetType(jObject, objectType) ?? objectType;
|
||||||
|
|
||||||
|
return _ReadJson(CreateAnotherReader(jObject, reader), targetType, null, serializer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonReader CreateAnotherReader(JObject jObject, JsonReader reader)
|
||||||
|
{
|
||||||
|
var jObjectReader = jObject.CreateReader();
|
||||||
|
jObjectReader.Culture = reader.Culture;
|
||||||
|
jObjectReader.CloseInput = reader.CloseInput;
|
||||||
|
jObjectReader.SupportMultipleContent = reader.SupportMultipleContent;
|
||||||
|
jObjectReader.DateTimeZoneHandling = reader.DateTimeZoneHandling;
|
||||||
|
jObjectReader.FloatParseHandling = reader.FloatParseHandling;
|
||||||
|
jObjectReader.DateFormatString = reader.DateFormatString;
|
||||||
|
jObjectReader.DateParseHandling = reader.DateParseHandling;
|
||||||
|
return jObjectReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type GetType(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
if (_typeMappingPropertyName == null)
|
||||||
|
{
|
||||||
|
return GetTypeByPropertyPresence(jObject, parentType);
|
||||||
|
}
|
||||||
|
return GetTypeFromDiscriminatorValue(jObject, parentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeByPropertyPresence(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
foreach (var type in parentType.GetTypeInfo().GetCustomAttributes<KnownSubTypeWithPropertyAttribute>())
|
||||||
|
{
|
||||||
|
JToken ignore;
|
||||||
|
if (jObject.TryGetValue(type.PropertyName, out ignore))
|
||||||
|
{
|
||||||
|
return type.SubType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Type GetTypeFromDiscriminatorValue(JObject jObject, Type parentType)
|
||||||
|
{
|
||||||
|
JToken jToken;
|
||||||
|
if (!jObject.TryGetValue(_typeMappingPropertyName, out jToken)) return null;
|
||||||
|
|
||||||
|
var discriminatorValue = jToken.ToObject<object>();
|
||||||
|
if (discriminatorValue == null) return null;
|
||||||
|
|
||||||
|
var typeMapping = GetSubTypeMapping(parentType);
|
||||||
|
if (typeMapping.Any())
|
||||||
|
{
|
||||||
|
return GetTypeFromMapping(typeMapping, discriminatorValue);
|
||||||
|
}
|
||||||
|
return GetTypeByName(discriminatorValue as string, parentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeByName(string typeName, Type parentType)
|
||||||
|
{
|
||||||
|
if (typeName == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var insideAssembly = parentType.GetTypeInfo().Assembly;
|
||||||
|
|
||||||
|
var typeByName = insideAssembly.GetType(typeName);
|
||||||
|
if (typeByName == null)
|
||||||
|
{
|
||||||
|
var searchLocation = parentType.FullName.Substring(0, parentType.FullName.Length - parentType.Name.Length);
|
||||||
|
typeByName = insideAssembly.GetType(searchLocation + typeName, false, true);
|
||||||
|
}
|
||||||
|
return typeByName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type GetTypeFromMapping(IReadOnlyDictionary<object, Type> typeMapping, object discriminatorValue)
|
||||||
|
{
|
||||||
|
var targetlookupValueType = typeMapping.First().Key.GetType();
|
||||||
|
var lookupValue = ConvertJsonValueToType(discriminatorValue, targetlookupValueType);
|
||||||
|
|
||||||
|
Type targetType;
|
||||||
|
return typeMapping.TryGetValue(lookupValue, out targetType) ? targetType : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Dictionary<object, Type> GetSubTypeMapping(Type type)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().GetCustomAttributes<KnownSubTypeAttribute>().ToDictionary(x => x.AssociatedValue, x => x.SubType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static object ConvertJsonValueToType(object objectType, Type targetlookupValueType)
|
||||||
|
{
|
||||||
|
if (targetlookupValueType.GetTypeInfo().IsEnum)
|
||||||
|
return Enum.ToObject(targetlookupValueType, objectType);
|
||||||
|
|
||||||
|
return Convert.ChangeType(objectType, targetlookupValueType);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected object _ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
_reader = reader;
|
||||||
|
_isInsideRead = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return serializer.Deserialize(reader, objectType);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isInsideRead = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -102,13 +102,13 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.MapProperty == input.MapProperty ||
|
this.MapProperty == input.MapProperty ||
|
||||||
(this.MapProperty != null &&
|
this.MapProperty != null &&
|
||||||
this.MapProperty.SequenceEqual(input.MapProperty))
|
this.MapProperty.SequenceEqual(input.MapProperty)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.MapOfMapProperty == input.MapOfMapProperty ||
|
this.MapOfMapProperty == input.MapOfMapProperty ||
|
||||||
(this.MapOfMapProperty != null &&
|
this.MapOfMapProperty != null &&
|
||||||
this.MapOfMapProperty.SequenceEqual(input.MapOfMapProperty))
|
this.MapOfMapProperty.SequenceEqual(input.MapOfMapProperty)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
using JsonSubTypes;
|
||||||
using PropertyChanged;
|
using PropertyChanged;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
@ -30,6 +31,9 @@ namespace IO.Swagger.Model
|
|||||||
/// Animal
|
/// Animal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataContract]
|
[DataContract]
|
||||||
|
[JsonConverter(typeof(JsonSubtypes), "className")]
|
||||||
|
[JsonSubtypes.KnownSubType(typeof(Dog), "Dog")]
|
||||||
|
[JsonSubtypes.KnownSubType(typeof(Cat), "Cat")]
|
||||||
[ImplementPropertyChanged]
|
[ImplementPropertyChanged]
|
||||||
public partial class Animal : IEquatable<Animal>, IValidatableObject
|
public partial class Animal : IEquatable<Animal>, IValidatableObject
|
||||||
{
|
{
|
||||||
@ -95,7 +99,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public string ToJson()
|
public virtual string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -176,6 +180,16 @@ namespace IO.Swagger.Model
|
|||||||
/// <param name="validationContext">Validation context</param>
|
/// <param name="validationContext">Validation context</param>
|
||||||
/// <returns>Validation Result</returns>
|
/// <returns>Validation Result</returns>
|
||||||
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
||||||
|
{
|
||||||
|
return this.BaseValidate(validationContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// To validate all properties of the instance
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext">Validation context</param>
|
||||||
|
/// <returns>Validation Result</returns>
|
||||||
|
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
|
||||||
{
|
{
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Initializes a new instance of the <see cref="AnimalFarm" /> class.
|
/// Initializes a new instance of the <see cref="AnimalFarm" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonConstructorAttribute]
|
[JsonConstructorAttribute]
|
||||||
public AnimalFarm()
|
public AnimalFarm() : base()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +49,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class AnimalFarm {\n");
|
sb.Append("class AnimalFarm {\n");
|
||||||
|
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
|
||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
@ -57,7 +58,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public new string ToJson()
|
public string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -82,7 +83,7 @@ namespace IO.Swagger.Model
|
|||||||
if (input == null)
|
if (input == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return false;
|
return base.Equals(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -93,7 +94,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
unchecked // Overflow is fine, just wrap
|
unchecked // Overflow is fine, just wrap
|
||||||
{
|
{
|
||||||
int hashCode = 41;
|
int hashCode = base.GetHashCode();
|
||||||
return hashCode;
|
return hashCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,8 +93,8 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.ArrayArrayNumber == input.ArrayArrayNumber ||
|
this.ArrayArrayNumber == input.ArrayArrayNumber ||
|
||||||
(this.ArrayArrayNumber != null &&
|
this.ArrayArrayNumber != null &&
|
||||||
this.ArrayArrayNumber.SequenceEqual(input.ArrayArrayNumber))
|
this.ArrayArrayNumber.SequenceEqual(input.ArrayArrayNumber)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,8 +93,8 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.ArrayNumber == input.ArrayNumber ||
|
this.ArrayNumber == input.ArrayNumber ||
|
||||||
(this.ArrayNumber != null &&
|
this.ArrayNumber != null &&
|
||||||
this.ArrayNumber.SequenceEqual(input.ArrayNumber))
|
this.ArrayNumber.SequenceEqual(input.ArrayNumber)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,18 +111,18 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.ArrayOfString == input.ArrayOfString ||
|
this.ArrayOfString == input.ArrayOfString ||
|
||||||
(this.ArrayOfString != null &&
|
this.ArrayOfString != null &&
|
||||||
this.ArrayOfString.SequenceEqual(input.ArrayOfString))
|
this.ArrayOfString.SequenceEqual(input.ArrayOfString)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.ArrayArrayOfInteger == input.ArrayArrayOfInteger ||
|
this.ArrayArrayOfInteger == input.ArrayArrayOfInteger ||
|
||||||
(this.ArrayArrayOfInteger != null &&
|
this.ArrayArrayOfInteger != null &&
|
||||||
this.ArrayArrayOfInteger.SequenceEqual(input.ArrayArrayOfInteger))
|
this.ArrayArrayOfInteger.SequenceEqual(input.ArrayArrayOfInteger)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.ArrayArrayOfModel == input.ArrayArrayOfModel ||
|
this.ArrayArrayOfModel == input.ArrayArrayOfModel ||
|
||||||
(this.ArrayArrayOfModel != null &&
|
this.ArrayArrayOfModel != null &&
|
||||||
this.ArrayArrayOfModel.SequenceEqual(input.ArrayArrayOfModel))
|
this.ArrayArrayOfModel.SequenceEqual(input.ArrayArrayOfModel)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,44 +41,12 @@ namespace IO.Swagger.Model
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Cat" /> class.
|
/// Initializes a new instance of the <see cref="Cat" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ClassName">ClassName (required).</param>
|
|
||||||
/// <param name="Color">Color (default to "red").</param>
|
|
||||||
/// <param name="Declawed">Declawed.</param>
|
/// <param name="Declawed">Declawed.</param>
|
||||||
public Cat(string ClassName = default(string), string Color = "red", bool? Declawed = default(bool?))
|
public Cat(bool? Declawed = default(bool?), string ClassName = "Cat", string Color = "red") : base(ClassName, Color)
|
||||||
{
|
{
|
||||||
// to ensure "ClassName" is required (not null)
|
|
||||||
if (ClassName == null)
|
|
||||||
{
|
|
||||||
throw new InvalidDataException("ClassName is a required property for Cat and cannot be null");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.ClassName = ClassName;
|
|
||||||
}
|
|
||||||
// use default value if no "Color" provided
|
|
||||||
if (Color == null)
|
|
||||||
{
|
|
||||||
this.Color = "red";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Color = Color;
|
|
||||||
}
|
|
||||||
this.Declawed = Declawed;
|
this.Declawed = Declawed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets ClassName
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="className", EmitDefaultValue=false)]
|
|
||||||
public string ClassName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets Color
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="color", EmitDefaultValue=false)]
|
|
||||||
public string Color { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Declawed
|
/// Gets or Sets Declawed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -93,8 +61,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class Cat {\n");
|
sb.Append("class Cat {\n");
|
||||||
sb.Append(" ClassName: ").Append(ClassName).Append("\n");
|
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
|
||||||
sb.Append(" Color: ").Append(Color).Append("\n");
|
|
||||||
sb.Append(" Declawed: ").Append(Declawed).Append("\n");
|
sb.Append(" Declawed: ").Append(Declawed).Append("\n");
|
||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
@ -104,7 +71,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public new string ToJson()
|
public override string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -129,17 +96,7 @@ namespace IO.Swagger.Model
|
|||||||
if (input == null)
|
if (input == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return
|
return base.Equals(input) &&
|
||||||
(
|
|
||||||
this.ClassName == input.ClassName ||
|
|
||||||
(this.ClassName != null &&
|
|
||||||
this.ClassName.Equals(input.ClassName))
|
|
||||||
) &&
|
|
||||||
(
|
|
||||||
this.Color == input.Color ||
|
|
||||||
(this.Color != null &&
|
|
||||||
this.Color.Equals(input.Color))
|
|
||||||
) &&
|
|
||||||
(
|
(
|
||||||
this.Declawed == input.Declawed ||
|
this.Declawed == input.Declawed ||
|
||||||
(this.Declawed != null &&
|
(this.Declawed != null &&
|
||||||
@ -155,11 +112,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
unchecked // Overflow is fine, just wrap
|
unchecked // Overflow is fine, just wrap
|
||||||
{
|
{
|
||||||
int hashCode = 41;
|
int hashCode = base.GetHashCode();
|
||||||
if (this.ClassName != null)
|
|
||||||
hashCode = hashCode * 59 + this.ClassName.GetHashCode();
|
|
||||||
if (this.Color != null)
|
|
||||||
hashCode = hashCode * 59 + this.Color.GetHashCode();
|
|
||||||
if (this.Declawed != null)
|
if (this.Declawed != null)
|
||||||
hashCode = hashCode * 59 + this.Declawed.GetHashCode();
|
hashCode = hashCode * 59 + this.Declawed.GetHashCode();
|
||||||
return hashCode;
|
return hashCode;
|
||||||
@ -193,6 +146,7 @@ namespace IO.Swagger.Model
|
|||||||
/// <returns>Validation Result</returns>
|
/// <returns>Validation Result</returns>
|
||||||
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
||||||
{
|
{
|
||||||
|
foreach(var x in BaseValidate(validationContext)) yield return x;
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,44 +41,12 @@ namespace IO.Swagger.Model
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Dog" /> class.
|
/// Initializes a new instance of the <see cref="Dog" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ClassName">ClassName (required).</param>
|
|
||||||
/// <param name="Color">Color (default to "red").</param>
|
|
||||||
/// <param name="Breed">Breed.</param>
|
/// <param name="Breed">Breed.</param>
|
||||||
public Dog(string ClassName = default(string), string Color = "red", string Breed = default(string))
|
public Dog(string Breed = default(string), string ClassName = "Dog", string Color = "red") : base(ClassName, Color)
|
||||||
{
|
{
|
||||||
// to ensure "ClassName" is required (not null)
|
|
||||||
if (ClassName == null)
|
|
||||||
{
|
|
||||||
throw new InvalidDataException("ClassName is a required property for Dog and cannot be null");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.ClassName = ClassName;
|
|
||||||
}
|
|
||||||
// use default value if no "Color" provided
|
|
||||||
if (Color == null)
|
|
||||||
{
|
|
||||||
this.Color = "red";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Color = Color;
|
|
||||||
}
|
|
||||||
this.Breed = Breed;
|
this.Breed = Breed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets ClassName
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="className", EmitDefaultValue=false)]
|
|
||||||
public string ClassName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or Sets Color
|
|
||||||
/// </summary>
|
|
||||||
[DataMember(Name="color", EmitDefaultValue=false)]
|
|
||||||
public string Color { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Breed
|
/// Gets or Sets Breed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -93,8 +61,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class Dog {\n");
|
sb.Append("class Dog {\n");
|
||||||
sb.Append(" ClassName: ").Append(ClassName).Append("\n");
|
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
|
||||||
sb.Append(" Color: ").Append(Color).Append("\n");
|
|
||||||
sb.Append(" Breed: ").Append(Breed).Append("\n");
|
sb.Append(" Breed: ").Append(Breed).Append("\n");
|
||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
@ -104,7 +71,7 @@ namespace IO.Swagger.Model
|
|||||||
/// Returns the JSON string presentation of the object
|
/// Returns the JSON string presentation of the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JSON string presentation of the object</returns>
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
public new string ToJson()
|
public override string ToJson()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
@ -129,17 +96,7 @@ namespace IO.Swagger.Model
|
|||||||
if (input == null)
|
if (input == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return
|
return base.Equals(input) &&
|
||||||
(
|
|
||||||
this.ClassName == input.ClassName ||
|
|
||||||
(this.ClassName != null &&
|
|
||||||
this.ClassName.Equals(input.ClassName))
|
|
||||||
) &&
|
|
||||||
(
|
|
||||||
this.Color == input.Color ||
|
|
||||||
(this.Color != null &&
|
|
||||||
this.Color.Equals(input.Color))
|
|
||||||
) &&
|
|
||||||
(
|
(
|
||||||
this.Breed == input.Breed ||
|
this.Breed == input.Breed ||
|
||||||
(this.Breed != null &&
|
(this.Breed != null &&
|
||||||
@ -155,11 +112,7 @@ namespace IO.Swagger.Model
|
|||||||
{
|
{
|
||||||
unchecked // Overflow is fine, just wrap
|
unchecked // Overflow is fine, just wrap
|
||||||
{
|
{
|
||||||
int hashCode = 41;
|
int hashCode = base.GetHashCode();
|
||||||
if (this.ClassName != null)
|
|
||||||
hashCode = hashCode * 59 + this.ClassName.GetHashCode();
|
|
||||||
if (this.Color != null)
|
|
||||||
hashCode = hashCode * 59 + this.Color.GetHashCode();
|
|
||||||
if (this.Breed != null)
|
if (this.Breed != null)
|
||||||
hashCode = hashCode * 59 + this.Breed.GetHashCode();
|
hashCode = hashCode * 59 + this.Breed.GetHashCode();
|
||||||
return hashCode;
|
return hashCode;
|
||||||
@ -193,6 +146,7 @@ namespace IO.Swagger.Model
|
|||||||
/// <returns>Validation Result</returns>
|
/// <returns>Validation Result</returns>
|
||||||
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
||||||
{
|
{
|
||||||
|
foreach(var x in BaseValidate(validationContext)) yield return x;
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,8 +148,8 @@ namespace IO.Swagger.Model
|
|||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.ArrayEnum == input.ArrayEnum ||
|
this.ArrayEnum == input.ArrayEnum ||
|
||||||
(this.ArrayEnum != null &&
|
this.ArrayEnum != null &&
|
||||||
this.ArrayEnum.SequenceEqual(input.ArrayEnum))
|
this.ArrayEnum.SequenceEqual(input.ArrayEnum)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,13 +123,13 @@ namespace IO.Swagger.Model
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
this.MapMapOfString == input.MapMapOfString ||
|
this.MapMapOfString == input.MapMapOfString ||
|
||||||
(this.MapMapOfString != null &&
|
this.MapMapOfString != null &&
|
||||||
this.MapMapOfString.SequenceEqual(input.MapMapOfString))
|
this.MapMapOfString.SequenceEqual(input.MapMapOfString)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.MapOfEnumString == input.MapOfEnumString ||
|
this.MapOfEnumString == input.MapOfEnumString ||
|
||||||
(this.MapOfEnumString != null &&
|
this.MapOfEnumString != null &&
|
||||||
this.MapOfEnumString.SequenceEqual(input.MapOfEnumString))
|
this.MapOfEnumString.SequenceEqual(input.MapOfEnumString)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,8 +121,8 @@ namespace IO.Swagger.Model
|
|||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.Map == input.Map ||
|
this.Map == input.Map ||
|
||||||
(this.Map != null &&
|
this.Map != null &&
|
||||||
this.Map.SequenceEqual(input.Map))
|
this.Map.SequenceEqual(input.Map)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,13 +202,13 @@ namespace IO.Swagger.Model
|
|||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.PhotoUrls == input.PhotoUrls ||
|
this.PhotoUrls == input.PhotoUrls ||
|
||||||
(this.PhotoUrls != null &&
|
this.PhotoUrls != null &&
|
||||||
this.PhotoUrls.SequenceEqual(input.PhotoUrls))
|
this.PhotoUrls.SequenceEqual(input.PhotoUrls)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.Tags == input.Tags ||
|
this.Tags == input.Tags ||
|
||||||
(this.Tags != null &&
|
this.Tags != null &&
|
||||||
this.Tags.SequenceEqual(input.Tags))
|
this.Tags.SequenceEqual(input.Tags)
|
||||||
) &&
|
) &&
|
||||||
(
|
(
|
||||||
this.Status == input.Status ||
|
this.Status == input.Status ||
|
||||||
|
Loading…
x
Reference in New Issue
Block a user