Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ updates:
- package-ecosystem: nuget
directory: "/"
groups:
coverlet:
patterns:
- coverlet*
Microsoft.OpenApi:
patterns:
- Microsoft.OpenApi*
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<ItemGroup Condition=" '$(PackageReadmeFile)' != '' ">
<None Include="$(MSBuildThisFileDirectory)$(PackageReadmeFile)" Pack="True" PackagePath="" />
</ItemGroup>
<PropertyGroup Condition=" '$(SignAssembly)' == 'true' AND '$(OS)' != 'Windows_NT' ">
<PropertyGroup Condition=" '$(SignAssembly)' == 'true' AND '$(OS)' != !$([MSBuild]::IsOSPlatform('Windows')) ">
<PublicSign>true</PublicSign>
</PropertyGroup>
<PropertyGroup>
Expand Down
14 changes: 7 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ItemGroup>
<PackageVersion Include="Autofac.Extensions.DependencyInjection" Version="10.0.0" />
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.4" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageVersion Include="IdentityServer4" Version="3.1.4" />
<PackageVersion Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
Expand All @@ -23,15 +23,15 @@
<PackageVersion Include="Microsoft.Extensions.FileProviders.Embedded" Version="2.1.0" />
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.22" />
<PackageVersion Include="Microsoft.OpenApi.Readers" Version="1.6.22" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="NSwag.MSBuild" Version="14.2.0" />
<PackageVersion Include="ReportGenerator" Version="5.4.1" />
<PackageVersion Include="ReportGenerator" Version="5.4.4" />
<PackageVersion Include="System.Text.Json" Version="4.6.0" />
<PackageVersion Include="Verify.Xunit" Version="28.3.2" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.core" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="Verify.Xunit" Version="28.16.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.core" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\src\Shared\JsonSchemaTypes.cs" Link="JsonSchemaTypes.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Swashbuckle.AspNetCore.Annotations\Swashbuckle.AspNetCore.Annotations.csproj" />
<ProjectReference Include="..\..\src\Swashbuckle.AspNetCore.SwaggerGen\Swashbuckle.AspNetCore.SwaggerGen.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void Setup()
{
Schema = new()
{
Type = "string",
Type = JsonSchemaTypes.String,
Description = "schema-level description",
},
};
Expand All @@ -120,7 +120,7 @@ public void Setup()
{
Schema = new()
{
Type = "string",
Type = JsonSchemaTypes.String,
},
},
},
Expand Down
12 changes: 12 additions & 0 deletions src/Shared/JsonSchemaTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Swashbuckle.AspNetCore;

