Skip to content

Commit 7803fa9

Browse files
committed
feat: Update Intent.AspNetCore.Swashbuckle to version 5.2.0
- Improved schema identifier generation to ensure OpenAPI compliance. - Updated NuGet package versions, including Swashbuckle dependencies. - Added new XML files for application deviations and output logs. - Introduced a new method for schema ID selection to enhance identifier formatting. - Updated release notes to reflect changes and provide usage notes for schema identifiers.
1 parent 1427c66 commit 7803fa9

File tree

13 files changed

+238
-70
lines changed

13 files changed

+238
-70
lines changed

Modules/Intent.Modules.AspNetCore.Scalar/Intent.AspNetCore.Scalar.imodspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<package>
33
<id>Intent.AspNetCore.Scalar</id>
4-
<version>1.0.2-pre.0</version>
4+
<version>1.0.2-pre.1</version>
55
<supportedClientVersions>[4.3.0-a,5.0.0)</supportedClientVersions>
66
<summary>Provides OpenApi support for using the Scalar library for ASP.NET Core.</summary>
77
<description>Provides OpenApi support for using the Scalar library for ASP.NET Core.</description>

Modules/Intent.Modules.AspNetCore.Scalar/Intent.Metadata/Module Builder/Intent.AspNetCore.Scalar/Elements/NuGet Package/Microsoft.AspNetCore.OpenApi__j1kvmt9x.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</childElement>
6666
<childElement id="3a219169-0fac-4d98-8b7e-43cdfc076f96" type="Package Version" typeId="231f8cf8-517b-4801-9682-991d22f4e662">
6767
<name>8.0.20</name>
68-
<display>8.0.19 ( &gt;= .NETCoreApp,Version=v8.0 )</display>
68+
<display>8.0.20 ( &gt;= .NETCoreApp,Version=v8.0 )</display>
6969
<isAbstract>false</isAbstract>
7070
<sort-children>by-type-then-by-name</sort-children>
7171
<genericTypes />
@@ -88,11 +88,14 @@
8888
<childElements>
8989
<childElement id="4bdd121e-1ca9-49ee-8f73-4486f9e4d6f3" type="NuGet Dependency" typeId="3097322a-a058-4058-beed-4fcd6272f61d">
9090
<name>Microsoft.OpenApi</name>
91+
<display>Microsoft.OpenApi (1.4.3)</display>
9192
<isAbstract>false</isAbstract>
9293
<value>1.4.3</value>
9394
<genericTypes />
9495
<isMapped>false</isMapped>
9596
<parentFolderId>3a219169-0fac-4d98-8b7e-43cdfc076f96</parentFolderId>
97+
<packageId>26ad62ab-3eab-479d-be93-ac6c6cd8046c</packageId>
98+
<packageName>Intent.AspNetCore.Scalar</packageName>
9699
<stereotypes />
97100
<metadata />
98101
<childElements />
@@ -101,7 +104,7 @@
101104
</childElement>
102105
<childElement id="5efb9258-95e3-4bb5-aeea-09d90ec7a88a" type="Package Version" typeId="231f8cf8-517b-4801-9682-991d22f4e662">
103106
<name>9.0.9</name>
104-
<display>9.0.8 ( &gt;= .NETCoreApp,Version=v9.0 )</display>
107+
<display>9.0.9 ( &gt;= .NETCoreApp,Version=v9.0 )</display>
105108
<isAbstract>false</isAbstract>
106109
<sort-children>by-type-then-by-name</sort-children>
107110
<genericTypes />
@@ -124,11 +127,14 @@
124127
<childElements>
125128
<childElement id="934ce7d1-d5ef-4b09-8a81-c9194143b9d0" type="NuGet Dependency" typeId="3097322a-a058-4058-beed-4fcd6272f61d">
126129
<name>Microsoft.OpenApi</name>
130+
<display>Microsoft.OpenApi (1.6.17)</display>
127131
<isAbstract>false</isAbstract>
128132
<value>1.6.17</value>
129133
<genericTypes />
130134
<isMapped>false</isMapped>
131135
<parentFolderId>5efb9258-95e3-4bb5-aeea-09d90ec7a88a</parentFolderId>
136+
<packageId>26ad62ab-3eab-479d-be93-ac6c6cd8046c</packageId>
137+
<packageName>Intent.AspNetCore.Scalar</packageName>
132138
<stereotypes />
133139
<metadata />
134140
<childElements />

