diff --git a/docs/site/Writerside/topics/how-to/Use-in-Swagger.md b/docs/site/Writerside/topics/how-to/Use-in-Swagger.md index ae3e44649e..0451091ea9 100644 --- a/docs/site/Writerside/topics/how-to/Use-in-Swagger.md +++ b/docs/site/Writerside/topics/how-to/Use-in-Swagger.md @@ -1,7 +1,7 @@ # Use in Swagger/OpenAPI You can use the value objects generated by Vogen as parameters in ASP.NET Core Web API endpoints. -When an endpoint is run, the .NET runtime will notice the `TypeConverter` that is generated by default, and use that to try +When an endpoint is run, the .NET runtime will notice the `TypeConverter` that is generated by default and use that to try to convert the daa from the request (e.g. `string` or `int`) to the value object. Front end tools, such as Swagger, use an OpenAPI specification to describe the endpoints and the types used in those endpoints. By default, the value objects generated for the OpenAPI document are specified as `object`. For example, for this endpoint: @@ -29,11 +29,13 @@ Both ways include setting a parameter in Vogen's global config: The choices are: `GenerateSwashbuckleMappingExtensionMethod` or `GenerateSwashbuckleSchemaFilter` -The extension method mechanism is preferable to the schema filter mechanism, as the schema filter uses Reflection at runtime, which is unavailable when using AOT (Ahead-Of-Time). +The extension method mechanism is preferable to the schema filter mechanism, as the schema filter uses Reflection at runtime, which is unavailable when using AOT (Ahead-Of-Time). + +This will create a class named `VogenSwashbuckleExtensions` without a namespace (so it'll be in the global namespaces). The class will contain an extension method named `MapVogenTypesInMyWebApp` (`MyWebApp` is the name of your app with illegal characters removed, e.g. `MyApp.Core` will become `MyAppCore`) The extension method that is generated looks like this: ```C# -static SwaggerGenOptions MapVogenTypes(this SwaggerGenOptions o) +SwaggerGenOptions MapVogenTypesInMyWebApp(this SwaggerGenOptions o) { o.MapType(() => new OpenApiSchema { Type = "number" }); o.MapType(() => new OpenApiSchema { Type = "string" }); @@ -43,12 +45,12 @@ static SwaggerGenOptions MapVogenTypes(this SwaggerGenOptions o) You register it like this: ```C# -builder.Services.AddSwaggerGen(opt => opt.MapVogenTypes()); +builder.Services.AddSwaggerGen(opt => opt.MapVogenTypesInMyWebApp()); ``` If your value objects are defined in another project, that project will also need assembly-level Vogen configuration. -Your other project will then emit a source generated extension method named `MapVogenTypes`. +Your other project will then emit a source-generated extension method named `MapVogenTypes`. Because there are now two extension methods with the same signature, you'll need to call them explicitly, e.g. ```c# diff --git a/samples/WebApplication/Program.cs b/samples/WebApplication/Program.cs index f24718264d..021127b824 100644 --- a/samples/WebApplication/Program.cs +++ b/samples/WebApplication/Program.cs @@ -25,9 +25,8 @@ { // the following extension method is available if you specify `GenerateSwashbuckleMappingExtensionMethod` - as shown above - //opt.MapVogenTypes(); - WebApplication.VogenSwashbuckleExtensions.MapVogenTypes(opt); - WebApplication.Shared.VogenSwashbuckleExtensions.MapVogenTypes(opt); + opt.MapVogenTypesInWebApplication(); + opt.MapVogenTypesInWebApplicationShared(); // the following schema filter is generated if you specify GenerateSwashbuckleSchemaFilter as shown above // opt.SchemaFilter(); diff --git a/src/Vogen/GenerateCodeForOpenApiSchemaCustomization.cs b/src/Vogen/GenerateCodeForOpenApiSchemaCustomization.cs index 64fa97a0af..9b70bb96fe 100644 --- a/src/Vogen/GenerateCodeForOpenApiSchemaCustomization.cs +++ b/src/Vogen/GenerateCodeForOpenApiSchemaCustomization.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Text; using Microsoft.CodeAnalysis; +using Vogen.Types; namespace Vogen; @@ -15,22 +16,22 @@ public static void WriteIfNeeded(VogenConfiguration? globalConfig, { var c = globalConfig?.OpenApiSchemaCustomizations ?? VogenConfiguration.DefaultInstance.OpenApiSchemaCustomizations; - var fullNamespace = compilation.Assembly.Name; - - var theNamespace = string.IsNullOrEmpty(fullNamespace) ? string.Empty : $"namespace {fullNamespace};"; + var projectName = ProjectName.FromAssemblyName(compilation.Assembly.Name); + + var inAppendage = string.IsNullOrEmpty(projectName) ? string.Empty : $"In{projectName}"; if (c.HasFlag(OpenApiSchemaCustomizations.GenerateSwashbuckleSchemaFilter)) { - WriteSchemaFilter(context, knownSymbols, theNamespace); + WriteSchemaFilter(context, knownSymbols, inAppendage); } if (c.HasFlag(OpenApiSchemaCustomizations.GenerateSwashbuckleMappingExtensionMethod)) { - WriteExtensionMethodMapping(context, workItems, knownSymbols, theNamespace); + WriteExtensionMethodMapping(context, workItems, knownSymbols, inAppendage); } } - private static void WriteSchemaFilter(SourceProductionContext context, VogenKnownSymbols knownSymbols, string theNamespace) + private static void WriteSchemaFilter(SourceProductionContext context, VogenKnownSymbols knownSymbols, string inAppendage) { if (!IsSwashbuckleReferenced(knownSymbols)) { @@ -42,11 +43,9 @@ private static void WriteSchemaFilter(SourceProductionContext context, VogenKnow {{GeneratedCodeSegments.Preamble}} - {{theNamespace}} - using System.Reflection; - public class VogenSchemaFilter : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter + public class VogenSchemaFilter{{inAppendage}} : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter { private const BindingFlags _flags = BindingFlags.Public | BindingFlags.Instance; @@ -107,7 +106,7 @@ private static void TryCopyPublicProperties(T oldObject, T newObject) where T private static void WriteExtensionMethodMapping(SourceProductionContext context, List workItems, VogenKnownSymbols knownSymbols, - string theNamespace) + string inAppendage) { if (!IsSwashbuckleReferenced(knownSymbols)) { @@ -119,11 +118,9 @@ private static void WriteExtensionMethodMapping(SourceProductionContext context, {{GeneratedCodeSegments.Preamble}} - {{theNamespace}} - public static class VogenSwashbuckleExtensions { - public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypes(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) + public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypes{{inAppendage}}(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) { {{MapWorkItems(workItems)}} diff --git a/src/Vogen/Types/ProjectName.cs b/src/Vogen/Types/ProjectName.cs new file mode 100644 index 0000000000..33a48cf9ae --- /dev/null +++ b/src/Vogen/Types/ProjectName.cs @@ -0,0 +1,20 @@ +namespace Vogen.Types; + +internal class ProjectName +{ + private ProjectName(string value) => Value = value; + + public static ProjectName FromAssemblyName(string assemblyName) + { + assemblyName = assemblyName.Replace(".", ""); + assemblyName = assemblyName.Replace(",", ""); + assemblyName = assemblyName.Replace(" ", ""); + + return new(assemblyName); + } + + public string Value { get; } + + public static implicit operator string(ProjectName name) => name.Value; + public override string ToString() => Value; +} \ No newline at end of file diff --git a/tests/SnapshotTests/BugFixes/snapshots/snap-vAspNetCore8.0/Bug604_Swashbuckle_has_missing_namespaces_for_the_vo.Test.verified.txt b/tests/SnapshotTests/BugFixes/snapshots/snap-vAspNetCore8.0/Bug604_Swashbuckle_has_missing_namespaces_for_the_vo.Test.verified.txt index 8675390deb..3ec5407dda 100644 --- a/tests/SnapshotTests/BugFixes/snapshots/snap-vAspNetCore8.0/Bug604_Swashbuckle_has_missing_namespaces_for_the_vo.Test.verified.txt +++ b/tests/SnapshotTests/BugFixes/snapshots/snap-vAspNetCore8.0/Bug604_Swashbuckle_has_missing_namespaces_for_the_vo.Test.verified.txt @@ -24,11 +24,9 @@ // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; - public static class VogenSwashbuckleExtensions { - public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypes(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) + public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypesIngenerator(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) { global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "integer", Format = "int32", Nullable = false }); global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType>(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "integer", Format = "int32", Nullable = true }); diff --git a/tests/SnapshotTests/BugFixes/snapshots/snap-vAspNetCore8.0/Bug608_swashbuckle_mappingTests.Used_to_treat_non_primitives_as_objects_but_now_treats_IParsable_as_strings.verified.txt b/tests/SnapshotTests/BugFixes/snapshots/snap-vAspNetCore8.0/Bug608_swashbuckle_mappingTests.Used_to_treat_non_primitives_as_objects_but_now_treats_IParsable_as_strings.verified.txt index 6319225068..f248594421 100644 --- a/tests/SnapshotTests/BugFixes/snapshots/snap-vAspNetCore8.0/Bug608_swashbuckle_mappingTests.Used_to_treat_non_primitives_as_objects_but_now_treats_IParsable_as_strings.verified.txt +++ b/tests/SnapshotTests/BugFixes/snapshots/snap-vAspNetCore8.0/Bug608_swashbuckle_mappingTests.Used_to_treat_non_primitives_as_objects_but_now_treats_IParsable_as_strings.verified.txt @@ -24,11 +24,9 @@ // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; - public static class VogenSwashbuckleExtensions { - public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypes(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) + public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypesIngenerator(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) { global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "string", Format = "uuid", Nullable = false }); global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType>(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "string", Format = "uuid", Nullable = true }); diff --git a/tests/SnapshotTests/BugFixes/snapshots/snap-vAspNetCore8.0/Bug610_Inconsistent_casting.Setting_implicit_casting_to_primitive_in_global_config_should_not_write_a_primitive_cast_to_wrapper.verified.txt b/tests/SnapshotTests/BugFixes/snapshots/snap-vAspNetCore8.0/Bug610_Inconsistent_casting.Setting_implicit_casting_to_primitive_in_global_config_should_not_write_a_primitive_cast_to_wrapper.verified.txt index b4773e35bd..7af6bc9fbb 100644 --- a/tests/SnapshotTests/BugFixes/snapshots/snap-vAspNetCore8.0/Bug610_Inconsistent_casting.Setting_implicit_casting_to_primitive_in_global_config_should_not_write_a_primitive_cast_to_wrapper.verified.txt +++ b/tests/SnapshotTests/BugFixes/snapshots/snap-vAspNetCore8.0/Bug610_Inconsistent_casting.Setting_implicit_casting_to_primitive_in_global_config_should_not_write_a_primitive_cast_to_wrapper.verified.txt @@ -18,10 +18,9 @@ #pragma warning disable CS8669, CS8632 // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; using System.Reflection; -public class VogenSchemaFilter : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter +public class VogenSchemaFilterIngenerator : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter { private const BindingFlags _flags = BindingFlags.Public | BindingFlags.Instance; public void Apply(global::Microsoft.OpenApi.Models.OpenApiSchema schema, global::Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) @@ -92,11 +91,9 @@ public class VogenSchemaFilter : global::Swashbuckle.AspNetCore.SwaggerGen.ISche // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; - public static class VogenSwashbuckleExtensions { - public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypes(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) + public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypesIngenerator(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) { global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "integer", Format = "int32", Nullable = false }); global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType>(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "integer", Format = "int32", Nullable = true }); diff --git a/tests/SnapshotTests/GeneralStuff/snapshots/snap-vAspNetCore8.0/GeneralTests.Can_specify_both_swashbuckle_filter_and_MapType_extension_method_generation_for_openapi.verified.txt b/tests/SnapshotTests/GeneralStuff/snapshots/snap-vAspNetCore8.0/GeneralTests.Can_specify_both_swashbuckle_filter_and_MapType_extension_method_generation_for_openapi.verified.txt index 79db3eee15..9976ad9220 100644 --- a/tests/SnapshotTests/GeneralStuff/snapshots/snap-vAspNetCore8.0/GeneralTests.Can_specify_both_swashbuckle_filter_and_MapType_extension_method_generation_for_openapi.verified.txt +++ b/tests/SnapshotTests/GeneralStuff/snapshots/snap-vAspNetCore8.0/GeneralTests.Can_specify_both_swashbuckle_filter_and_MapType_extension_method_generation_for_openapi.verified.txt @@ -18,10 +18,9 @@ #pragma warning disable CS8669, CS8632 // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; using System.Reflection; -public class VogenSchemaFilter : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter +public class VogenSchemaFilterIngenerator : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter { private const BindingFlags _flags = BindingFlags.Public | BindingFlags.Instance; public void Apply(global::Microsoft.OpenApi.Models.OpenApiSchema schema, global::Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) @@ -92,11 +91,9 @@ public class VogenSchemaFilter : global::Swashbuckle.AspNetCore.SwaggerGen.ISche // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; - public static class VogenSwashbuckleExtensions { - public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypes(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) + public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypesIngenerator(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) { global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "integer", Format = "int32", Nullable = false }); global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "number", Nullable = false }); diff --git a/tests/SnapshotTests/GeneralStuff/snapshots/snap-vAspNetCore8.0/GeneralTests.Can_specify_swashbuckle_MapType_extension_method_generation_for_openapi.verified.txt b/tests/SnapshotTests/GeneralStuff/snapshots/snap-vAspNetCore8.0/GeneralTests.Can_specify_swashbuckle_MapType_extension_method_generation_for_openapi.verified.txt index 5c0a02e9c3..91a4275bb6 100644 --- a/tests/SnapshotTests/GeneralStuff/snapshots/snap-vAspNetCore8.0/GeneralTests.Can_specify_swashbuckle_MapType_extension_method_generation_for_openapi.verified.txt +++ b/tests/SnapshotTests/GeneralStuff/snapshots/snap-vAspNetCore8.0/GeneralTests.Can_specify_swashbuckle_MapType_extension_method_generation_for_openapi.verified.txt @@ -24,11 +24,9 @@ // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; - public static class VogenSwashbuckleExtensions { - public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypes(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) + public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypesIngenerator(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) { global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "integer", Format = "int32", Nullable = false }); global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "number", Nullable = false }); diff --git a/tests/SnapshotTests/GeneralStuff/snapshots/snap-vAspNetCore8.0/GeneralTests.Can_specify_swashbuckle_filter_generation_for_openapi.verified.txt b/tests/SnapshotTests/GeneralStuff/snapshots/snap-vAspNetCore8.0/GeneralTests.Can_specify_swashbuckle_filter_generation_for_openapi.verified.txt index b15232c62c..59655fb847 100644 --- a/tests/SnapshotTests/GeneralStuff/snapshots/snap-vAspNetCore8.0/GeneralTests.Can_specify_swashbuckle_filter_generation_for_openapi.verified.txt +++ b/tests/SnapshotTests/GeneralStuff/snapshots/snap-vAspNetCore8.0/GeneralTests.Can_specify_swashbuckle_filter_generation_for_openapi.verified.txt @@ -18,10 +18,9 @@ #pragma warning disable CS8669, CS8632 // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; using System.Reflection; -public class VogenSchemaFilter : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter +public class VogenSchemaFilterIngenerator : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter { private const BindingFlags _flags = BindingFlags.Public | BindingFlags.Instance; public void Apply(global::Microsoft.OpenApi.Models.OpenApiSchema schema, global::Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) diff --git a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_both_filter_and_MapType_extension_method_999bbcbfced9b3f8.verified.txt b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_both_filter_and_MapType_extension_method_999bbcbfced9b3f8.verified.txt index 76d3775538..ef2fd0dd67 100644 --- a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_both_filter_and_MapType_extension_method_999bbcbfced9b3f8.verified.txt +++ b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_both_filter_and_MapType_extension_method_999bbcbfced9b3f8.verified.txt @@ -18,10 +18,9 @@ #pragma warning disable CS8669, CS8632 // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; using System.Reflection; -public class VogenSchemaFilter : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter +public class VogenSchemaFilterIngenerator : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter { private const BindingFlags _flags = BindingFlags.Public | BindingFlags.Instance; public void Apply(global::Microsoft.OpenApi.Models.OpenApiSchema schema, global::Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) @@ -92,11 +91,9 @@ public class VogenSchemaFilter : global::Swashbuckle.AspNetCore.SwaggerGen.ISche // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; - public static class VogenSwashbuckleExtensions { - public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypes(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) + public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypesIngenerator(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) { global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "integer", Format = "int32", Nullable = false }); global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "number", Nullable = false }); diff --git a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_both_filter_and_MapType_extension_method_c61bd4ba08e7d371.verified.txt b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_both_filter_and_MapType_extension_method_c61bd4ba08e7d371.verified.txt index 79db3eee15..9976ad9220 100644 --- a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_both_filter_and_MapType_extension_method_c61bd4ba08e7d371.verified.txt +++ b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_both_filter_and_MapType_extension_method_c61bd4ba08e7d371.verified.txt @@ -18,10 +18,9 @@ #pragma warning disable CS8669, CS8632 // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; using System.Reflection; -public class VogenSchemaFilter : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter +public class VogenSchemaFilterIngenerator : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter { private const BindingFlags _flags = BindingFlags.Public | BindingFlags.Instance; public void Apply(global::Microsoft.OpenApi.Models.OpenApiSchema schema, global::Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) @@ -92,11 +91,9 @@ public class VogenSchemaFilter : global::Swashbuckle.AspNetCore.SwaggerGen.ISche // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; - public static class VogenSwashbuckleExtensions { - public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypes(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) + public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypesIngenerator(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) { global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "integer", Format = "int32", Nullable = false }); global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "number", Nullable = false }); diff --git a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_extension_method_for_mapping_types_32176bb7ed8221dd.verified.txt b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_extension_method_for_mapping_types_32176bb7ed8221dd.verified.txt index 83f7030004..8b5908f553 100644 --- a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_extension_method_for_mapping_types_32176bb7ed8221dd.verified.txt +++ b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_extension_method_for_mapping_types_32176bb7ed8221dd.verified.txt @@ -24,11 +24,9 @@ // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; - public static class VogenSwashbuckleExtensions { - public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypes(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) + public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypesIngenerator(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) { global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType<@double.MyVoInt>(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "integer", Format = "int32", Nullable = false }); global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType<@double.MyVoFloat>(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "number", Nullable = false }); diff --git a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_extension_method_for_mapping_types_999bbcbfced9b3f8.verified.txt b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_extension_method_for_mapping_types_999bbcbfced9b3f8.verified.txt index c1848313a9..0b566950b6 100644 --- a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_extension_method_for_mapping_types_999bbcbfced9b3f8.verified.txt +++ b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_extension_method_for_mapping_types_999bbcbfced9b3f8.verified.txt @@ -24,11 +24,9 @@ // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; - public static class VogenSwashbuckleExtensions { - public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypes(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) + public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypesIngenerator(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) { global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "integer", Format = "int32", Nullable = false }); global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "number", Nullable = false }); diff --git a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_extension_method_for_mapping_types_c61bd4ba08e7d371.verified.txt b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_extension_method_for_mapping_types_c61bd4ba08e7d371.verified.txt index b4224c56b9..eb6435e88e 100644 --- a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_extension_method_for_mapping_types_c61bd4ba08e7d371.verified.txt +++ b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_extension_method_for_mapping_types_c61bd4ba08e7d371.verified.txt @@ -24,11 +24,9 @@ // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; - public static class VogenSwashbuckleExtensions { - public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypes(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) + public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypesIngenerator(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) { global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "integer", Format = "int32", Nullable = false }); global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "number", Nullable = false }); diff --git a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_filter_code_32176bb7ed8221dd.verified.txt b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_filter_code_32176bb7ed8221dd.verified.txt index e7147ace67..abdbf56bc2 100644 --- a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_filter_code_32176bb7ed8221dd.verified.txt +++ b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_filter_code_32176bb7ed8221dd.verified.txt @@ -18,10 +18,9 @@ #pragma warning disable CS8669, CS8632 // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; using System.Reflection; -public class VogenSchemaFilter : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter +public class VogenSchemaFilterIngenerator : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter { private const BindingFlags _flags = BindingFlags.Public | BindingFlags.Instance; public void Apply(global::Microsoft.OpenApi.Models.OpenApiSchema schema, global::Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) diff --git a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_filter_code_999bbcbfced9b3f8.verified.txt b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_filter_code_999bbcbfced9b3f8.verified.txt index 86555c906d..876e3f0fe2 100644 --- a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_filter_code_999bbcbfced9b3f8.verified.txt +++ b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_filter_code_999bbcbfced9b3f8.verified.txt @@ -18,10 +18,9 @@ #pragma warning disable CS8669, CS8632 // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; using System.Reflection; -public class VogenSchemaFilter : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter +public class VogenSchemaFilterIngenerator : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter { private const BindingFlags _flags = BindingFlags.Public | BindingFlags.Instance; public void Apply(global::Microsoft.OpenApi.Models.OpenApiSchema schema, global::Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) diff --git a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_filter_code_c61bd4ba08e7d371.verified.txt b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_filter_code_c61bd4ba08e7d371.verified.txt index b15232c62c..59655fb847 100644 --- a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_filter_code_c61bd4ba08e7d371.verified.txt +++ b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Generates_filter_code_c61bd4ba08e7d371.verified.txt @@ -18,10 +18,9 @@ #pragma warning disable CS8669, CS8632 // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; using System.Reflection; -public class VogenSchemaFilter : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter +public class VogenSchemaFilterIngenerator : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter { private const BindingFlags _flags = BindingFlags.Public | BindingFlags.Instance; public void Apply(global::Microsoft.OpenApi.Models.OpenApiSchema schema, global::Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context) diff --git a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Treats_custom_IParsable_as_string.verified.txt b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Treats_custom_IParsable_as_string.verified.txt index a4f0d856c0..4b2802f3e8 100644 --- a/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Treats_custom_IParsable_as_string.verified.txt +++ b/tests/SnapshotTests/OpenApi/snapshots/snap-vAspNetCore8.0/SwashbuckleTests.Treats_custom_IParsable_as_string.verified.txt @@ -24,11 +24,9 @@ // Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' #pragma warning disable CS1591 -namespace generator; - public static class VogenSwashbuckleExtensions { - public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypes(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) + public static global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions MapVogenTypesIngenerator(this global::Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions o) { global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "string", Nullable = false }); diff --git a/tests/Vogen.Tests/ProjectNameTests.cs b/tests/Vogen.Tests/ProjectNameTests.cs new file mode 100644 index 0000000000..d8b4bb16f3 --- /dev/null +++ b/tests/Vogen.Tests/ProjectNameTests.cs @@ -0,0 +1,22 @@ +using FluentAssertions; +using Vogen.Types; +using Xunit; + +namespace Vogen.Tests; + +public class ProjectNameTests +{ + [Theory] + [InlineData("MyAssembly.Core", "MyAssemblyCore")] + [InlineData("MyAssembly . Core", "MyAssemblyCore")] + [InlineData("My._Projéct_Oh.Yes_It.Is1plɹo_MollǝH", "My_Projéct_OhYes_ItIs1plɹo_MollǝH")] + public void Removes_spaces_commas_and_dots_with_with_underscores(string input, string output) => + ProjectName.FromAssemblyName(input).Value.Should().Be(output); + + [Fact] + public void Implicitly_casts_to_string() + { + string s = ProjectName.FromAssemblyName("MyType"); + s.Should().Be("MyType"); + } +} \ No newline at end of file