add default member's value for C# models

This commit is contained in:
wing328 2015-12-08 15:09:30 +08:00
parent 9ed5b863c4
commit f9f0992cc8
12 changed files with 100 additions and 25 deletions

View File

@ -7,9 +7,7 @@ import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.SupportingFile;
import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.CodegenModel;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.Property;
import io.swagger.models.properties.*;
import io.swagger.codegen.CliOption;
import java.io.File;
@ -300,4 +298,51 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
}
return objs;
}
/**
* Return the default value of the property
*
* @param p Swagger property object
* @return string presentation of the default value of the property
*/
@Override
public String toDefaultValue(Property p) {
if (p instanceof StringProperty) {
StringProperty dp = (StringProperty) p;
if (dp.getDefault() != null) {
return "\"" + dp.getDefault().toString() + "\"";
}
} else if (p instanceof BooleanProperty) {
BooleanProperty dp = (BooleanProperty) p;
if (dp.getDefault() != null) {
return dp.getDefault().toString();
}
} else if (p instanceof DateProperty) {
// TODO
} else if (p instanceof DateTimeProperty) {
// TODO
} else if (p instanceof DoubleProperty) {
DoubleProperty dp = (DoubleProperty) p;
if (dp.getDefault() != null) {
return dp.getDefault().toString();
}
} else if (p instanceof FloatProperty) {
FloatProperty dp = (FloatProperty) p;
if (dp.getDefault() != null) {
return dp.getDefault().toString();
}
} else if (p instanceof IntegerProperty) {
IntegerProperty dp = (IntegerProperty) p;
if (dp.getDefault() != null) {
return dp.getDefault().toString();
}
} else if (p instanceof LongProperty) {
LongProperty dp = (LongProperty) p;
if (dp.getDefault() != null) {
return dp.getDefault().toString();
}
}
return null;
}
}

View File

@ -18,6 +18,15 @@ namespace {{packageName}}.Model
[DataContract]
public class {{classname}} : IEquatable<{{classname}}>{{#parent}}, {{{parent}}}{{/parent}}
{
/// <summary>
/// Initializes a new instance of the <see cref="{{classname}}" /> class.
/// </summary>
public {{classname}}()
{
{{#vars}}{{#defaultValue}}this.{{name}} = {{{defaultValue}}};
{{/defaultValue}}{{/vars}}
}
{{#vars}}
/// <summary>
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}

View File

@ -16,6 +16,14 @@ namespace IO.Swagger.Model
[DataContract]
public class Category : IEquatable<Category>
{
/// <summary>
/// Initializes a new instance of the <see cref="Category" /> class.
/// </summary>
public Category()
{
}
/// <summary>
/// Gets or Sets Id

View File

@ -16,6 +16,14 @@ namespace IO.Swagger.Model
[DataContract]
public class Order : IEquatable<Order>
{
/// <summary>
/// Initializes a new instance of the <see cref="Order" /> class.
/// </summary>
public Order()
{
}
/// <summary>
/// Gets or Sets Id

View File

@ -16,6 +16,14 @@ namespace IO.Swagger.Model
[DataContract]
public class Pet : IEquatable<Pet>
{
/// <summary>
/// Initializes a new instance of the <see cref="Pet" /> class.
/// </summary>
public Pet()
{
}
/// <summary>
/// Gets or Sets Id

View File

@ -16,6 +16,14 @@ namespace IO.Swagger.Model
[DataContract]
public class Tag : IEquatable<Tag>
{
/// <summary>
/// Initializes a new instance of the <see cref="Tag" /> class.
/// </summary>
public Tag()
{
}
/// <summary>
/// Gets or Sets Id

View File

@ -16,6 +16,14 @@ namespace IO.Swagger.Model
[DataContract]
public class User : IEquatable<User>
{
/// <summary>
/// Initializes a new instance of the <see cref="User" /> class.
/// </summary>
public User()
{
}
/// <summary>
/// Gets or Sets Id

View File

@ -1,30 +1,11 @@
<Properties StartupItem="SwaggerClientTest.csproj">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs">
<Files>
<File FileName="TestConfiguration.cs" Line="17" Column="33" />
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs" Line="523" Column="49" />
<File FileName="TestPet.cs" Line="87" Column="4" />
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs" Line="1" Column="1" />
<File FileName="TestApiClient.cs" Line="22" Column="4" />
<File FileName="TestPet.cs" Line="81" Column="17" />
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs" Line="12" Column="18" />
</Files>
<Pads>
<Pad Id="MonoDevelop.NUnit.TestPad">
<State name="__root__">
<Node name="SwaggerClientTest" expanded="True">
<Node name="SwaggerClientTest" expanded="True">
<Node name="SwaggerClient" expanded="True">
<Node name="TestPet" expanded="True">
<Node name="TestPet" expanded="True">
<Node name="TestGetPetByIdAsyncWithHttpInfo" selected="True" />
</Node>
</Node>
</Node>
</Node>
</Node>
</State>
</Pad>
</Pads>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />