Merge branch 'cs/req_properties_2584' of https://github.com/jimschubert/swagger-codegen into jimschubert-cs/req_properties_2584

Conflicts:
	samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln
	samples/client/petstore/csharp/SwaggerClient/README.md
	samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger.Test/IO.Swagger.Test.csproj
	samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj
This commit is contained in:
wing328
2016-05-13 21:49:16 +08:00
14 changed files with 77 additions and 10 deletions

View File

@@ -27,7 +27,7 @@ public class CodegenModel {
public Set<String> allMandatory;
public Set<String> imports = new TreeSet<String>();
public Boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum;
public Boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, hasRequired;
public ExternalDocs externalDocs;
public Map<String, Object> vendorExtensions;

View File

@@ -2465,6 +2465,7 @@ public class DefaultCodegen {
private void addVars(CodegenModel m, Map<String, Property> properties, List<String> required,
Map<String, Property> allProperties, List<String> allRequired) {
m.hasRequired = false;
if (properties != null && !properties.isEmpty()) {
m.hasVars = true;
m.hasEnums = false;
@@ -2503,6 +2504,7 @@ public class DefaultCodegen {
} else {
final CodegenProperty cp = fromProperty(key, prop);
cp.required = mandatory.contains(key) ? true : null;
m.hasRequired = Boolean.TRUE.equals(m.hasRequired) || Boolean.TRUE.equals(cp.required);
if (cp.isEnum) {
// FIXME: if supporting inheritance, when called a second time for allProperties it is possible for
// m.hasEnums to be set incorrectly if allProperties has enumerations but properties does not.

View File

@@ -20,6 +20,11 @@ namespace {{packageName}}.Client
/// </summary>
public class ApiClient
{
private JsonSerializerSettings serializerSettings = new JsonSerializerSettings
{
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
};
/// <summary>
/// Initializes a new instance of the <see cref="ApiClient" /> class
/// with default configuration and base path ({{basePath}}).
@@ -305,7 +310,7 @@ namespace {{packageName}}.Client
// at this point, it must be a model (json)
try
{
return JsonConvert.DeserializeObject(response.Content, type);
return JsonConvert.DeserializeObject(response.Content, type, serializerSettings);
}
catch (Exception e)
{

View File

@@ -24,6 +24,13 @@
public {{{datatypeWithEnum}}}{{#isEnum}}?{{/isEnum}} {{name}} { get; set; }
{{/isEnum}}
{{/vars}}
{{#hasRequired}}
/// <summary>
/// Initializes a new instance of the <see cref="{{classname}}" /> class.
/// </summary>
[JsonConstructorAttribute]
protected {{classname}}() { }
{{/hasRequired}}
/// <summary>
/// Initializes a new instance of the <see cref="{{classname}}" /> class.
/// </summary>

View File

@@ -12,10 +12,17 @@ Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
<<<<<<< HEAD
{C075FB79-0DDE-43E3-9FA5-E239EE9B9B5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C075FB79-0DDE-43E3-9FA5-E239EE9B9B5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C075FB79-0DDE-43E3-9FA5-E239EE9B9B5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C075FB79-0DDE-43E3-9FA5-E239EE9B9B5A}.Release|Any CPU.Build.0 = Release|Any CPU
=======
{086EEE3F-4CAC-475B-A3D9-F0D944DC9D79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{086EEE3F-4CAC-475B-A3D9-F0D944DC9D79}.Debug|Any CPU.Build.0 = Debug|Any CPU
{086EEE3F-4CAC-475B-A3D9-F0D944DC9D79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{086EEE3F-4CAC-475B-A3D9-F0D944DC9D79}.Release|Any CPU.Build.0 = Release|Any CPU
>>>>>>> 705ed78de1c6d18255cdd5c32acec3d09470ff7b
{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}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -24,4 +31,4 @@ EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
EndGlobal

View File

@@ -134,12 +134,6 @@ Class | Method | HTTP request | Description
## Documentation for Authorization
### api_key
- **Type**: API key
- **API key parameter name**: api_key
- **Location**: HTTP header
### petstore_auth
- **Type**: OAuth
@@ -149,3 +143,9 @@ Class | Method | HTTP request | Description
- write:pets: modify pets in your account
- read:pets: read your pets
### api_key
- **Type**: API key
- **API key parameter name**: api_key
- **Location**: HTTP header

View File

@@ -18,6 +18,11 @@ namespace IO.Swagger.Client
/// </summary>
public class ApiClient
{
private JsonSerializerSettings serializerSettings = new JsonSerializerSettings
{
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
};
/// <summary>
/// Initializes a new instance of the <see cref="ApiClient" /> class
/// with default configuration and base path (http://petstore.swagger.io/v2).
@@ -289,7 +294,7 @@ namespace IO.Swagger.Client
// at this point, it must be a model (json)
try
{
return JsonConvert.DeserializeObject(response.Content, type);
return JsonConvert.DeserializeObject(response.Content, type, serializerSettings);
}
catch (Exception e)
{

View File

@@ -17,6 +17,11 @@ namespace IO.Swagger.Model
[DataContract]
public partial class Animal : IEquatable<Animal>
{
/// <summary>
/// Initializes a new instance of the <see cref="Animal" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Animal() { }
/// <summary>
/// Initializes a new instance of the <see cref="Animal" /> class.
/// </summary>

View File

@@ -17,6 +17,11 @@ namespace IO.Swagger.Model
[DataContract]
public partial class Cat : Animal, IEquatable<Cat>
{
/// <summary>
/// Initializes a new instance of the <see cref="Cat" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Cat() { }
/// <summary>
/// Initializes a new instance of the <see cref="Cat" /> class.
/// </summary>

View File

@@ -17,6 +17,11 @@ namespace IO.Swagger.Model
[DataContract]
public partial class Dog : Animal, IEquatable<Dog>
{
/// <summary>
/// Initializes a new instance of the <see cref="Dog" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Dog() { }
/// <summary>
/// Initializes a new instance of the <see cref="Dog" /> class.
/// </summary>

View File

@@ -17,6 +17,11 @@ namespace IO.Swagger.Model
[DataContract]
public partial class FormatTest : IEquatable<FormatTest>
{
/// <summary>
/// Initializes a new instance of the <see cref="FormatTest" /> class.
/// </summary>
[JsonConstructorAttribute]
protected FormatTest() { }
/// <summary>
/// Initializes a new instance of the <see cref="FormatTest" /> class.
/// </summary>

View File

@@ -17,6 +17,11 @@ namespace IO.Swagger.Model
[DataContract]
public partial class Name : IEquatable<Name>
{
/// <summary>
/// Initializes a new instance of the <see cref="Name" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Name() { }
/// <summary>
/// Initializes a new instance of the <see cref="Name" /> class.
/// </summary>

View File

@@ -53,6 +53,11 @@ namespace IO.Swagger.Model
/// <summary>
/// Initializes a new instance of the <see cref="Pet" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Pet() { }
/// <summary>
/// Initializes a new instance of the <see cref="Pet" /> class.
/// </summary>
/// <param name="Id">Id.</param>
/// <param name="Category">Category.</param>
/// <param name="Name">Name (required).</param>

View File

@@ -9,3 +9,14 @@
/Users/williamcheng/Code/swagger-api/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
/Users/williamcheng/Code/swagger-api/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Swagger Library.dll
/Users/williamcheng/Code/swagger-api/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Swagger Library.dll.mdb
/Volumes/Extra/projects/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
/Volumes/Extra/projects/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.swagger-logo.png
/Volumes/Extra/projects/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
/Volumes/Extra/projects/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
/Volumes/Extra/projects/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
/Volumes/Extra/projects/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
/Volumes/Extra/projects/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
/Volumes/Extra/projects/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
/Volumes/Extra/projects/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
/Volumes/Extra/projects/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Swagger Library.dll
/Volumes/Extra/projects/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Swagger Library.dll.mdb