Modules/Intent.Modules.AspNetCore.Scalar/Intent.Metadata/Module Builder/Intent.AspNetCore.Scalar/Elements/NuGet Package/Scalar.AspNetCore__h50w7q8t.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<childElements>
2727
<childElement id="9916f3fc-385b-4ebb-815a-5cd510b0755d" type="Package Version" typeId="231f8cf8-517b-4801-9682-991d22f4e662">
2828
<name>2.8.10</name>
29-
<display>2.7.2 ( &gt;= .NETCoreApp,Version=v9.0 )</display>
29+
<display>2.8.10 ( &gt;= .NETCoreApp,Version=v9.0 )</display>
3030
<isAbstract>false</isAbstract>
3131
<genericTypes />
3232
<isMapped>false</isMapped>
@@ -49,7 +49,7 @@
4949
</childElement>
5050
<childElement id="31cf42f6-5485-4f54-ac97-d9ae55294517" type="Package Version" typeId="231f8cf8-517b-4801-9682-991d22f4e662">
5151
<name>2.8.10</name>
52-
<display>2.7.2 ( &gt;= .NETCoreApp,Version=v8.0 )</display>
52+
<display>2.8.10 ( &gt;= .NETCoreApp,Version=v8.0 )</display>
5353
<isAbstract>false</isAbstract>
5454
<genericTypes />
5555
<isMapped>false</isMapped>

Modules/Intent.Modules.AspNetCore.Scalar/Intent.Metadata/Module Builder/Intent.AspNetCore.Scalar/Intent.AspNetCore.Scalar.pkg.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<definitionPackageName>Intent.ModuleBuilder</definitionPackageName>
3232
<definitionPackageId>9972b2a9-b749-4bba-b5c8-824bf694c6ef</definitionPackageId>
3333
<properties>
34-
<property name="4bb9695b-6004-46e1-acea-c48c60c5f8ce" display="Version" value="1.0.1" isActive="true" />
34+
<property name="4bb9695b-6004-46e1-acea-c48c60c5f8ce" display="Version" value="1.0.2-pre.1" isActive="true" />
3535
<property name="177a2415-e749-46e7-8257-440e19ecfb5e" display="API Namespace" isActive="true" />
3636
<property name="0d2ae582-090e-42d6-a7d6-689144433254" display="NuGet Package Id" isActive="true" />
3737
<property name="27cf6544-a9a2-4992-9fef-51d0ed49e66e" display="NuGet Package Version" value="" isActive="true" />

Modules/Intent.Modules.AspNetCore.Scalar/Templates/OpenApiConfiguration/OpenApiConfigurationTemplatePartial.cs

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public OpenApiConfigurationTemplate(IOutputTarget outputTarget, object model = n
4949
.AddUsing("Microsoft.OpenApi.Models")
5050
.AddUsing("Microsoft.Extensions.DependencyInjection")
5151
.AddUsing("System")
52+
.AddUsing("System.Linq")
5253
.AddUsing("System.Threading.Tasks")
5354
.AddUsing("System.Collections.Generic")
5455
.AddClass($"OpenApiConfiguration", @class =>
@@ -65,21 +66,19 @@ public OpenApiConfigurationTemplate(IOutputTarget outputTarget, object model = n
6566
.AddArgument(new CSharpLambdaBlock("options"), argument =>
6667
{
6768
var lambdaBlock = (CSharpLambdaBlock)argument;
68-
if (ExecutionContext.GetSettings().GetScalarSettings().UseFullyQualifiedSchemaIdentifiers())
69-
{
70-
lambdaBlock.AddStatement(new CSharpInvocationStatement("options.AddSchemaTransformer")
71-
.AddArgument(new CSharpLambdaBlock("(schema, context, cancellationToken)"), configure =>
72-
{
73-
configure.AddIfStatement("context.JsonTypeInfo.Type.IsValueType || context.JsonTypeInfo.Type == typeof(String) || context.JsonTypeInfo.Type == typeof(string)", @if => @if.AddReturn("Task.CompletedTask"));
74-
configure.AddIfStatement("schema.Annotations == null || !schema.Annotations.TryGetValue(\"x-schema-id\", out object? _)", @if => @if.AddReturn("Task.CompletedTask"));
69+
70+
lambdaBlock.AddStatement(new CSharpInvocationStatement("options.AddSchemaTransformer")
71+
.AddArgument(new CSharpLambdaBlock("(schema, context, cancellationToken)"), configure =>
72+
{
73+
configure.AddIfStatement("context.JsonTypeInfo.Type.IsValueType || context.JsonTypeInfo.Type == typeof(String) || context.JsonTypeInfo.Type == typeof(string)", @if => @if.AddReturn("Task.CompletedTask"));
74+
configure.AddIfStatement("schema.Annotations == null || !schema.Annotations.TryGetValue(\"x-schema-id\", out object? _)", @if => @if.AddReturn("Task.CompletedTask"));
7575

76-
configure.AddStatement("string? transformedTypeName = context.JsonTypeInfo.Type.FullName?.Replace(\"+\", \".\", StringComparison.Ordinal);");
77-
configure.AddStatement("schema.Annotations[\"x-schema-id\"] = transformedTypeName;");
78-
configure.AddStatement("schema.Title = transformedTypeName;");
76+
configure.AddStatement("var schemaId = SchemaIdSelector(context.JsonTypeInfo.Type);", s => s.SeparatedFromPrevious());
77+
configure.AddStatement("schema.Annotations[\"x-schema-id\"] = schemaId;");
78+
configure.AddStatement("schema.Title = schemaId;");
7979

80-
configure.AddStatement("return Task.CompletedTask;");
81-
}).WithArgumentsOnNewLines());
82-
}
80+
configure.AddStatement("return Task.CompletedTask;", s => s.SeparatedFromPrevious());
81+
}).WithArgumentsOnNewLines());
8382

8483
lambdaBlock.AddStatement(new CSharpInvocationStatement("options.AddDocumentTransformer")
8584
.AddArgument(new CSharpLambdaBlock("(document, context, cancellationToken)"), configure =>
@@ -145,6 +144,66 @@ public OpenApiConfigurationTemplate(IOutputTarget outputTarget, object model = n
145144
);
146145
configureOpenApi.AddReturn("services");
147146
});
147+
148+
if (ExecutionContext.GetSettings().GetScalarSettings().UseFullyQualifiedSchemaIdentifiers())
149+
{
150+
@class.AddMethod("string", "SchemaIdSelector", method =>
151+
{
152+
method.Private().Static();
153+
method.AddParameter(UseType("System.Type"), "modelType");
154+
155+
method.AddIfStatement("modelType.IsArray", @if =>
156+
{
157+
@if.AddStatement(@"var elementType = modelType.GetElementType()!;");
158+
@if.AddStatement(@"return $""{SchemaIdSelector(elementType)}Array"";");
159+
});
160+
161+
method.AddStatement(@"var typeName = modelType.FullName?.Replace(""+"", ""_"") ?? modelType.Name.Replace(""+"", ""_"");", s => s.SeparatedFromPrevious());
162+
163+
method.AddIfStatement("!modelType.IsConstructedGenericType", @if =>
164+
{
165+
@if.AddStatement("return typeName;");
166+
});
167+
168+
method.AddStatement(@"var genericTypeDefName = modelType.GetGenericTypeDefinition().FullName;", s => s.SeparatedFromPrevious());
169+
method.AddStatement(@"var baseName = (genericTypeDefName?.Split('`')[0] ?? modelType.Name.Split('`')[0]).Replace(""+"", ""_"");");
170+
171+
method.AddStatement(@"var genericArgs = modelType.GetGenericArguments()
172+
.Select(SchemaIdSelector)
173+
.ToArray();", s => s.SeparatedFromPrevious());
174+
175+
method.AddStatement(@"return $""{baseName}_Of_{string.Join(""_And_"", genericArgs)}"";", s => s.SeparatedFromPrevious());
176+
});
177+
}
178+
else
179+
{
180+
@class.AddMethod("string", "SchemaIdSelector", method =>
181+
{
182+
method.Private().Static();
183+
method.AddParameter(UseType("System.Type"), "modelType");
184+
185+
method.AddIfStatement("modelType.IsArray", @if =>
186+
{
187+
@if.AddStatement(@"var elementType = modelType.GetElementType()!;");
188+
@if.AddStatement(@"return $""{SchemaIdSelector(elementType)}Array"";");
189+
});
190+
191+
method.AddStatement(@"var modelName = modelType.Name.Replace(""+"", ""_"");", s => s.SeparatedFromPrevious());
192+
193+
method.AddIfStatement("!modelType.IsConstructedGenericType", @if =>
194+
{
195+
@if.AddStatement("return modelName;");
196+
});
197+
198+
method.AddStatement(@"var baseName = modelName.Split('`').First();", s => s.SeparatedFromPrevious());
199+
200+
method.AddStatement(@"var genericArgs = modelType.GetGenericArguments()
201+
.Select(SchemaIdSelector)
202+
.ToArray();", s => s.SeparatedFromPrevious());
203+
204+
method.AddStatement(@"return $""{baseName}Of{string.Join(""And"", genericArgs)}"";", s => s.SeparatedFromPrevious());
205+
});
206+
}
148207
});
149208
}
150209

Modules/Intent.Modules.AspNetCore.Scalar/release-notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
### Version 1.0.2
22

33
- Improvement: Updated NuGet package versions.
4+
- Fixed: Aligned with `Intent.AspNetCore.Swashbuckle` so that Schema identifier generation to ensure generated swagger schema is OpenAPI compliant.
5+
6+
> ⚠️ NOTE
7+
>
8+
> When using simple schema identifiers, generic types will use `Of` and `And` to separate generic types and parameters.
9+
> When using full-namespace identifiers, the identifier will use `_Of_` and `_And_` to separate generic types and parameters.
410
511
### Version 1.0.1
612

Modules/Intent.Modules.AspNetCore.Swashbuckle/AspNetCore.Swashbuckle.application.deviations.log.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<approvedByDisplayName>Joel Turner</approvedByDisplayName>
1313
<approvedAt>2024-08-20T11:54:01.6387799Z</approvedAt>
1414
<deviationsHash>4CBB3166FB45F3EF7CB4B8D6387CA98B886C20293F5FB816802BC1C9C02E9946</deviationsHash>
15-
<fileHash>7ABAE2E555BE4BFBD1A688E66C90180D059FEA10C319E20ADDBC9DE0534EA1E0</fileHash>
15+
<fileHash>646CD49D6D220D5414AF9F51EA5D079D6AA41FC7382F63C7853C792A7FC63597</fileHash>
1616
</file>
1717
<file>
1818
<correlationId>Intent.ModuleBuilder.TemplateRegistration.SingleFileNoModel#f9817e5f-293b-47bb-895e-22d387b7c6f0</correlationId>

Modules/Intent.Modules.AspNetCore.Swashbuckle/Intent.AspNetCore.Swashbuckle.imodspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<package>
33
<id>Intent.AspNetCore.Swashbuckle</id>
4-
<version>5.1.12-pre.0</version>
4+
<version>5.2.0-pre.0</version>
55
<supportedClientVersions>[4.5.15-a, 5.0.0-a)</supportedClientVersions>
66
<summary>Provides Swagger support for using the Swashbuckle library for ASP.NET Core.</summary>
77
<description>Provides Swagger support for using the Swashbuckle library for ASP.NET Core.</description>

0 commit comments

Comments
 (0)