internal static class JsonSchemaTypes
{
public const string Array = "array";
public const string Boolean = "boolean";
public const string Integer = "integer";
public const string Number = "number";
public const string Null = "null";
public const string Object = "object";
public const string String = "string";
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ private static void ApplySwaggerOperationAttribute(

if (swaggerOperationAttribute.Tags != null)
{
operation.Tags = swaggerOperationAttribute.Tags
.Select(tagName => new OpenApiTag { Name = tagName })
.ToList();
operation.Tags = [.. swaggerOperationAttribute.Tags.Select(tagName => new OpenApiTag { Name = tagName })];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ Swashbuckle.AspNetCore.Annotations.SwaggerRequestBodyAttribute.SwaggerRequestBod
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute.ContentTypes.get -> string[]
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute.ContentTypes.set -> void
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute.Description.get -> string
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute.Description.set -> void
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute.SwaggerResponseAttribute(int statusCode, string description = null, System.Type type = null) -> void
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute.SwaggerResponseAttribute(int statusCode, string description = null, System.Type type = null, params string[] contentTypes) -> void
Swashbuckle.AspNetCore.Annotations.SwaggerSchemaAttribute
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute.Description.get -> string
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute.Description.set -> void
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute.Description.get -> string
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute.Description.set -> void
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute.Description.get -> string
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute.Description.set -> void
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute.Description.get -> string
Swashbuckle.AspNetCore.Annotations.SwaggerResponseAttribute.Description.set -> void
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@
<AdditionalFiles Include="PublicAPI\PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI\PublicAPI.Unshipped.txt" />
</ItemGroup>
<ItemGroup Condition="Exists('PublicAPI\$(TargetFramework)')">
<AdditionalFiles Include="PublicAPI\$(TargetFramework)\PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI\$(TargetFramework)\PublicAPI.Unshipped.txt" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Swashbuckle.AspNetCore.ApiTesting
{
public class JsonAllOfValidator(JsonValidator jsonValidator) : IJsonValidator
{
private JsonValidator _jsonValidator = jsonValidator;
private readonly JsonValidator _jsonValidator = jsonValidator;

public bool CanValidate(OpenApiSchema schema) => schema.AllOf != null && schema.AllOf.Any();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Swashbuckle.AspNetCore.ApiTesting
{
public class JsonAnyOfValidator(JsonValidator jsonValidator) : IJsonValidator
{
private JsonValidator _jsonValidator = jsonValidator;
private readonly JsonValidator _jsonValidator = jsonValidator;

public bool CanValidate(OpenApiSchema schema) => schema.AnyOf != null && schema.AnyOf.Any();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class JsonArrayValidator(IJsonValidator jsonValidator) : IJsonValidator
{
private readonly IJsonValidator _jsonValidator = jsonValidator;

public bool CanValidate(OpenApiSchema schema) => schema.Type == "array";
public bool CanValidate(OpenApiSchema schema) => schema.Type == JsonSchemaTypes.Array;

public bool Validate(
OpenApiSchema schema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Swashbuckle.AspNetCore.ApiTesting
{
public class JsonBooleanValidator : IJsonValidator
{
public bool CanValidate(OpenApiSchema schema) => schema.Type == "boolean";
public bool CanValidate(OpenApiSchema schema) => schema.Type == JsonSchemaTypes.Boolean;

public bool Validate(
OpenApiSchema schema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Swashbuckle.AspNetCore.ApiTesting
{
public class JsonNullValidator : IJsonValidator
{
public bool CanValidate(OpenApiSchema schema) => schema.Type == "null";
public bool CanValidate(OpenApiSchema schema) => schema.Type == JsonSchemaTypes.Null;

public bool Validate(
OpenApiSchema schema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Swashbuckle.AspNetCore.ApiTesting
{
public class JsonNumberValidator : IJsonValidator
{
public bool CanValidate(OpenApiSchema schema) => schema.Type == "number";
public bool CanValidate(OpenApiSchema schema) => schema.Type == JsonSchemaTypes.Number;

public bool Validate(
OpenApiSchema schema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class JsonObjectValidator(IJsonValidator jsonValidator) : IJsonValidator
{
private readonly IJsonValidator _jsonValidator = jsonValidator;

public bool CanValidate(OpenApiSchema schema) => schema.Type == "object";
public bool CanValidate(OpenApiSchema schema) => schema.Type == JsonSchemaTypes.Object;

public bool Validate(
OpenApiSchema schema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Swashbuckle.AspNetCore.ApiTesting
{
public class JsonStringValidator : IJsonValidator
{
public bool CanValidate(OpenApiSchema schema) => schema.Type == "string";
public bool CanValidate(OpenApiSchema schema) => schema.Type == JsonSchemaTypes.String;

public bool Validate(
OpenApiSchema schema,
Expand Down
60 changes: 37 additions & 23 deletions src/Swashbuckle.AspNetCore.ApiTesting/OpenApiSchemaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,47 @@ internal static bool TryParse(this OpenApiSchema schema, string stringValue, out
{
typedValue = null;

if (schema.Type == "integer" && schema.Format == "int64" && long.TryParse(stringValue, out long longValue))
if (schema.Type == JsonSchemaTypes.Integer && schema.Format == "int64" && long.TryParse(stringValue, out long longValue))
{
typedValue = longValue;

else if (schema.Type == "integer" && int.TryParse(stringValue, out int intValue))
}
else if (schema.Type == JsonSchemaTypes.Integer && int.TryParse(stringValue, out int intValue))
{
typedValue = intValue;

else if (schema.Type == "number" && schema.Format == "double" && double.TryParse(stringValue, out double doubleValue))
}
else if (schema.Type == JsonSchemaTypes.Number && schema.Format == "double" && double.TryParse(stringValue, out double doubleValue))
{
typedValue = doubleValue;

else if (schema.Type == "number" && float.TryParse(stringValue, out float floatValue))
}
else if (schema.Type == JsonSchemaTypes.Number && float.TryParse(stringValue, out float floatValue))
{
typedValue = floatValue;

else if (schema.Type == "string" && schema.Format == "byte" && byte.TryParse(stringValue, out byte byteValue))
}
else if (schema.Type == JsonSchemaTypes.String && schema.Format == "byte" && byte.TryParse(stringValue, out byte byteValue))
{
typedValue = byteValue;

else if (schema.Type == "boolean" && bool.TryParse(stringValue, out bool boolValue))
}
else if (schema.Type == JsonSchemaTypes.Boolean && bool.TryParse(stringValue, out bool boolValue))
{
typedValue = boolValue;

else if (schema.Type == "string" && schema.Format == "date" && DateTime.TryParse(stringValue, out DateTime dateValue))
}
else if (schema.Type == JsonSchemaTypes.String && schema.Format == "date" && DateTime.TryParse(stringValue, out DateTime dateValue))
{
typedValue = dateValue;

else if (schema.Type == "string" && schema.Format == "date-time" && DateTime.TryParse(stringValue, out DateTime dateTimeValue))
}
else if (schema.Type == JsonSchemaTypes.String && schema.Format == "date-time" && DateTime.TryParse(stringValue, out DateTime dateTimeValue))
{
typedValue = dateTimeValue;

else if (schema.Type == "string" && schema.Format == "uuid" && Guid.TryParse(stringValue, out Guid uuidValue))
}
else if (schema.Type == JsonSchemaTypes.String && schema.Format == "uuid" && Guid.TryParse(stringValue, out Guid uuidValue))
{
typedValue = uuidValue;

else if (schema.Type == "string")
}
else if (schema.Type == JsonSchemaTypes.String)
{
typedValue = stringValue;

else if (schema.Type == "array")
}
else if (schema.Type == JsonSchemaTypes.Array)
{
var arrayValue = (schema.Items == null)
? stringValue.Split(',')
Expand All @@ -59,10 +69,14 @@ internal static bool TryParse(this OpenApiSchema schema, string stringValue, out

internal static string TypeIdentifier(this OpenApiSchema schema)
{
var idBuilder = new StringBuilder(schema.Type);
var idBuilder = new StringBuilder();

idBuilder.Append(schema.Type);

if (schema.Type == "array" && schema.Items != null)
if (schema.Type == JsonSchemaTypes.Array && schema.Items != null)
{
idBuilder.Append($"[{schema.Items.Type}]");
}

return idBuilder.ToString();
}
Expand Down
12 changes: 6 additions & 6 deletions src/Swashbuckle.AspNetCore.ApiTesting/RequestValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ private static IEnumerable<OpenApiParameter> ExpandParameterSpecs(
.Concat(operationSpec.Parameters)
.Select(p =>
{
return p.Reference != null
? (OpenApiParameter)openApiDocument.ResolveReference(p.Reference)
return p.Reference != null ?
(OpenApiParameter)openApiDocument.ResolveReference(p.Reference)
: p;
});
}
Expand Down Expand Up @@ -112,8 +112,8 @@ private static void ValidateParameters(
continue;
}

var schema = (parameterSpec.Schema.Reference != null)
? (OpenApiSchema)openApiDocument.ResolveReference(parameterSpec.Schema.Reference)
var schema = (parameterSpec.Schema.Reference != null) ?
(OpenApiSchema)openApiDocument.ResolveReference(parameterSpec.Schema.Reference)
: parameterSpec.Schema;

if (!schema.TryParse(value, out object typedValue))
Expand All @@ -125,8 +125,8 @@ private static void ValidateParameters(

private void ValidateContent(OpenApiRequestBody requestBodySpec, OpenApiDocument openApiDocument, HttpContent content)
{
requestBodySpec = requestBodySpec.Reference != null
? (OpenApiRequestBody)openApiDocument.ResolveReference(requestBodySpec.Reference)
requestBodySpec = requestBodySpec.Reference != null ?
(OpenApiRequestBody)openApiDocument.ResolveReference(requestBodySpec.Reference)
: requestBodySpec;

if (requestBodySpec.Required && content == null)
Expand Down
4 changes: 2 additions & 2 deletions src/Swashbuckle.AspNetCore.ApiTesting/ResponseValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ private static void ValidateHeaders(
continue;
}

var schema = (headerSpec.Schema.Reference != null)
? (OpenApiSchema)openApiDocument.ResolveReference(headerSpec.Schema.Reference)
var schema = (headerSpec.Schema.Reference != null) ?
(OpenApiSchema)openApiDocument.ResolveReference(headerSpec.Schema.Reference)
: headerSpec.Schema;

if (value == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@
<AdditionalFiles Include="PublicAPI\PublicAPI.Unshipped.txt" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Shared\JsonSchemaTypes.cs" Link="JsonSchemaTypes.cs" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions src/Swashbuckle.AspNetCore.SwaggerGen/JsonModelFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.OpenApi.Any;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Swashbuckle.AspNetCore;

internal static class JsonModelFactory
{
public static IOpenApiAny CreateFromJson(string json)
=> OpenApiAnyFactory.CreateFromJson(json);
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ static Swashbuckle.AspNetCore.SwaggerGen.MemberInfoExtensions.GetInlineAndMetada
static Swashbuckle.AspNetCore.SwaggerGen.MemberInfoExtensions.IsDictionaryValueNonNullable(this System.Reflection.MemberInfo memberInfo) -> bool
static Swashbuckle.AspNetCore.SwaggerGen.MemberInfoExtensions.IsNonNullableReferenceType(this System.Reflection.MemberInfo memberInfo) -> bool
static Swashbuckle.AspNetCore.SwaggerGen.MethodInfoExtensions.GetUnderlyingGenericTypeMethod(this System.Reflection.MethodInfo constructedTypeMethod) -> System.Reflection.MethodInfo
static Swashbuckle.AspNetCore.SwaggerGen.OpenApiAnyFactory.CreateFromJson(string json) -> Microsoft.OpenApi.Any.IOpenApiAny
static Swashbuckle.AspNetCore.SwaggerGen.OpenApiAnyFactory.CreateFromJson(string json, System.Text.Json.JsonSerializerOptions options) -> Microsoft.OpenApi.Any.IOpenApiAny
static Swashbuckle.AspNetCore.SwaggerGen.OpenApiSchemaExtensions.ApplyRouteConstraints(this Microsoft.OpenApi.Models.OpenApiSchema schema, Microsoft.AspNetCore.Mvc.ApiExplorer.ApiParameterRouteInfo routeInfo) -> void
static Swashbuckle.AspNetCore.SwaggerGen.OpenApiSchemaExtensions.ApplyValidationAttributes(this Microsoft.OpenApi.Models.OpenApiSchema schema, System.Collections.Generic.IEnumerable<object> customAttributes) -> void
static Swashbuckle.AspNetCore.SwaggerGen.OpenApiSchemaExtensions.ResolveType(this Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaRepository schemaRepository) -> string
static Swashbuckle.AspNetCore.SwaggerGen.PropertyInfoExtensions.HasAttribute<TAttribute>(this System.Reflection.PropertyInfo property) -> bool
static Swashbuckle.AspNetCore.SwaggerGen.PropertyInfoExtensions.IsPubliclyReadable(this System.Reflection.PropertyInfo property) -> bool
static Swashbuckle.AspNetCore.SwaggerGen.PropertyInfoExtensions.IsPubliclyWritable(this System.Reflection.PropertyInfo property) -> bool
Expand Down Expand Up @@ -168,7 +165,6 @@ Swashbuckle.AspNetCore.SwaggerGen.JsonSerializerDataContractResolver.IsSupported
Swashbuckle.AspNetCore.SwaggerGen.JsonSerializerDataContractResolver.JsonSerializerDataContractResolver(System.Text.Json.JsonSerializerOptions serializerOptions) -> void
Swashbuckle.AspNetCore.SwaggerGen.MemberInfoExtensions
Swashbuckle.AspNetCore.SwaggerGen.MethodInfoExtensions
Swashbuckle.AspNetCore.SwaggerGen.OpenApiAnyFactory
Swashbuckle.AspNetCore.SwaggerGen.OpenApiSchemaExtensions
Swashbuckle.AspNetCore.SwaggerGen.OperationFilterContext
Swashbuckle.AspNetCore.SwaggerGen.OperationFilterContext.ApiDescription.get -> Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
static Swashbuckle.AspNetCore.SwaggerGen.OpenApiAnyFactory.CreateFromJson(string json) -> Microsoft.OpenApi.Any.IOpenApiAny
Swashbuckle.AspNetCore.SwaggerGen.OpenApiAnyFactory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
static Swashbuckle.AspNetCore.SwaggerGen.OpenApiAnyFactory.CreateFromJson(string json, System.Text.Json.JsonSerializerOptions options) -> Microsoft.OpenApi.Any.IOpenApiAny
static Swashbuckle.AspNetCore.SwaggerGen.OpenApiSchemaExtensions.ResolveType(this Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaRepository schemaRepository) -> string
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
static Swashbuckle.AspNetCore.SwaggerGen.OpenApiAnyFactory.CreateFromJson(string json) -> Microsoft.OpenApi.Any.IOpenApiAny
Swashbuckle.AspNetCore.SwaggerGen.OpenApiAnyFactory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
static Swashbuckle.AspNetCore.SwaggerGen.OpenApiAnyFactory.CreateFromJson(string json, System.Text.Json.JsonSerializerOptions options) -> Microsoft.OpenApi.Any.IOpenApiAny
static Swashbuckle.AspNetCore.SwaggerGen.OpenApiSchemaExtensions.ResolveType(this Microsoft.OpenApi.Models.OpenApiSchema schema, Swashbuckle.AspNetCore.SwaggerGen.SchemaRepository schemaRepository) -> string
Loading