From 38ac1eb0507a066cc7f5e800db9aa0fc3f9973f0 Mon Sep 17 00:00:00 2001 From: Senn Geerts Date: Sat, 13 Jul 2024 13:43:06 +0200 Subject: [PATCH] #197 .build nuget package --- .../StreetlightsAPI/StreetlightsAPI.csproj | 5 - .../AsyncAPI.Saunter.Generator.Build.csproj | 13 +- .../AsyncAPI.Saunter.Generator.Build.targets | 25 +-- .../AsyncAPI.Saunter.Generator.Cli.csproj | 4 +- .../ToFile/ServiceProviderBuilder.cs | 2 +- .../ToFile/ToFileCommand.cs | 2 +- ...ncAPI.Saunter.Generator.Build.Tests.csproj | 7 +- .../IntegrationTests.cs | 161 +----------------- 8 files changed, 30 insertions(+), 189 deletions(-) diff --git a/examples/StreetlightsAPI/StreetlightsAPI.csproj b/examples/StreetlightsAPI/StreetlightsAPI.csproj index 6f179ce5..59dc6fdb 100644 --- a/examples/StreetlightsAPI/StreetlightsAPI.csproj +++ b/examples/StreetlightsAPI/StreetlightsAPI.csproj @@ -29,11 +29,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - - - --version "999.*" --add-source "$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)../../local-nuget-source))" - diff --git a/src/AsyncAPI.Saunter.Generator.Build/AsyncAPI.Saunter.Generator.Build.csproj b/src/AsyncAPI.Saunter.Generator.Build/AsyncAPI.Saunter.Generator.Build.csproj index a8fbfeee..6d0e85e8 100644 --- a/src/AsyncAPI.Saunter.Generator.Build/AsyncAPI.Saunter.Generator.Build.csproj +++ b/src/AsyncAPI.Saunter.Generator.Build/AsyncAPI.Saunter.Generator.Build.csproj @@ -1,7 +1,7 @@  - net6.0;net8.0 + net8.0 enable 12 true @@ -15,7 +15,7 @@ https://github.com/asyncapi/saunter true true - false + true false https://github.com/asyncapi/saunter MIT @@ -24,6 +24,10 @@ 1.0.0 + + true + + 999.$([System.DateTime]::Now.ToString("yy"))$([System.DateTime]::Now.DayOfYear).$([System.DateTime]::Now.ToString("HHmm")) @@ -41,6 +45,11 @@ + + + + + diff --git a/src/AsyncAPI.Saunter.Generator.Build/build/AsyncAPI.Saunter.Generator.Build.targets b/src/AsyncAPI.Saunter.Generator.Build/build/AsyncAPI.Saunter.Generator.Build.targets index 3e6012ab..f89ee0da 100644 --- a/src/AsyncAPI.Saunter.Generator.Build/build/AsyncAPI.Saunter.Generator.Build.targets +++ b/src/AsyncAPI.Saunter.Generator.Build/build/AsyncAPI.Saunter.Generator.Build.targets @@ -6,16 +6,16 @@ $([System.IO.Path]::GetDirectoryName($(MSBuildThisFileDirectory))) $([System.IO.Path]::GetDirectoryName($(AsyncAPIBuildToolBuildDir))) - ./.config/dotnet-tools.json - $([System.IO.Path]::GetFullPath($([System.IO.Path]::Combine($(AsyncAPIBuildToolRoot), $(LocalToolConfigFile))))) - - --version [1.0.2-beta] - $([System.IO.File]::Exists($(LocalToolConfigFillFullPath))) + $([System.IO.Path]::Combine($(AsyncAPIBuildToolRoot), tools, net8.0, AsyncAPI.Saunter.Generator.Cli.dll)) + $([System.IO.Path]::Combine($(MSBuildProjectDirectory), $(OutputPath), $(AssemblyTitle).dll)) + $([System.IO.Path]::Combine($(MSBuildProjectDirectory), $(AsyncAPIDocumentOutputPath))) - - + + + + @@ -27,17 +27,8 @@ - - - - - - diff --git a/src/AsyncAPI.Saunter.Generator.Cli/AsyncAPI.Saunter.Generator.Cli.csproj b/src/AsyncAPI.Saunter.Generator.Cli/AsyncAPI.Saunter.Generator.Cli.csproj index e7c0b16e..f224cc62 100644 --- a/src/AsyncAPI.Saunter.Generator.Cli/AsyncAPI.Saunter.Generator.Cli.csproj +++ b/src/AsyncAPI.Saunter.Generator.Cli/AsyncAPI.Saunter.Generator.Cli.csproj @@ -42,7 +42,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -56,7 +56,7 @@ - + diff --git a/src/AsyncAPI.Saunter.Generator.Cli/ToFile/ServiceProviderBuilder.cs b/src/AsyncAPI.Saunter.Generator.Cli/ToFile/ServiceProviderBuilder.cs index 69bde4f2..5773b5fd 100644 --- a/src/AsyncAPI.Saunter.Generator.Cli/ToFile/ServiceProviderBuilder.cs +++ b/src/AsyncAPI.Saunter.Generator.Cli/ToFile/ServiceProviderBuilder.cs @@ -16,7 +16,7 @@ public IServiceProvider BuildServiceProvider(string startupAssembly) var fullPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), startupAssembly)); logger.LogInformation($"Loading startup assembly: {fullPath}"); var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(fullPath); - var nswagCommandsAssembly = Assembly.LoadFrom("NSwag.Commands.dll"); + var nswagCommandsAssembly = Assembly.LoadFrom(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(typeof(ServiceProviderBuilder).Assembly.Location), "NSwag.Commands.dll"))); var nswagServiceProvider = nswagCommandsAssembly.GetType("NSwag.Commands.ServiceProviderResolver"); var serviceProvider = (IServiceProvider)nswagServiceProvider.InvokeMember("GetServiceProvider", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static, null, null, [assembly]); return serviceProvider; diff --git a/src/AsyncAPI.Saunter.Generator.Cli/ToFile/ToFileCommand.cs b/src/AsyncAPI.Saunter.Generator.Cli/ToFile/ToFileCommand.cs index 0a62c43d..c801645e 100644 --- a/src/AsyncAPI.Saunter.Generator.Cli/ToFile/ToFileCommand.cs +++ b/src/AsyncAPI.Saunter.Generator.Cli/ToFile/ToFileCommand.cs @@ -68,6 +68,6 @@ public int ToFile([Argument] string startupassembly, string output = "./", strin } } - return 1; + return 0; } } diff --git a/test/AsyncAPI.Saunter.Generator.Build.Tests/AsyncAPI.Saunter.Generator.Build.Tests.csproj b/test/AsyncAPI.Saunter.Generator.Build.Tests/AsyncAPI.Saunter.Generator.Build.Tests.csproj index de4f84f2..2d2d926c 100644 --- a/test/AsyncAPI.Saunter.Generator.Build.Tests/AsyncAPI.Saunter.Generator.Build.Tests.csproj +++ b/test/AsyncAPI.Saunter.Generator.Build.Tests/AsyncAPI.Saunter.Generator.Build.Tests.csproj @@ -11,8 +11,11 @@ - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs b/test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs index e7751ac3..f3379ec5 100644 --- a/test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs +++ b/test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs @@ -67,169 +67,12 @@ public void StreetlightsAPIExportSpecTest() File.Exists("asyncapi.json").ShouldBeTrue("asyncapi.json"); var yml = File.ReadAllText("asyncapi.yml"); - yml.ShouldBe(""" - asyncapi: 2.6.0 - info: - title: Streetlights API - version: 1.0.0 - description: The Smartylighting Streetlights API allows you to remotely manage the city lights. - license: - name: Apache 2.0 - url: https://www.apache.org/licenses/LICENSE-2.0 - servers: - mosquitto: - url: test.mosquitto.org - protocol: mqtt - webapi: - url: localhost:5000 - protocol: http - defaultContentType: application/json - channels: - publish/light/measured: - servers: - - webapi - publish: - operationId: MeasureLight - summary: Inform about environmental lighting conditions for a particular streetlight. - tags: - - name: Light - message: - $ref: '#/components/messages/lightMeasuredEvent' - subscribe/light/measured: - servers: - - mosquitto - subscribe: - operationId: PublishLightMeasurement - summary: Subscribe to environmental lighting conditions for a particular streetlight. - tags: - - name: Light - message: - payload: - $ref: '#/components/schemas/lightMeasuredEvent' - components: - schemas: - lightMeasuredEvent: - type: object - properties: - id: - type: integer - format: int32 - description: Id of the streetlight. - lumens: - type: integer - format: int32 - description: Light intensity measured in lumens. - sentAt: - type: string - format: date-time - description: Light intensity measured in lumens. - additionalProperties: false - messages: - lightMeasuredEvent: - payload: - $ref: '#/components/schemas/lightMeasuredEvent' - name: lightMeasuredEvent - """, "yaml"); + yml.ShouldBe(ExpectedSpecFiles.Yml_v2_6, "yaml"); var yaml = File.ReadAllText("asyncapi.yaml"); yaml.ShouldBe(yml, "yml"); var json = File.ReadAllText("asyncapi.json"); - json.ShouldBe(""" - { - "asyncapi": "2.6.0", - "info": { - "title": "Streetlights API", - "version": "1.0.0", - "description": "The Smartylighting Streetlights API allows you to remotely manage the city lights.", - "license": { - "name": "Apache 2.0", - "url": "https://www.apache.org/licenses/LICENSE-2.0" - } - }, - "servers": { - "mosquitto": { - "url": "test.mosquitto.org", - "protocol": "mqtt" - }, - "webapi": { - "url": "localhost:5000", - "protocol": "http" - } - }, - "defaultContentType": "application/json", - "channels": { - "publish/light/measured": { - "servers": [ - "webapi" - ], - "publish": { - "operationId": "MeasureLight", - "summary": "Inform about environmental lighting conditions for a particular streetlight.", - "tags": [ - { - "name": "Light" - } - ], - "message": { - "$ref": "#/components/messages/lightMeasuredEvent" - } - } - }, - "subscribe/light/measured": { - "servers": [ - "mosquitto" - ], - "subscribe": { - "operationId": "PublishLightMeasurement", - "summary": "Subscribe to environmental lighting conditions for a particular streetlight.", - "tags": [ - { - "name": "Light" - } - ], - "message": { - "payload": { - "$ref": "#/components/schemas/lightMeasuredEvent" - } - } - } - } - }, - "components": { - "schemas": { - "lightMeasuredEvent": { - "type": "object", - "properties": { - "id": { - "type": "integer", - "format": "int32", - "description": "Id of the streetlight." - }, - "lumens": { - "type": "integer", - "format": "int32", - "description": "Light intensity measured in lumens." - }, - "sentAt": { - "type": "string", - "format": "date-time", - "description": "Light intensity measured in lumens." - } - }, - "additionalProperties": false - } - }, - "messages": { - "lightMeasuredEvent": { - "payload": { - "$ref": "#/components/schemas/lightMeasuredEvent" - }, - "name": "lightMeasuredEvent" - } - } - } - } - """, "json"); + json.ShouldBe(ExpectedSpecFiles.Json_v2_6, "json"); } }