Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for STJ-native C# code gen #4782

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<NSwagDictionaryBaseType>$(NSwagDictionaryBaseType)</NSwagDictionaryBaseType>
<NSwagClassStyle>$(NSwagClassStyle)</NSwagClassStyle>
<NSwagJsonLibrary>$(NSwagJsonLibrary)</NSwagJsonLibrary>
<NSwagJsonPolymorphicSerializationStyle>$(NSwagJsonPolymorphicSerializationStyle)</NSwagJsonPolymorphicSerializationStyle>
<NSwagGenerateDefaultValues>$(NSwagGenerateDefaultValues)</NSwagGenerateDefaultValues>
<NSwagGenerateDataAnnotations>$(NSwagGenerateDataAnnotations)</NSwagGenerateDataAnnotations>
<NSwagExcludedTypeNames>$(NSwagExcludedTypeNames)</NSwagExcludedTypeNames>
Expand Down Expand Up @@ -154,6 +155,7 @@
<NSwagDictionaryBaseType>$(NSwagDictionaryBaseType)</NSwagDictionaryBaseType>
<NSwagClassStyle>$(NSwagClassStyle)</NSwagClassStyle>
<NSwagJsonLibrary>$(NSwagJsonLibrary)</NSwagJsonLibrary>
<NSwagJsonPolymorphicSerializationStyle>$(NSwagJsonPolymorphicSerializationStyle)</NSwagJsonPolymorphicSerializationStyle>
<NSwagGenerateDefaultValues>$(NSwagGenerateDefaultValues)</NSwagGenerateDefaultValues>
<NSwagGenerateDataAnnotations>$(NSwagGenerateDataAnnotations)</NSwagGenerateDataAnnotations>
<NSwagExcludedTypeNames>$(NSwagExcludedTypeNames)</NSwagExcludedTypeNames>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@
<CurrentOpenApiReference>
<Command Condition="'%(NSwagJsonLibrary)' != ''">%(Command) /jsonLibrary:%(NSwagJsonLibrary)</Command>
</CurrentOpenApiReference>
<CurrentOpenApiReference>
<Command Condition="'%(NSwagJsonPolymorphicSerializationStyle)' != ''">%(Command) /jsonPolymorphicSerializationStyle:%(NSwagJsonPolymorphicSerializationStyle)</Command>
</CurrentOpenApiReference>
<CurrentOpenApiReference>
<Command Condition="'%(NSwagGenerateDefaultValues)' != ''">%(Command) /generateDefaultValues:%(NSwagGenerateDefaultValues)</Command>
</CurrentOpenApiReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ public CSharpJsonLibrary JsonLibrary
set { Settings.JsonLibrary = value; }
}

[Argument(Name = "JsonPolymorphicSerializationStyle", IsRequired = false, Description = "The CSharp JSON polymorphic serialization style, 'NSwag' or 'SystemTextJson' (default: 'NSwag', 'SystemTextJson' is experimental).")]
public CSharpJsonPolymorphicSerializationStyle JsonPolymorphicSerializationStyle
{
get { return Settings.JsonPolymorphicSerializationStyle; }
set { Settings.JsonPolymorphicSerializationStyle = value; }
}

[Argument(Name = "GenerateDefaultValues", IsRequired = false, Description = "Specifies whether to generate default values for properties (may generate CSharp 6 code, default: true).")]
public bool GenerateDefaultValues
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ public CSharpJsonLibrary JsonLibrary
set { Settings.CSharpGeneratorSettings.JsonLibrary = value; }
}

[Argument(Name = "JsonPolymorphicSerializationStyle", IsRequired = false, Description = "The CSharp JSON polymorphic serialization style, 'NSwag' or 'SystemTextJson' (default: 'NSwag', 'SystemTextJson' is experimental).")]
public CSharpJsonPolymorphicSerializationStyle JsonPolymorphicSerializationStyle
{
get { return Settings.JsonPolymorphicSerializationStyle; }
set { Settings.JsonPolymorphicSerializationStyle = value; }
}

