Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/default constructor #103

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e5c32dd
Add Swagger Schema Filter
lucasteles Oct 21, 2022
5654495
Merge branch 'swagger_schema' of github.com:lucasteles/StronglyTypedI…
mdementyev Mar 2, 2023
84066cc
Merge pull request #2 from tennisi/lucasteles-swagger_schema
mdementyev Mar 2, 2023
b48da5e
Tests
kkgonsovsky Mar 7, 2023
c3b53b7
0.007
kkgonsovsky Mar 7, 2023
ba4a1e2
0.007
kkgonsovsky Mar 7, 2023
8c4d3b9
ubuntu-latest
kkgonsovsky Mar 7, 2023
bbfbcc4
Minus reference
kkgonsovsky Mar 7, 2023
9e6c5f4
references
kkgonsovsky Mar 7, 2023
71f123e
temp
kkgonsovsky Mar 7, 2023
17e24fc
Tests Fix
kkgonsovsky Mar 7, 2023
bd3a80c
Рабочие тесты
kkgonsovsky Mar 13, 2023
641e795
version/nullable
kkgonsovsky Mar 13, 2023
57a79b8
version
kkgonsovsky Mar 13, 2023
23599fe
version
kkgonsovsky Mar 13, 2023
e462cab
Merge pull request #5 from tennisi/swagger_testing
kkgonsovsky Mar 13, 2023
742e3ba
change version
kkgonsovsky Mar 13, 2023
079d098
version
kkgonsovsky Mar 13, 2023
769c6cb
Parsable
kkgonsovsky Mar 13, 2023
caad21d
Parsable Tests
kkgonsovsky Mar 13, 2023
bc67c85
parsable tests
kkgonsovsky Mar 13, 2023
9785506
parsing tests
kkgonsovsky Mar 13, 2023
8bc80c5
version
kkgonsovsky Mar 13, 2023
5cac970
net7/netstandart
kkgonsovsky Mar 13, 2023
10f4597
tests
kkgonsovsky Mar 13, 2023
0fc5484
parsable tests
kkgonsovsky Mar 13, 2023
b917714
iparsable test
kkgonsovsky Mar 13, 2023
7a34b7f
nullables disable
kkgonsovsky Mar 14, 2023
0afb021
nullables disable
kkgonsovsky Mar 14, 2023
ff7a8d0
all frameworks
kkgonsovsky Mar 14, 2023
d2d4d74
decimal for DapperHandler
kkgonsovsky Mar 14, 2023
b086452
dapper decimal
kkgonsovsky Mar 14, 2023
37de464
decimal value (long)
kkgonsovsky Mar 14, 2023
2f6969e
parsable test
kkgonsovsky Mar 14, 2023
ad8aadf
System.IFormatProvider
kkgonsovsky Mar 14, 2023
eba59a8
fix
kkgonsovsky Mar 14, 2023
b70f758
nullable
kkgonsovsky Mar 14, 2023
681af0f
combinations of #nullable enable/disable
kkgonsovsky Mar 14, 2023
24c2b26
Merge pull request #6 from tennisi/parsable
kkgonsovsky Mar 14, 2023
ee4073f
DapperTypeHandler Init/DbType
kkgonsovsky Mar 14, 2023
cfa53fa
Merge pull request #7 from tennisi/feature/DapperInitandFieldType
kkgonsovsky Mar 14, 2023
c71beb0
DefaultConstructor
kkgonsovsky Mar 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
120 changes: 60 additions & 60 deletions .github/workflows/BuildAndPack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,63 +58,63 @@ jobs:
with:
name: artifacts
path: artifacts
windows-latest:
name: windows-latest
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
7.0.x
6.0.x
5.0.x
3.1.x
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v2
with:
path: |
.nuke/temp
~/.nuget/packages
!~/.nuget/packages/stronglytypeid
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Run './build.cmd Clean Test TestPackages PushToNuGet'
run: ./build.cmd Clean Test TestPackages PushToNuGet
env:
GithubToken: ${{ secrets.GITHUB_TOKEN }}
NuGetToken: ${{ secrets.NUGET_TOKEN }}
MSBuildEnableWorkloadResolver: false
- uses: actions/upload-artifact@v1
with:
name: artifacts
path: artifacts
macOS-latest:
name: macOS-latest
runs-on: macOS-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
7.0.x
6.0.x
5.0.x
3.1.x
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v2
with:
path: |
.nuke/temp
~/.nuget/packages
!~/.nuget/packages/stronglytypeid
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Run './build.cmd Clean Test TestPackages PushToNuGet'
run: ./build.cmd Clean Test TestPackages PushToNuGet
env:
GithubToken: ${{ secrets.GITHUB_TOKEN }}
NuGetToken: ${{ secrets.NUGET_TOKEN }}
MSBuildEnableWorkloadResolver: false
- uses: actions/upload-artifact@v1
with:
name: artifacts
path: artifacts
# windows-latest:
# name: windows-latest
# runs-on: windows-latest
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-dotnet@v3
# with:
# dotnet-version: |
# 7.0.x
# 6.0.x
# 5.0.x
# 3.1.x
# - name: Cache .nuke/temp, ~/.nuget/packages
# uses: actions/cache@v2
# with:
# path: |
# .nuke/temp
# ~/.nuget/packages
# !~/.nuget/packages/stronglytypeid
# key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
# - name: Run './build.cmd Clean Test TestPackages PushToNuGet'
# run: ./build.cmd Clean Test TestPackages PushToNuGet
# env:
# GithubToken: ${{ secrets.GITHUB_TOKEN }}
# NuGetToken: ${{ secrets.NUGET_TOKEN }}
# MSBuildEnableWorkloadResolver: false
# - uses: actions/upload-artifact@v1
# with:
# name: artifacts
# path: artifacts
# macOS-latest:
# name: macOS-latest
# runs-on: macOS-latest
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-dotnet@v3
# with:
# dotnet-version: |
# 7.0.x
# 6.0.x
# 5.0.x
# 3.1.x
# - name: Cache .nuke/temp, ~/.nuget/packages
# uses: actions/cache@v2
# with:
# path: |
# .nuke/temp
# ~/.nuget/packages
# !~/.nuget/packages/stronglytypeid
# key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
# - name: Run './build.cmd Clean Test TestPackages PushToNuGet'
# run: ./build.cmd Clean Test TestPackages PushToNuGet
# env:
# GithubToken: ${{ secrets.GITHUB_TOKEN }}
# NuGetToken: ${{ secrets.NUGET_TOKEN }}
# MSBuildEnableWorkloadResolver: false
# - uses: actions/upload-artifact@v1
# with:
# name: artifacts
# path: artifacts
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>logo.png</PackageIcon>
<PackageProjectUrl>https://github.com/andrewlock/StronglyTypedId</PackageProjectUrl>
<PackageProjectUrl>https://github.com/tennisi/StronglyTypedId</PackageProjectUrl>
<PackageTags>stronglytypedid attribute generator generation codegen codegenerator codegeneration netescapades</PackageTags>
<RepositoryUrl>https://github.com/andrewlock/StronglyTypedId</RepositoryUrl>
<RepositoryUrl>https://github.com/tennisi/StronglyTypedId</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>
Expand Down Expand Up @@ -42,4 +42,4 @@

