Skip to content

Commit

Permalink
Merge pull request #1144 from swagger-api/dotnet-oneof
Browse files Browse the repository at this point in the history
Support for OneOf in Model for DotNet Generators
  • Loading branch information
HugoMario authored May 5, 2023
2 parents 11d1bd3 + 40d89b5 commit 0a9e28a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
20 changes: 18 additions & 2 deletions src/main/resources/handlebars/aspnetcore/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ using Newtonsoft.Json;
{{#models}}
{{#model}}
namespace {{packageName}}.Models
{ {{#isEnum}}{{>enumClass}}{{/isEnum}}{{^isEnum}}
{
{{^isComposedModel}}
{{#isEnum}}{{>enumClass}}{{/isEnum}}{{^isEnum}}
/// <summary>
/// {{description}}
/// </summary>
[DataContract]
public partial class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}}IEquatable<{{classname}}>
public partial class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}}IEquatable<{{classname}}>{{#interfaceModels}}{{#@first}}, {{/@first}}{{classname}}{{^@last}}, {{/@last}}{{#@last}} {{/@last}}{{/interfaceModels}}
{ {{#vars}}{{#isEnum}}{{^isContainer}}{{>enumClass}}{{/isContainer}}{{/isEnum}}{{#items.isEnum}}{{#items}}{{^isContainer}}{{>enumClass}}{{/isContainer}}{{/items}}{{/items.isEnum}}
/// <summary>
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
Expand Down Expand Up @@ -139,6 +141,20 @@ namespace {{packageName}}.Models
#endregion Operators
}
{{/isEnum}}
{{/isComposedModel}}
{{#isComposedModel}}
/// <summary>
/// {{description}}
/// </summary>
public interface {{{classname}}}
{
{{#vendorExtensions}}
{{#x-discriminator-type-getter}}
{{x-discriminator-type}} {{x-discriminator-type-getter}}();
{{/x-discriminator-type-getter}}
{{/vendorExtensions}}
}
{{/isComposedModel}}
{{/model}}
{{/models}}
}
12 changes: 12 additions & 0 deletions src/main/resources/handlebars/csharp/interface.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <summary>
/// {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
/// </summary>
public interface {{{classname}}}
{
{{#vendorExtensions}}
{{#x-discriminator-type-getter}}
{{x-discriminator-type}} {{x-discriminator-type-getter}}();
{{/x-discriminator-type-getter}}
{{/vendorExtensions}}
}
8 changes: 7 additions & 1 deletion src/main/resources/handlebars/csharp/model.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{>partial_header}}
{{^x-is-composed-model}}
using System;
using System.Linq;
using System.IO;
Expand Down Expand Up @@ -27,12 +28,17 @@ using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
{{/netStandard}}
using SwaggerDateConverter = {{packageName}}.Client.SwaggerDateConverter;

{{/x-is-composed-model}}
{{#models}}
{{#model}}
namespace {{packageName}}.{{modelPackage}}
{
{{#isComposedModel}}
{{>interface}}
{{/isComposedModel}}
{{^isComposedModel}}
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>modelGeneric}}{{/isEnum}}
{{/isComposedModel}}
{{/model}}
{{/models}}
}
2 changes: 1 addition & 1 deletion src/main/resources/handlebars/csharp/modelGeneric.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{#generatePropertyChanged}}
[ImplementPropertyChanged]
{{/generatePropertyChanged}}
{{>visibility}} partial class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}} IEquatable<{{classname}}>{{^netStandard}}{{#validatable}}, IValidatableObject{{/validatable}}{{/netStandard}}
{{>visibility}} partial class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}} IEquatable<{{classname}}>{{^netStandard}}{{#validatable}}, IValidatableObject{{/validatable}}{{/netStandard}}{{#interfaceModels}}{{#@first}}, {{/@first}}{{classname}}{{^@last}}, {{/@last}}{{#@last}} {{/@last}}{{/interfaceModels}}
{
{{#vars}}
{{#items.isEnum}}
Expand Down

0 comments on commit 0a9e28a

Please sign in to comment.