[Argument(Name = "GenerateDefaultValues", IsRequired = false, Description = "Specifies whether to generate default values for properties (may generate CSharp 6 code, default: true).")]
public bool GenerateDefaultValues
{
Expand Down
2 changes: 2 additions & 0 deletions src/NSwag.Sample.NET70Minimal/nswag.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"dictionaryBaseType": "System.Collections.Generic.Dictionary",
"classStyle": "Poco",
"jsonLibrary": "NewtonsoftJson",
"jsonPolymorphicSerializationStyle": "NSwag",
"generateDefaultValues": true,
"generateDataAnnotations": true,
"excludedTypeNames": [],
Expand Down Expand Up @@ -206,6 +207,7 @@
"dictionaryBaseType": "System.Collections.Generic.Dictionary",
"classStyle": "Poco",
"jsonLibrary": "NewtonsoftJson",
"jsonPolymorphicSerializationStyle": "NSwag",
"generateDefaultValues": true,
"generateDataAnnotations": true,
"excludedTypeNames": [],
Expand Down
2 changes: 2 additions & 0 deletions src/NSwag.Sample.NET80Minimal/nswag.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"dictionaryBaseType": "System.Collections.Generic.Dictionary",
"classStyle": "Poco",
"jsonLibrary": "NewtonsoftJson",
"jsonPolymorphicSerializationStyle": "NSwag",
"generateDefaultValues": true,
"generateDataAnnotations": true,
"excludedTypeNames": [],
Expand Down Expand Up @@ -206,6 +207,7 @@
"dictionaryBaseType": "System.Collections.Generic.Dictionary",
"classStyle": "Poco",
"jsonLibrary": "NewtonsoftJson",
"jsonPolymorphicSerializationStyle": "NSwag",
"generateDefaultValues": true,
"generateDataAnnotations": true,
"excludedTypeNames": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public OpenApiToCSharpClientCommand Command
.Select(t => (CSharpJsonLibrary)Enum.Parse(typeof(CSharpJsonLibrary), t))
.ToArray();

/// <summary>Gets the list of JSON polymorphic serialization styles. </summary>
public CSharpJsonPolymorphicSerializationStyle[] JsonPolymorphicSerializationStyles { get; } = Enum.GetNames(typeof(CSharpJsonPolymorphicSerializationStyle))
.Select(t => (CSharpJsonPolymorphicSerializationStyle)Enum.Parse(typeof(CSharpJsonPolymorphicSerializationStyle), t))
.ToArray();

/// <summary>Gets new line behaviors. </summary>
public NewLineBehavior[] NewLineBehaviors { get; } = Enum.GetNames(typeof(NewLineBehavior))
.Select(t => (NewLineBehavior)Enum.Parse(typeof(NewLineBehavior), t))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@
<ComboBox SelectedItem="{Binding Command.JsonLibrary, Mode=TwoWay}"
ToolTip="JsonLibrary"
ItemsSource="{Binding JsonLibraries}" Margin="0,0,0,12" />



<TextBlock Text="JSON Polymorphic Serialization Style ('System.Text.Json' is experimental/incomplete!)" FontWeight="Bold" Margin="0,0,0,6" />
<ComboBox SelectedItem="{Binding Command.JsonPolymorphicSerializationStyles, Mode=TwoWay}"
ToolTip="JsonLibrary"
ItemsSource="{Binding JsonPolymorphicSerializationStyles}" Margin="0,0,0,12" />

<CheckBox IsChecked="{Binding Command.RequiredPropertiesMustBeDefined, Mode=TwoWay}" ToolTip="RequiredPropertiesMustBeDefined" Margin="0,0,0,12">
<TextBlock Text="Required properties must be defined in JSON (sets Required.Always when the property is required)" TextWrapping="Wrap" />
</CheckBox>
Expand Down
Loading