mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-05 15:10:49 +00:00
Merge pull request #1679 from wing328/csharp_default_value
[C#] add default member's value for C# models
This commit is contained in:
commit
0dd2ebc78e
@ -7,9 +7,7 @@ import io.swagger.codegen.DefaultCodegen;
|
|||||||
import io.swagger.codegen.SupportingFile;
|
import io.swagger.codegen.SupportingFile;
|
||||||
import io.swagger.codegen.CodegenProperty;
|
import io.swagger.codegen.CodegenProperty;
|
||||||
import io.swagger.codegen.CodegenModel;
|
import io.swagger.codegen.CodegenModel;
|
||||||
import io.swagger.models.properties.ArrayProperty;
|
import io.swagger.models.properties.*;
|
||||||
import io.swagger.models.properties.MapProperty;
|
|
||||||
import io.swagger.models.properties.Property;
|
|
||||||
import io.swagger.codegen.CliOption;
|
import io.swagger.codegen.CliOption;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -300,4 +298,51 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
}
|
}
|
||||||
return objs;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,15 @@ namespace {{packageName}}.Model
|
|||||||
[DataContract]
|
[DataContract]
|
||||||
public class {{classname}} : IEquatable<{{classname}}>{{#parent}}, {{{parent}}}{{/parent}}
|
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}}
|
{{#vars}}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
||||||
|
@ -16,6 +16,14 @@ namespace IO.Swagger.Model
|
|||||||
[DataContract]
|
[DataContract]
|
||||||
public class Category : IEquatable<Category>
|
public class Category : IEquatable<Category>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Category" /> class.
|
||||||
|
/// </summary>
|
||||||
|
public Category()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Id
|
/// Gets or Sets Id
|
||||||
|
@ -16,6 +16,14 @@ namespace IO.Swagger.Model
|
|||||||
[DataContract]
|
[DataContract]
|
||||||
public class Order : IEquatable<Order>
|
public class Order : IEquatable<Order>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Order" /> class.
|
||||||
|
/// </summary>
|
||||||
|
public Order()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Id
|
/// Gets or Sets Id
|
||||||
|
@ -16,6 +16,14 @@ namespace IO.Swagger.Model
|
|||||||
[DataContract]
|
[DataContract]
|
||||||
public class Pet : IEquatable<Pet>
|
public class Pet : IEquatable<Pet>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Pet" /> class.
|
||||||
|
/// </summary>
|
||||||
|
public Pet()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Id
|
/// Gets or Sets Id
|
||||||
|
@ -16,6 +16,14 @@ namespace IO.Swagger.Model
|
|||||||
[DataContract]
|
[DataContract]
|
||||||
public class Tag : IEquatable<Tag>
|
public class Tag : IEquatable<Tag>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Tag" /> class.
|
||||||
|
/// </summary>
|
||||||
|
public Tag()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Id
|
/// Gets or Sets Id
|
||||||
|
@ -16,6 +16,14 @@ namespace IO.Swagger.Model
|
|||||||
[DataContract]
|
[DataContract]
|
||||||
public class User : IEquatable<User>
|
public class User : IEquatable<User>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="User" /> class.
|
||||||
|
/// </summary>
|
||||||
|
public User()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Id
|
/// Gets or Sets Id
|
||||||
|
@ -1,30 +1,11 @@
|
|||||||
<Properties StartupItem="SwaggerClientTest.csproj">
|
<Properties StartupItem="SwaggerClientTest.csproj">
|
||||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
<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>
|
<Files>
|
||||||
<File FileName="TestConfiguration.cs" Line="17" Column="33" />
|
<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="81" Column="17" />
|
||||||
<File FileName="TestPet.cs" Line="87" Column="4" />
|
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs" Line="12" Column="18" />
|
||||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs" Line="1" Column="1" />
|
|
||||||
<File FileName="TestApiClient.cs" Line="22" Column="4" />
|
|
||||||
</Files>
|
</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.Workbench>
|
||||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
<BreakpointStore />
|
<BreakpointStore />
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user