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> 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

@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
VisualStudioVersion = 12.0.0.0
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
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger.Test", "src\IO.Swagger.Test\IO.Swagger.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"
EndProject
@ -12,10 +12,10 @@ Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{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
{74456AF8-75EE-4ABC-97EB-CA96A472DD21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74456AF8-75EE-4ABC-97EB-CA96A472DD21}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74456AF8-75EE-4ABC-97EB-CA96A472DD21}.Release|Any CPU.ActiveCfg = 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.Build.0 = Debug|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
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:
- API 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
## Frameworks supported

View File

@ -65,7 +65,7 @@
<Import Project="$(MsBuildToolsPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<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>
</ProjectReference>
</ItemGroup>

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

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

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

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