-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from GeorgDangl/dev
Merge for next release with Swagger support
- Loading branch information
Showing
20 changed files
with
599 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp3.0;netstandard2.0;net461</TargetFrameworks> | ||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> | ||
<Authors>Georg Dangl</Authors> | ||
<Company /> | ||
<Description>Extensions to use LightQuery with NSwag</Description> | ||
<Copyright>(c) $([System.DateTime]::Now.Year) Georg Dangl</Copyright> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageProjectUrl>https://github.com/GeorgDangl/LightQuery</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/GeorgDangl/LightQuery.git</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<PackageTags>Asp-Net-Core Querying Sorting Filtering</PackageTags> | ||
<PackageIcon>gd_icon_256.png</PackageIcon> | ||
<SignAssembly>true</SignAssembly> | ||
<AssemblyOriginatorKeyFile>LightQuery.NSwag.snk</AssemblyOriginatorKeyFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NSwag.AspNetCore" Version="13.1.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\LightQuery.EntityFrameworkCore\LightQuery.EntityFrameworkCore.csproj" /> | ||
<ProjectReference Include="..\LightQuery\LightQuery.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\gd_icon_256.png" Pack="true" PackagePath="\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using LightQuery.EntityFrameworkCore; | ||
using NSwag; | ||
using NSwag.Generation.Processors; | ||
using NSwag.Generation.Processors.Contexts; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace LightQuery.NSwag | ||
{ | ||
public class LightQueryOperationsProcessor : IOperationProcessor | ||
{ | ||
public bool Process(OperationProcessorContext context) | ||
{ | ||
if (context.MethodInfo.GetCustomAttributes() | ||
.Any(a => a is LightQueryAttribute | ||
|| a is AsyncLightQueryAttribute)) | ||
{ | ||
context.OperationDescription | ||
.Operation | ||
.Parameters | ||
.Add(new OpenApiParameter | ||
{ | ||
Name = "sort", | ||
Kind = OpenApiParameterKind.Query, | ||
Description = "sort", | ||
Schema = new NJsonSchema.JsonSchema | ||
{ | ||
Type = NJsonSchema.JsonObjectType.String | ||
} | ||
}); | ||
context.OperationDescription | ||
.Operation | ||
.Parameters | ||
.Add(new OpenApiParameter | ||
{ | ||
Name = "thenSort", | ||
Kind = OpenApiParameterKind.Query, | ||
Description = "then sort", | ||
Schema = new NJsonSchema.JsonSchema | ||
{ | ||
Type = NJsonSchema.JsonObjectType.String | ||
} | ||
}); | ||
context.OperationDescription | ||
.Operation | ||
.Parameters | ||
.Add(new OpenApiParameter | ||
{ | ||
Name = "pageSize", | ||
Kind = OpenApiParameterKind.Query, | ||
Description = "page size", | ||
Schema = new NJsonSchema.JsonSchema | ||
{ | ||
Type = NJsonSchema.JsonObjectType.Integer | ||
} | ||
}); | ||
context.OperationDescription | ||
.Operation | ||
.Parameters | ||
.Add(new OpenApiParameter | ||
{ | ||
Name = "page", | ||
Kind = OpenApiParameterKind.Query, | ||
Description = "page", | ||
Schema = new NJsonSchema.JsonSchema | ||
{ | ||
Type = NJsonSchema.JsonObjectType.Integer | ||
} | ||
}); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp3.0;netstandard2.0;net461</TargetFrameworks> | ||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> | ||
<Authors>Georg Dangl, Berkay AKÇAY</Authors> | ||
<Company /> | ||
<Description>Extensions to use LightQuery with Swashbuckle</Description> | ||
<Copyright>(c) $([System.DateTime]::Now.Year) Georg Dangl</Copyright> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageProjectUrl>https://github.com/GeorgDangl/LightQuery</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/GeorgDangl/LightQuery.git</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<PackageTags>Asp-Net-Core Querying Sorting Filtering</PackageTags> | ||
<PackageIcon>gd_icon_256.png</PackageIcon> | ||
<SignAssembly>true</SignAssembly> | ||
<AssemblyOriginatorKeyFile>LightQuery.Swashbuckle.snk</AssemblyOriginatorKeyFile> | ||
<!-- This is required, otherwise Swashbuckle would try to generate OpenApi Documents on build | ||
See: https://github.com/domaindrivendev/Swashbuckle/issues/1358 --> | ||
<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\LightQuery.EntityFrameworkCore\LightQuery.EntityFrameworkCore.csproj" /> | ||
<ProjectReference Include="..\LightQuery\LightQuery.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\gd_icon_256.png" Pack="true" PackagePath="\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.Linq; | ||
using System.Reflection; | ||
using LightQuery.EntityFrameworkCore; | ||
using Microsoft.AspNetCore.Mvc.Controllers; | ||
using Microsoft.OpenApi.Any; | ||
using Microsoft.OpenApi.Models; | ||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
namespace LightQuery.Swashbuckle | ||
{ | ||
/// <summary> | ||
/// Generates operation filter for LightQuery's paramters | ||
/// Swashbuckle <see cref="IOperationFilter"/> | ||
/// </summary> | ||
/// <remarks>OpenAPI Support</remarks> | ||
public class LightQueryOperationFilter : IOperationFilter | ||
{ | ||
public void Apply(OpenApiOperation operation, OperationFilterContext context) | ||
{ | ||
if (((ControllerActionDescriptor)context.ApiDescription.ActionDescriptor).MethodInfo.GetCustomAttributes().Any(a => a is AsyncLightQueryAttribute || a is LightQueryAttribute)) | ||
{ | ||
// sort | ||
operation.Parameters.Add(new OpenApiParameter() | ||
{ | ||
Name = "sort", | ||
In = ParameterLocation.Query, | ||
Description = "sort", | ||
Required = false, | ||
Schema = new OpenApiSchema | ||
{ | ||
Type = "string", | ||
Example = new OpenApiString("CreatedAt desc") | ||
} | ||
}); | ||
|
||
// thenSort | ||
operation.Parameters.Add(new OpenApiParameter() | ||
{ | ||
Name = "thenSort", | ||
In = ParameterLocation.Query, | ||
Description = "then sort", | ||
Required = false, | ||
Schema = new OpenApiSchema | ||
{ | ||
Type = "string", | ||
Example = new OpenApiString("UpdatedAt desc") | ||
} | ||
}); | ||
|
||
// pageSize | ||
operation.Parameters.Add(new OpenApiParameter() | ||
{ | ||
Name = "pageSize", | ||
In = ParameterLocation.Query, | ||
Description = "page size", | ||
Required = false, | ||
Schema = new OpenApiSchema | ||
{ | ||
Type = "integer", | ||
Example = new OpenApiInteger(10) | ||
} | ||
}); | ||
|
||
// page | ||
operation.Parameters.Add(new OpenApiParameter() | ||
{ | ||
Name = "page", | ||
In = ParameterLocation.Query, | ||
Description = "page", | ||
Required = false, | ||
Schema = new OpenApiSchema | ||
{ | ||
Type = "integer", | ||
Example = new OpenApiInteger(1) | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.