Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d461fed

Browse files
committed
Update to latest OpenAPI
1 parent 7421e2f commit d461fed

40 files changed

+541
-353
lines changed

‎package-versions.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@
3434
<PropertyGroup Condition="'$(TargetFramework)' == 'net10.0'">
3535
<!-- Published dependencies (only update on major version change) -->
3636
<EntityFrameworkCoreFrozenVersion>10.0.*-*</EntityFrameworkCoreFrozenVersion>
37+
<SwashbuckleFrozenVersion>9.0.0-pr.3283.*</SwashbuckleFrozenVersion>
3738

3839
<!-- Non-published dependencies (these are safe to update, won't cause a breaking change) -->
3940
<AspNetCoreVersion>10.0.*-*</AspNetCoreVersion>
41+
<SwashbuckleVersion>9.0.0-pr.3283.*</SwashbuckleVersion>
42+
<MicrosoftOpenApiVersion>2.0.0-preview.21</MicrosoftOpenApiVersion>
43+
<MicrosoftApiServerVersion>10.0.*-*</MicrosoftApiServerVersion>
4044
<EntityFrameworkCoreVersion>10.0.*-*</EntityFrameworkCoreVersion>
4145
<EntityFrameworkCorePomeloVersion>9.0.*-*</EntityFrameworkCorePomeloVersion>
4246
</PropertyGroup>

‎src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
3+
<TargetFrameworks>net10.0</TargetFrameworks>
44
<OpenApiGenerateDocumentsOnBuild>true</OpenApiGenerateDocumentsOnBuild>
55
<OpenApiDocumentsDirectory>GeneratedSwagger</OpenApiDocumentsDirectory>
66
</PropertyGroup>

‎src/Examples/JsonApiDotNetCoreExample/SetOpenApiServerAtBuildTimeFilter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
1616
{
1717
if (_httpContextAccessor.HttpContext == null)
1818
{
19+
swaggerDoc.Servers ??= [];
20+
1921
swaggerDoc.Servers.Add(new OpenApiServer
2022
{
2123
Url = "https://localhost:44340"

‎src/JsonApiDotNetCore.OpenApi.Swashbuckle/ConfigureSwaggerGenOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public void Configure(SwaggerGenOptions options)
7474
options.DocumentFilter<StringEnumOrderingFilter>();
7575
options.DocumentFilter<SetSchemaTypeToObjectDocumentFilter>();
7676
options.DocumentFilter<UnusedComponentSchemaCleaner>();
77+
options.DocumentFilter<SortSchemasFilter>();
78+
options.DocumentFilter<RemoveTagsFilter>();
7779
}
7880

7981
private List<Type> SelectDerivedTypes(Type baseType)

‎src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiDotNetCore.OpenApi.Swashbuckle.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net10.0;net8.0</TargetFrameworks>
3+
<TargetFrameworks>net10.0</TargetFrameworks>
44
<IsPackable>true</IsPackable>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
66
<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
@@ -33,6 +33,7 @@
3333
</ItemGroup>
3434

3535
<ItemGroup>
36+
<PackageReference Include="Microsoft.OpenApi" Version="$(MicrosoftOpenApiVersion)" />
3637
<PackageReference Include="SauceControl.InheritDoc" Version="$(InheritDocVersion)" PrivateAssets="All" />
3738
<PackageReference Include="Swashbuckle.AspNetCore" Version="$(SwashbuckleFrozenVersion)" />
3839
</ItemGroup>

‎src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiSchemaIdSelector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public string GetSchemaId(Type type)
120120

121121
private string ApplySchemaTemplate(string schemaTemplate, ResourceType? resourceType, string? relationshipName, AtomicOperationCode? operationCode)
122122
{
123-
string schemaId = schemaTemplate;
123+
string? schemaId = schemaTemplate;
124124

125125
schemaId = resourceType != null
126126
? schemaId.Replace("[ResourceName]", resourceType.PublicName.Singularize()).Pascalize()
@@ -136,7 +136,7 @@ private string ApplySchemaTemplate(string schemaTemplate, ResourceType? resource
136136
schemaId = schemaId.Replace("[OperationCode]", operationCode.Value.ToString().Pascalize());
137137
}
138138

139-
string pascalCaseSchemaId = schemaId.Pascalize();
139+
string? pascalCaseSchemaId = schemaId.Pascalize();
140140

141141
JsonNamingPolicy? namingPolicy = _options.SerializerOptions.PropertyNamingPolicy;
142142
return namingPolicy != null ? namingPolicy.ConvertName(pascalCaseSchemaId) : pascalCaseSchemaId;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.OpenApi.Models;
2+
3+
namespace JsonApiDotNetCore.OpenApi.Swashbuckle;
4+
5+
internal static class MicrosoftOpenApiCompatibilityExtensions
6+
{
7+
public static void SetNullable(this OpenApiSchema schema, bool nullable)
8+
{
9+
ArgumentNullException.ThrowIfNull(schema);
10+
11+
if (nullable)
12+
{
13+
schema.Type ??= JsonSchemaType.Null;
14+
schema.Type |= JsonSchemaType.Null;
15+
}
16+
else
17+
{
18+
if (schema.Type != null)
19+
{
20+
schema.Type &= ~JsonSchemaType.Null;
21+
}
22+
}
23+
}
24+
}

‎src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiDescriptionLinkProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public OpenApiDescriptionLinkProvider(IOptionsMonitor<SwaggerGeneratorOptions> s
3030

3131
if (swaggerGeneratorOptions.SwaggerDocs.Count > 0)
3232
{
33-
string latestVersionDocumentName = swaggerGeneratorOptions.SwaggerDocs.Last().Key;
33+
string? latestVersionDocumentName = swaggerGeneratorOptions.SwaggerDocs.Last().Key;
3434

3535
SwaggerOptions swaggerOptions = _swaggerOptionsMonitor.CurrentValue;
3636
return swaggerOptions.RouteTemplate.Replace("{documentName}", latestVersionDocumentName).Replace("{extension:regex(^(json|ya?ml)$)}", "json");

‎src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiOperationIdSelector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private string ApplyTemplate(string openApiOperationIdTemplate, ResourceType? re
9494
// @formatter:wrap_chained_method_calls chop_always
9595
// @formatter:wrap_before_first_method_call true
9696

97-
string pascalCaseOpenApiOperationId = openApiOperationIdTemplate
97+
string? pascalCaseOpenApiOperationId = openApiOperationIdTemplate
9898
.Replace("[Method]", method)
9999
.Replace("[PrimaryResourceName]", resourceType?.PublicName.Singularize())
100100
.Replace("[RelationshipName]", relationshipName)

‎src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiSchemaExtensions.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.OpenApi.Models;
2+
using Microsoft.OpenApi.Models.Interfaces;
23

34
namespace JsonApiDotNetCore.OpenApi.Swashbuckle;
45

@@ -9,22 +10,23 @@ public static void ReorderProperties(this OpenApiSchema fullSchema, IEnumerable<
910
ArgumentNullException.ThrowIfNull(fullSchema);
1011
ArgumentNullException.ThrowIfNull(propertyNamesInOrder);
1112

12-
var propertiesInOrder = new Dictionary<string, OpenApiSchema>();
13+
var propertiesInOrder = new Dictionary<string, IOpenApiSchema>();
1314

1415
foreach (string propertyName in propertyNamesInOrder)
1516
{
16-
if (fullSchema.Properties.TryGetValue(propertyName, out OpenApiSchema? schema))
17+
if (fullSchema.Properties!=null&&fullSchema.Properties.TryGetValue(propertyName, out IOpenApiSchema? schema))
1718
{
1819
propertiesInOrder.Add(propertyName, schema);
1920
}
2021
}
2122

23+
ConsistencyGuard.ThrowIf(fullSchema.Properties == null);
2224
ConsistencyGuard.ThrowIf(fullSchema.Properties.Count != propertiesInOrder.Count);
2325

2426
fullSchema.Properties = propertiesInOrder;
2527
}
2628

27-
public static OpenApiSchema WrapInExtendedSchema(this OpenApiSchema source)
29+
public static OpenApiSchema WrapInExtendedSchema(this IOpenApiSchema source)
2830
{
2931
ArgumentNullException.ThrowIfNull(source);
3032

@@ -34,11 +36,11 @@ public static OpenApiSchema WrapInExtendedSchema(this OpenApiSchema source)
3436
};
3537
}
3638

37-
public static OpenApiSchema UnwrapLastExtendedSchema(this OpenApiSchema source)
39+
public static IOpenApiSchema UnwrapLastExtendedSchema(this IOpenApiSchema source)
3840
{
3941
ArgumentNullException.ThrowIfNull(source);
4042

41-
if (source.AllOf is { Count: > 0 })
43+
if (sourceisOpenApiSchema&&source.AllOf is { Count: > 0 })
4244
{
4345
return source.AllOf.Last();
4446
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /