Merge branch 'jimschubert-cs/req_properties_2584'

This commit is contained in:
wing328 2016-05-13 22:17:55 +08:00
commit 1939ce8e91
16 changed files with 62 additions and 13 deletions

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012 # Visual Studio 2012
VisualStudioVersion = 12.0.0.0 VisualStudioVersion = 12.0.0.0
MinimumVisualStudioVersion = 10.0.0.1 MinimumVisualStudioVersion = 10.0.0.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{C075FB79-0DDE-43E3-9FA5-E239EE9B9B5A}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{74456AF8-75EE-4ABC-97EB-CA96A472DD21}"
EndProject 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
@ -12,10 +12,10 @@ 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
{C075FB79-0DDE-43E3-9FA5-E239EE9B9B5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {74456AF8-75EE-4ABC-97EB-CA96A472DD21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C075FB79-0DDE-43E3-9FA5-E239EE9B9B5A}.Debug|Any CPU.Build.0 = Debug|Any CPU {74456AF8-75EE-4ABC-97EB-CA96A472DD21}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C075FB79-0DDE-43E3-9FA5-E239EE9B9B5A}.Release|Any CPU.ActiveCfg = Release|Any CPU {74456AF8-75EE-4ABC-97EB-CA96A472DD21}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C075FB79-0DDE-43E3-9FA5-E239EE9B9B5A}.Release|Any CPU.Build.0 = Release|Any CPU {74456AF8-75EE-4ABC-97EB-CA96A472DD21}.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

View File

@ -1,12 +1,12 @@
# IO.Swagger - the C# library for the Swagger Petstore # IO.Swagger - the C# library for the Swagger Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
This C# SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project: This C# SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
- API version: 1.0.0 - API version: 1.0.0
- SDK version: 1.0.0 - SDK version: 1.0.0
- Build date: 2016-05-10T17:39:13.582+08:00 - Build date: 2016-05-13T21:50:05.372+08:00
- Build package: class io.swagger.codegen.languages.CSharpClientCodegen - Build package: class io.swagger.codegen.languages.CSharpClientCodegen
## Frameworks supported ## Frameworks supported

View File

@ -65,7 +65,7 @@
<Import Project="$(MsBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MsBuildToolsPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\IO.Swagger\IO.Swagger.csproj"> <ProjectReference Include="..\IO.Swagger\IO.Swagger.csproj">
<Project>{C075FB79-0DDE-43E3-9FA5-E239EE9B9B5A}</Project> <Project>{74456AF8-75EE-4ABC-97EB-CA96A472DD21}</Project>
<Name>IO.Swagger</Name> <Name>IO.Swagger</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>

View File

@ -18,6 +18,11 @@ namespace IO.Swagger.Client
/// </summary> /// </summary>
public class ApiClient public class ApiClient
{ {
private JsonSerializerSettings serializerSettings = new JsonSerializerSettings
{
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
};
/// <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 (http://petstore.swagger.io/v2). /// 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) // at this point, it must be a model (json)
try try
{ {
return JsonConvert.DeserializeObject(response.Content, type); return JsonConvert.DeserializeObject(response.Content, type, serializerSettings);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C075FB79-0DDE-43E3-9FA5-E239EE9B9B5A}</ProjectGuid> <ProjectGuid>{74456AF8-75EE-4ABC-97EB-CA96A472DD21}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Swagger Library</RootNamespace> <RootNamespace>Swagger Library</RootNamespace>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@
<File FileName="TestPet.cs" Line="1" Column="1" /> <File FileName="TestPet.cs" Line="1" Column="1" />
<File FileName="TestOrder.cs" Line="1" Column="1" /> <File FileName="TestOrder.cs" Line="1" Column="1" />
<File FileName="../SwaggerClient/src/IO.Swagger/Api/FakeApi.cs" Line="1" Column="1" /> <File FileName="../SwaggerClient/src/IO.Swagger/Api/FakeApi.cs" Line="1" Column="1" />
<File FileName="../SwaggerClient/src/IO.Swagger/Model/ApiResponse.cs" Line="1" Column="1" /> <File FileName="../SwaggerClient/src/IO.Swagger/Model/ApiResponse.cs" Line="13" Column="2" />
</Files> </Files>
</MonoDevelop.Ide.Workbench> </MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints> <MonoDevelop.Ide.DebuggingService.Breakpoints>