<Import Project="releasenotes.props" />

</Project>
</Project>
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ To use the the [StronglyTypedId NuGet package](https://www.nuget.org/packages/St
* [System.Text.Json](https://www.nuget.org/packages/System.Text.Json/) (optional, only required if [generating a System.Text `JsonConverter`](https://andrewlock.net/using-strongly-typed-entity-ids-to-avoid-primitive-obsession-part-2/#creating-a-custom-jsonconverter)). Note that in .NET Core apps, you will likely already reference this project via transitive dependencies.
* [Dapper](https://www.nuget.org/packages/Dapper/) (optional, only required if [generating a type mapper](https://andrewlock.net/using-strongly-typed-entity-ids-to-avoid-primitive-obsession-part-3/#interfacing-with-external-system-using-strongly-typed-ids))
* [EF Core](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore) (optional, only required if [generating an EF Core ValueConverter](https://andrewlock.net/strongly-typed-ids-in-ef-core-using-strongly-typed-entity-ids-to-avoid-primitive-obsession-part-4/))
* [Swagger Annotations](https://www.nuget.org/packages/Swashbuckle.AspNetCore.Annotations) (optional, only required if [generating an Swagger Schema Filter](#openapiswagger-specification)


To install the packages, add the references to your _csproj_ file, for example by running

Expand Down Expand Up @@ -160,6 +162,18 @@ public partial struct OrderId { }
public partial struct UserId { }
```

## OpenApi/Swagger Specification

If you wish to use an ID in your Swagger models and want to have schema and model sample reflecting the ID backingfield type you will need:
- Install [Swagger Annotations](https://www.nuget.org/packages/Swashbuckle.AspNetCore.Annotations) `>=5.0.0`
- Enable annotation in swagger gen with `services.AddSwaggerGen(c => c.EnableAnnotations());`
- Use the converter flag `StronglyTypedIdConverter.SwaggerSchemaFilter` on the ID decorator. eg:
```csharp
[StronglyTypedId(
backingType: StronglyTypedIdBackingType.Int,
converters: StronglyTypedIdConverter.SwaggerSchemaFilter | StronglyTypedIdConverter.SystemTextJson)]
public partial struct UserId { }
```

## Embedding the attributes in your project

Expand Down Expand Up @@ -253,4 +267,4 @@ The `struct`s you decorate with the `StronglyTypedId` attribute must be marked `

`StronglyTypedId` wouldn't work if not for [AArnott's CodeGeneration.Roslyn](https://github.com/AArnott/CodeGeneration.Roslyn) library.

The build process and general design of the library was modelled on the [RecordGenerator](https://github.com/amis92/RecordGenerator/blob/master/README.md) project, which is similar to this project, but can be used to generate immutable Record types.
The build process and general design of the library was modelled on the [RecordGenerator](https://github.com/amis92/RecordGenerator/blob/master/README.md) project, which is similar to this project, but can be used to generate immutable Record types.
33 changes: 23 additions & 10 deletions StronglyTypedId.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 Version 16
VisualStudioVersion = 16.0.28803.352
# Visual Studio Version 17
VisualStudioVersion = 17.4.33122.133
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EE1258BD-3422-4F55-B9CF-B4D6C95DAD68}"
EndProject
Expand All @@ -16,21 +16,26 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
releasenotes.props = releasenotes.props
version.props = version.props
.github\workflows\BuildAndPack.yml = .github\workflows\BuildAndPack.yml
CHANGELOG.md = CHANGELOG.md
build.sh = build.sh
NuGet.integration-tests.config = NuGet.integration-tests.config
global.json = global.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds", "src\StronglyTypedIds\StronglyTypedIds.csproj", "{9C0F3A36-ED47-4D0F-B736-EFC559C9E2DA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds", "src\StronglyTypedIds\StronglyTypedIds.csproj", "{9C0F3A36-ED47-4D0F-B736-EFC559C9E2DA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.Tests", "test\StronglyTypedIds.Tests\StronglyTypedIds.Tests.csproj", "{00B5ED3F-827D-41CD-9AF2-A9A20A6604E1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds.Tests", "test\StronglyTypedIds.Tests\StronglyTypedIds.Tests.csproj", "{00B5ED3F-827D-41CD-9AF2-A9A20A6604E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.IntegrationTests", "test\StronglyTypedIds.IntegrationTests\StronglyTypedIds.IntegrationTests.csproj", "{09F7364F-8CE9-4E9D-9BB7-B4CEBF682904}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds.IntegrationTests", "test\StronglyTypedIds.IntegrationTests\StronglyTypedIds.IntegrationTests.csproj", "{09F7364F-8CE9-4E9D-9BB7-B4CEBF682904}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{E13FB452-2D47-4719-8BAA-7B695D79AF3A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.Attributes", "src\StronglyTypedIds.Attributes\StronglyTypedIds.Attributes.csproj", "{F25F6E67-E62A-4075-86CF-4C4EDD7E4883}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds.Attributes", "src\StronglyTypedIds.Attributes\StronglyTypedIds.Attributes.csproj", "{F25F6E67-E62A-4075-86CF-4C4EDD7E4883}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.Nuget.IntegrationTests", "test\StronglyTypedIds.Nuget.IntegrationTests\StronglyTypedIds.Nuget.IntegrationTests.csproj", "{A7355210-7DDC-4968-84B7-79002113EA6E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds.Nuget.IntegrationTests", "test\StronglyTypedIds.Nuget.IntegrationTests\StronglyTypedIds.Nuget.IntegrationTests.csproj", "{A7355210-7DDC-4968-84B7-79002113EA6E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StronglyTypedIds.Nuget.Attributes.IntegrationTests", "test\StronglyTypedIds.Nuget.Attributes.IntegrationTests\StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj", "{19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StronglyTypedIds.Nuget.Attributes.IntegrationTests", "test\StronglyTypedIds.Nuget.Attributes.IntegrationTests\StronglyTypedIds.Nuget.Attributes.IntegrationTests.csproj", "{19A9B323-8C0B-4D1B-A20C-8CECFFD37F23}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -42,8 +47,6 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C0F3A36-ED47-4D0F-B736-EFC559C9E2DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C0F3A36-ED47-4D0F-B736-EFC559C9E2DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C0F3A36-ED47-4D0F-B736-EFC559C9E2DA}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -80,6 +83,16 @@ Global
{09F7364F-8CE9-4E9D-9BB7-B4CEBF682904}.Release|x64.Build.0 = Release|Any CPU
{09F7364F-8CE9-4E9D-9BB7-B4CEBF682904}.Release|x86.ActiveCfg = Release|Any CPU
{09F7364F-8CE9-4E9D-9BB7-B4CEBF682904}.Release|x86.Build.0 = Release|Any CPU
{E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Debug|x64.ActiveCfg = Debug|Any CPU
{E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Debug|x64.Build.0 = Debug|Any CPU
{E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Debug|x86.ActiveCfg = Debug|Any CPU
{E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Debug|x86.Build.0 = Debug|Any CPU
{E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Release|x64.ActiveCfg = Release|Any CPU
{E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Release|x64.Build.0 = Release|Any CPU
{E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Release|x86.ActiveCfg = Release|Any CPU
{E13FB452-2D47-4719-8BAA-7B695D79AF3A}.Release|x86.Build.0 = Release|Any CPU
{F25F6E67-E62A-4075-86CF-4C4EDD7E4883}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F25F6E67-E62A-4075-86CF-4C4EDD7E4883}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F25F6E67-E62A-4075-86CF-4C4EDD7E4883}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down
2 changes: 1 addition & 1 deletion build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Build : NukeBuild

Target PushToNuGet => _ => _
.DependsOn(Compile)
.OnlyWhenStatic(() => IsTag && IsServerBuild && IsWin)
.OnlyWhenStatic(() => true || ( IsTag && IsServerBuild && IsWin ))
.Requires(() => NuGetToken)
.After(Pack)
.Executes(() =>
Expand Down
6 changes: 6 additions & 0 deletions src/StronglyTypedIds.Attributes/StronglyTypedIdConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,11 @@ public enum StronglyTypedIdConverter
/// Creates a Dapper TypeHandler for converting to and from the type
/// </summary>
DapperTypeHandler = 32,

/// <summary>
/// Creates a Swagger SchemaFilter for OpenApi documentation
/// </summary>
SwaggerSchemaFilter = 64,

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace StronglyTypedIds
[Flags]
public enum StronglyTypedIdImplementations
{
// Used with HasFlag, so needs to be 1, 2, 4 etc
// Used with HasFlag, so needs to be 1, 2, 4, 8 etc

/// <summary>
/// Don't implement any additional members for the strongly typed ID
Expand All @@ -33,5 +33,11 @@ public enum StronglyTypedIdImplementations
/// Implement the <see cref="IComparable{T}"/> interface
/// </summary>
IComparable = 4,

// ReSharper disable once InconsistentNaming
/// <summary>
/// Implement the <see cref="IParsable{T}"/> interface
/// </summary>
IParsable = 8
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>StronglyTypedIds</RootNamespace>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
4 changes: 3 additions & 1 deletion src/StronglyTypedIds/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;

namespace StronglyTypedIds
{
internal static class Constants
{
public const string Usage = nameof(Usage);
}
}
}
Loading