Skip to content

Commit

Permalink
Merge pull request #8 from GeorgDangl/dev
Browse files Browse the repository at this point in the history
Merge for next release with Swagger support
  • Loading branch information
GeorgDangl authored Jun 1, 2020
2 parents b49b3a2 + 5ca1936 commit c0d4e12
Show file tree
Hide file tree
Showing 20 changed files with 599 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

All notable changes to **LightQuery** are documented here.

## v1.9.0:
- Addition of the **LightQuery.Swashbuckle** (thanks to GitHub user @berkayakcay) and **LightQuery.NSwag** packages to support Swagger & OpenAPI generation

## v1.8.1:
- The Angular library was updateds to be compatible with Angular v9.1
- The Angular library was updated to be compatible with Angular v9.1

## v1.8.0:
- Add a `thenSort` parameter to specify a second sort option. This translates to something like `queryable.OrderBy(sort).ThenBy(thenSort)`
Expand Down
18 changes: 16 additions & 2 deletions LightQuery.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2005
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LightQuery", "src\LightQuery\LightQuery.csproj", "{33650DEE-5957-45BA-AFE4-2AFEA731DA4D}"
EndProject
Expand Down Expand Up @@ -45,6 +45,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LightQuery.Shared.Tests", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = ".build", "build\.build.csproj", "{506E6C78-4821-4269-A19A-7B60900EFBC6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LightQuery.NSwag", "src\LightQuery.NSwag\LightQuery.NSwag.csproj", "{9D88E0DE-D298-4143-B051-E022B20B102E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LightQuery.Swashbuckle", "src\LightQuery.Swashbuckle\LightQuery.Swashbuckle.csproj", "{CAF56EA7-A8E2-4AC7-A274-1D26C8E15401}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -101,6 +105,14 @@ Global
{38C64E1E-28CD-46D9-A4B2-D2E59683F8C0}.Release|Any CPU.Build.0 = Release|Any CPU
{506E6C78-4821-4269-A19A-7B60900EFBC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{506E6C78-4821-4269-A19A-7B60900EFBC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D88E0DE-D298-4143-B051-E022B20B102E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D88E0DE-D298-4143-B051-E022B20B102E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D88E0DE-D298-4143-B051-E022B20B102E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D88E0DE-D298-4143-B051-E022B20B102E}.Release|Any CPU.Build.0 = Release|Any CPU
{CAF56EA7-A8E2-4AC7-A274-1D26C8E15401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CAF56EA7-A8E2-4AC7-A274-1D26C8E15401}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CAF56EA7-A8E2-4AC7-A274-1D26C8E15401}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CAF56EA7-A8E2-4AC7-A274-1D26C8E15401}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -118,6 +130,8 @@ Global
{8CCD27FA-22E5-41FA-A796-44290D427ED9} = {7F628AED-CB88-45FF-BF48-8EA02C691700}
{B2D54A8A-30DD-489C-847D-9347E4F7D436} = {6526DECE-8511-41B3-B5A6-C8170D362611}
{38C64E1E-28CD-46D9-A4B2-D2E59683F8C0} = {7F628AED-CB88-45FF-BF48-8EA02C691700}
{9D88E0DE-D298-4143-B051-E022B20B102E} = {6526DECE-8511-41B3-B5A6-C8170D362611}
{CAF56EA7-A8E2-4AC7-A274-1D26C8E15401} = {6526DECE-8511-41B3-B5A6-C8170D362611}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A225AC12-BAEB-44E1-8A7E-CE6E82AF1756}
Expand Down
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ e.g. sorting can be done by using `bankAccount.balance`. Take this example:
{
"name": "Bob",
"bankAccount": null
},
}
]
```

Expand Down Expand Up @@ -288,6 +288,54 @@ export class UsersDetailsService extends PaginationBaseService<User> implements
}
```

## Swagger & OpenAPI Support

The packages **LightQuery.NSwag** and **LightQuery.Swashbuckle** support the automatic generation
of correct Swagger & OpenAPI parameter descriptions for the sort and pagination parameters.

### Example with NSwag

Just add the `LightQuery.NSwag.LightQueryOperationsProcessor` to your document generation:

```csharp
services.AddSwaggerDocument(nSwagConfig =>
{
nSwagConfig.DocumentName = "swagger20";
nSwagConfig.OperationProcessors.Add(new LightQueryOperationsProcessor());
});
services.AddOpenApiDocument(nSwagConfig =>
{
nSwagConfig.DocumentName = "openapi30";
nSwagConfig.OperationProcessors.Add(new LightQueryOperationsProcessor());
});
```

### Example with Swashbuckle

Just add the `LightQuery.Swashbuckle.LightQueryOperationFilter` to your document generation:

```csharp
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("swagger20", new OpenApiInfo()
{
Description = "swagger20"
});
options.OperationFilter<LightQueryOperationFilter>();
});

services.AddSwaggerGen(options =>
{
options.SwaggerDoc("openapi30", new OpenApiInfo()
{
Description = "openapi30"
});
options.OperationFilter<LightQueryOperationFilter>();
});


```

## Assembly Strong Naming & Usage in Signed Applications

This module produces strong named assemblies when compiled. When consumers of this package require strongly named assemblies, for example when they
Expand Down
2 changes: 2 additions & 0 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class Build : NukeBuild
GlobDirectories(SourceDirectory / "LightQuery.Client", "**/bin", "**/obj").ForEach(DeleteDirectory);
GlobDirectories(SourceDirectory / "LightQuery.EntityFrameworkCore", "**/bin", "**/obj").ForEach(DeleteDirectory);
GlobDirectories(SourceDirectory / "LightQuery.Shared", "**/bin", "**/obj").ForEach(DeleteDirectory);
GlobDirectories(SourceDirectory / "LightQuery.NSwag", "**/bin", "**/obj").ForEach(DeleteDirectory);
GlobDirectories(SourceDirectory / "LightQuery.Swashbuckle", "**/bin", "**/obj").ForEach(DeleteDirectory);
GlobDirectories(RootDirectory / "test", "**/bin", "**/obj").ForEach(DeleteDirectory);
EnsureCleanDirectory(OutputDirectory);
});
Expand Down
33 changes: 33 additions & 0 deletions src/LightQuery.NSwag/LightQuery.NSwag.csproj
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 added src/LightQuery.NSwag/LightQuery.NSwag.snk
Binary file not shown.
75 changes: 75 additions & 0 deletions src/LightQuery.NSwag/LightQueryOperationsProcessor.cs
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;
}
}
}
36 changes: 36 additions & 0 deletions src/LightQuery.Swashbuckle/LightQuery.Swashbuckle.csproj
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.
80 changes: 80 additions & 0 deletions src/LightQuery.Swashbuckle/LightQueryOperationFilter.cs
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)
}
});
}
}
}
}
Loading

0 comments on commit c0d4e12

Please sign in to comment.