Skip to content

Commit

Permalink
General upgrade to nswag v14 and dotnet 8 (#39)
Browse files Browse the repository at this point in the history
* General upgrade to nswag v14 and dotnet 8

* bump dotnet version

* upgrade to OC 1.8.3

---------

Co-authored-by: Dean Marcussen <dean.marcussen@digitalconstructionworks.com>
  • Loading branch information
deanmarcussen and Dean Marcussen authored Jul 24, 2024
1 parent 177a02e commit 1f1749d
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
38 changes: 19 additions & 19 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Project>

<ItemGroup>
<PackageReference Update="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Update="NJsonSchema" Version="10.8.0" />
<PackageReference Update="NSwag.AspNetCore" Version="13.18.0" />
<PackageReference Update="OrchardCore.Application.Cms.Targets" Version="1.5.0" />
<PackageReference Update="OrchardCore.ContentFields" Version="1.5.0" />
<PackageReference Update="OrchardCore.ContentManagement" Version="1.5.0" />
<PackageReference Update="OrchardCore.ContentManagement.Abstractions" Version="1.5.0" />
<PackageReference Update="OrchardCore.Contents.Core" Version="1.5.0" />
<PackageReference Update="OrchardCore.ContentTypes.Abstractions" Version="1.5.0" />
<PackageReference Update="OrchardCore.DisplayManagement" Version="1.5.0" />
<PackageReference Update="OrchardCore.Flows" Version="1.5.0" />
<PackageReference Update="OrchardCore.Html" Version="1.5.0" />
<PackageReference Update="OrchardCore.Lists" Version="1.5.0" />
<PackageReference Update="OrchardCore.Infrastructure" Version="1.5.0" />
<PackageReference Update="OrchardCore.Logging.NLog" Version="1.5.0" />
<PackageReference Update="OrchardCore.Module.Targets" Version="1.5.0" />
<PackageReference Update="OrchardCore.ResourceManagement" Version="1.5.0" />
<PackageReference Update="OrchardCore.Theme.Targets" Version="1.5.0" />
<PackageReference Update="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Update="NJsonSchema" Version="11.0.2" />
<PackageReference Update="NSwag.AspNetCore" Version="14.1.0" />
<PackageReference Update="OrchardCore.Application.Cms.Targets" Version="1.8.3" />
<PackageReference Update="OrchardCore.ContentFields" Version="1.8.3" />
<PackageReference Update="OrchardCore.ContentManagement" Version="1.8.3" />
<PackageReference Update="OrchardCore.ContentManagement.Abstractions" Version="1.8.3" />
<PackageReference Update="OrchardCore.Contents.Core" Version="1.8.3" />
<PackageReference Update="OrchardCore.ContentTypes.Abstractions" Version="1.8.3" />
<PackageReference Update="OrchardCore.DisplayManagement" Version="1.8.3" />
<PackageReference Update="OrchardCore.Flows" Version="1.8.3" />
<PackageReference Update="OrchardCore.Html" Version="1.8.3" />
<PackageReference Update="OrchardCore.Lists" Version="1.8.3" />
<PackageReference Update="OrchardCore.Infrastructure" Version="1.8.3" />
<PackageReference Update="OrchardCore.Logging.NLog" Version="1.8.3" />
<PackageReference Update="OrchardCore.Module.Targets" Version="1.8.3" />
<PackageReference Update="OrchardCore.ResourceManagement" Version="1.8.3" />
<PackageReference Update="OrchardCore.Theme.Targets" Version="1.8.3" />
</ItemGroup>
</Project>
</Project>
13 changes: 11 additions & 2 deletions ThisNetWorks.OrchardCore.OpenApi.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
# Visual Studio Version 17
VisualStudioVersion = 17.8.34330.188
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThisNetWorks.OrchardCore.OpenApi", "src\ThisNetWorks.OrchardCore.OpenApi\ThisNetWorks.OrchardCore.OpenApi.csproj", "{CE8911A8-8769-4958-B9B6-873D53853ED7}"
EndProject
Expand All @@ -23,6 +23,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThisNetWorks.OrchardCore.Op
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThisNetWorks.OrchardCore.OpenApi.SampleModels", "samples\ThisNetWorks.OrchardCore.OpenApi.SampleModels\ThisNetWorks.OrchardCore.OpenApi.SampleModels.csproj", "{A1370FC8-40E2-45A3-B9D8-0810C8B2ADD6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThisNetWorks.OrchardCore.OpenApi.ConsoleClient", "samples\ThisNetWorks.OrchardCore.OpenApi.ConsoleClient\ThisNetWorks.OrchardCore.OpenApi.ConsoleClient.csproj", "{FE33358F-A87E-42CA-8204-2125DA8622A0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -72,6 +74,12 @@ Global
{A1370FC8-40E2-45A3-B9D8-0810C8B2ADD6}.DebugOpenApi|Any CPU.Build.0 = Debug|Any CPU
{A1370FC8-40E2-45A3-B9D8-0810C8B2ADD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1370FC8-40E2-45A3-B9D8-0810C8B2ADD6}.Release|Any CPU.Build.0 = Release|Any CPU
{FE33358F-A87E-42CA-8204-2125DA8622A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE33358F-A87E-42CA-8204-2125DA8622A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE33358F-A87E-42CA-8204-2125DA8622A0}.DebugOpenApi|Any CPU.ActiveCfg = Debug|Any CPU
{FE33358F-A87E-42CA-8204-2125DA8622A0}.DebugOpenApi|Any CPU.Build.0 = Debug|Any CPU
{FE33358F-A87E-42CA-8204-2125DA8622A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE33358F-A87E-42CA-8204-2125DA8622A0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -84,6 +92,7 @@ Global
{CFC87DD8-1FA2-42C6-B930-3796C46AFFF0} = {8C451866-7272-45C2-BA76-4248E11155EC}
{9415CCCA-F0BA-48D7-8F0B-04D81911D076} = {8C451866-7272-45C2-BA76-4248E11155EC}
{A1370FC8-40E2-45A3-B9D8-0810C8B2ADD6} = {8C451866-7272-45C2-BA76-4248E11155EC}
{FE33358F-A87E-42CA-8204-2125DA8622A0} = {8C451866-7272-45C2-BA76-4248E11155EC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EF1A5E30-9076-4572-B772-5ACD6F440A24}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<RazorRuntimeCompilation>false</RazorRuntimeCompilation>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,43 @@ public SamplePartDisplayDriver(IContentDefinitionManager contentDefinitionManage
public override IDisplayResult Display(SamplePart SamplePart)
{
return Combine(
Initialize<SamplePartViewModel>("SamplePart", m => BuildViewModel(m, SamplePart))
Initialize<SamplePartViewModel>("SamplePart", async vm =>await BuildViewModelAsync(vm, SamplePart))
.Location("Detail", "Content:20"),
Initialize<SamplePartViewModel>("SamplePart_Summary", m => BuildViewModel(m, SamplePart))
Initialize<SamplePartViewModel>("SamplePart_Summary", async m =>await BuildViewModelAsync(m, SamplePart))
.Location("Summary", "Meta:5")
);
}

public override IDisplayResult Edit(SamplePart SamplePart)
{
return Initialize<SamplePartViewModel>("SamplePart_Edit", m => BuildViewModel(m, SamplePart));
return Initialize<SamplePartViewModel>("SamplePart_Edit", async vm => await BuildViewModelAsync(vm, SamplePart));
}

public override async Task<IDisplayResult> UpdateAsync(SamplePart model, IUpdateModel updater)
{
var settings = GetSamplePartSettings(model);

await updater.TryUpdateModelAsync(model, Prefix, t => t.Show);

return Edit(model);
}

public SamplePartSettings GetSamplePartSettings(SamplePart part)
public async Task<SamplePartSettings> GetSamplePartSettingsAsync(SamplePart part)
{
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType);
var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(part.ContentItem.ContentType);
var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(p => p.PartDefinition.Name == nameof(SamplePart));
var settings = contentTypePartDefinition.GetSettings<SamplePartSettings>();

return settings;
}

private Task BuildViewModel(SamplePartViewModel model, SamplePart part)
private async Task BuildViewModelAsync(SamplePartViewModel model, SamplePart part)
{
var settings = GetSamplePartSettings(part);
var settings = await GetSamplePartSettingsAsync(part);

model.ContentItem = part.ContentItem;
model.MySetting = settings.MySetting;
model.Show = part.Show;
model.SamplePart = part;
model.Settings = settings;

return Task.CompletedTask;
}
}
}
26 changes: 13 additions & 13 deletions samples/ThisNetWorks.OrchardCore.OpenApi.SampleModule/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ IRecipeMigrator recipeMigrator
_recipeMigrator = recipeMigrator;
}

public int Create()
public async Task<int> CreateAsync()
{
_contentDefinitionManager.AlterPartDefinition("SamplePart", builder => builder
await _contentDefinitionManager.AlterPartDefinitionAsync("SamplePart", builder => builder
.Attachable()
.WithDescription("Provides a Sample part for your content item.")
.WithField("MyTextField", field => field
Expand All @@ -35,19 +35,19 @@ public int Create()
}

// This creates some useful type definitions for bag parts.
public int UpdateFrom1()
public async Task<int> UpdateFrom1Async()
{
_contentDefinitionManager.AlterTypeDefinition("Bar", type => type
await _contentDefinitionManager.AlterTypeDefinitionAsync("Bar", type => type
.DisplayedAs("Bar")
.WithPart("HtmlBodyPart")
);

_contentDefinitionManager.AlterTypeDefinition("Foo", type => type
await _contentDefinitionManager.AlterTypeDefinitionAsync("Foo", type => type
.DisplayedAs("Foo")
.WithPart("MarkdownBodyPart")
);

_contentDefinitionManager.AlterTypeDefinition("Bag", type => type
await _contentDefinitionManager.AlterTypeDefinitionAsync("Bag", type => type
.DisplayedAs("Bag container")
.Listable()
.Creatable()
Expand All @@ -67,9 +67,9 @@ public int UpdateFrom1()
}

// This adds a field to the HtmlBodyPart
public int UpdateFrom2()
public async Task<int> UpdateFrom2Async()
{
_contentDefinitionManager.AlterPartDefinition("HtmlBodyPart", part => part
await _contentDefinitionManager.AlterPartDefinitionAsync("HtmlBodyPart", part => part
.WithField("FooField", field => field
.OfType("TextField")
.WithDisplayName("Foo Field")
Expand All @@ -79,16 +79,16 @@ public int UpdateFrom2()
return 3;
}

public int UpdateFrom3()
public async Task<int> UpdateFrom3Async()
{
_contentDefinitionManager.AlterTypeDefinition("FooText", type => type
await _contentDefinitionManager.AlterTypeDefinitionAsync("FooText", type => type
.Securable()
.Versionable()
.DisplayedAs("Foo text")
.WithPart("FooText")
);

_contentDefinitionManager.AlterPartDefinition("FooText", part => part
await _contentDefinitionManager.AlterPartDefinitionAsync("FooText", part => part
.WithField("FooField", field => field
.OfType("TextField")
.WithDisplayName("Foo Field")
Expand All @@ -98,9 +98,9 @@ public int UpdateFrom3()
return 4;
}

public int UpdateFrom4()
public async Task<int> UpdateFrom4Async()
{
_contentDefinitionManager.AlterTypeDefinition("FooTextContainer", type => type
await _contentDefinitionManager.AlterTypeDefinitionAsync("FooTextContainer", type => type
.DisplayedAs("Foo text container")
.Listable()
.Securable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public override void ConfigureServices(IServiceCollection services)
generator.OperationProcessors.Add(
new AspNetCoreOperationSecurityScopeProcessor("bearer"));
});
o.Middleware.SwaggerUi3Settings = (swagger) =>
o.Middleware.SwaggerUISettings = (swagger) =>
{
swagger.OAuth2Client = new OAuth2ClientSettings
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class OpenApiMiddlewareOptions

public Action<OpenApiDocumentMiddlewareSettings> OpenApiDocumentMiddlewareSettings { get; set; }

public bool UseOrchardCoreSwaggerUi3Middleware { get; set; } = true;
public bool UseOrchardCoreSwaggerMiddleware { get; set; } = true;

public Action<SwaggerUi3Settings> SwaggerUi3Settings { get; set; }
public Action<SwaggerUiSettings> SwaggerUISettings { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using NJsonSchema;
using NJsonSchema.Converters;
using NJsonSchema.NewtonsoftJson.Converters;
using NSwag.Generation.Processors;
using NSwag.Generation.Processors.Contexts;
using OrchardCore.ContentManagement;
Expand Down Expand Up @@ -51,7 +51,7 @@ public void Process(DocumentProcessorContext context)
var fieldDtoSchema = context.SchemaGenerator.Generate(typeof(ContentFieldDto), context.SchemaResolver);
fieldDtoSchema.AllowAdditionalProperties = false;

var ctds = _contentDefinitionManager.ListTypeDefinitions();
var ctds = _contentDefinitionManager.ListTypeDefinitionsAsync().GetAwaiter().GetResult();
var allFieldDefinitions = ctds
.SelectMany(x => x.Parts.SelectMany(p => p.PartDefinition.Fields))
.Select(x => x.FieldDefinition).ToLookup(x => x.Name, StringComparer.OrdinalIgnoreCase);
Expand Down Expand Up @@ -94,7 +94,7 @@ public void Process(DocumentProcessorContext context)
var partDtoSchema = context.SchemaGenerator.Generate(typeof(ContentPartDto), context.SchemaResolver);

partDtoSchema.AllowAdditionalProperties = false;
var allPartDefinitions = _contentDefinitionManager.ListPartDefinitions();
var allPartDefinitions = _contentDefinitionManager.ListPartDefinitionsAsync().GetAwaiter().GetResult();

// Register code only parts first.
foreach (var registeredPartOption in _contentOptions.ContentPartOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ protected override async Task<string> GetDocumentAsync(HttpContext context)
// We will need a cache provider, that can handle clearing cache from Scoped events.
//try
//{
var json = (await GenerateDocumentAsync(context)).ToJson();

return json;
var openApiDocument = await GenerateDocumentAsync(context);

var data = openApiDocument.ToJson();

return data;
//}
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/ThisNetWorks.OrchardCore.OpenApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using NJsonSchema;
using NJsonSchema.NewtonsoftJson.Generation;
using NSwag.Generation.Processors;
using OrchardCore.Modules;
using System;
Expand All @@ -21,10 +23,13 @@ public override void ConfigureServices(IServiceCollection services)
{
o.Middleware.GeneratorOptions.Add((o, sp) =>
{
// This forces Pascal Case everywhere, which resolves issues with ContentElement properties.
o.SerializerSettings = new JsonSerializerSettings
o.SchemaSettings = new NewtonsoftJsonSchemaGeneratorSettings
{
ContractResolver = new DefaultContractResolver()
SerializerSettings = new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver()
},
SchemaType = SchemaType.OpenApi3
};
});
});
Expand All @@ -51,9 +56,9 @@ public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilde
builder.UseOrchardCoreOpenApi(options.Middleware.OpenApiDocumentMiddlewareSettings);
}

if (options.Middleware.UseOrchardCoreSwaggerUi3Middleware)
if (options.Middleware.UseOrchardCoreSwaggerMiddleware)
{
builder.UseSwaggerUi3(options.Middleware.SwaggerUi3Settings);
builder.UseSwaggerUi(options.Middleware.SwaggerUISettings);
}
}
}
Expand Down
Loading

0 comments on commit 1f1749d

Please # to comment.