Browse Source

Add nullable annotations to OpenIddict.EntityFramework.Models

pull/1038/head
Kévin Chalet 6 years ago
parent
commit
0f0a50a969
  1. 1
      src/OpenIddict.EntityFramework.Models/OpenIddict.EntityFramework.Models.csproj
  2. 48
      src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkApplication.cs
  3. 26
      src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkAuthorization.cs
  4. 34
      src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkScope.cs
  5. 36
      src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkToken.cs
  6. 8
      src/OpenIddict.EntityFramework/Configurations/OpenIddictEntityFrameworkApplicationConfiguration.cs
  7. 8
      src/OpenIddict.EntityFramework/Configurations/OpenIddictEntityFrameworkAuthorizationConfiguration.cs
  8. 1
      src/OpenIddict.EntityFramework/Configurations/OpenIddictEntityFrameworkScopeConfiguration.cs
  9. 6
      src/OpenIddict.EntityFramework/Configurations/OpenIddictEntityFrameworkTokenConfiguration.cs

1
src/OpenIddict.EntityFramework.Models/OpenIddict.EntityFramework.Models.csproj

@ -2,6 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks> <TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>

48
src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkApplication.cs

@ -7,6 +7,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace OpenIddict.EntityFramework.Models namespace OpenIddict.EntityFramework.Models
{ {
@ -26,7 +27,10 @@ namespace OpenIddict.EntityFramework.Models
/// Represents an OpenIddict application. /// Represents an OpenIddict application.
/// </summary> /// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; ClientId = {ClientId,nq} ; Type = {Type,nq}")] [DebuggerDisplay("Id = {Id.ToString(),nq} ; ClientId = {ClientId,nq} ; Type = {Type,nq}")]
public class OpenIddictEntityFrameworkApplication<TKey, TAuthorization, TToken> where TKey : IEquatable<TKey> public class OpenIddictEntityFrameworkApplication<TKey, TAuthorization, TToken>
where TKey : notnull, IEquatable<TKey>
where TAuthorization : class
where TToken : class
{ {
/// <summary> /// <summary>
/// Gets the list of the authorizations associated with this application. /// Gets the list of the authorizations associated with this application.
@ -34,77 +38,74 @@ namespace OpenIddict.EntityFramework.Models
public virtual ICollection<TAuthorization> Authorizations { get; } = new HashSet<TAuthorization>(); public virtual ICollection<TAuthorization> Authorizations { get; } = new HashSet<TAuthorization>();
/// <summary> /// <summary>
/// Gets or sets the client identifier /// Gets or sets the client identifier associated with the current application.
/// associated with the current application.
/// </summary> /// </summary>
public virtual string ClientId { get; set; } public virtual string? ClientId { get; set; }
/// <summary> /// <summary>
/// Gets or sets the client secret associated with the current application. /// Gets or sets the client secret associated with the current application.
/// Note: depending on the application manager used to create this instance, /// Note: depending on the application manager used to create this instance,
/// this property may be hashed or encrypted for security reasons. /// this property may be hashed or encrypted for security reasons.
/// </summary> /// </summary>
public virtual string ClientSecret { get; set; } public virtual string? ClientSecret { get; set; }
/// <summary> /// <summary>
/// Gets or sets the concurrency token. /// Gets or sets the concurrency token.
/// </summary> /// </summary>
public virtual string ConcurrencyToken { get; set; } = Guid.NewGuid().ToString(); public virtual string? ConcurrencyToken { get; set; } = Guid.NewGuid().ToString();
/// <summary> /// <summary>
/// Gets or sets the consent type /// Gets or sets the consent type associated with the current application.
/// associated with the current application.
/// </summary> /// </summary>
public virtual string ConsentType { get; set; } public virtual string? ConsentType { get; set; }
/// <summary> /// <summary>
/// Gets or sets the display name /// Gets or sets the display name associated with the current application.
/// associated with the current application.
/// </summary> /// </summary>
public virtual string DisplayName { get; set; } public virtual string? DisplayName { get; set; }
/// <summary> /// <summary>
/// Gets or sets the localized display names /// Gets or sets the localized display names
/// associated with the current application, /// associated with the current application,
/// serialized as a JSON object. /// serialized as a JSON object.
/// </summary> /// </summary>
public virtual string DisplayNames { get; set; } public virtual string? DisplayNames { get; set; }
/// <summary> /// <summary>
/// Gets or sets the unique identifier /// Gets or sets the unique identifier associated with the current application.
/// associated with the current application.
/// </summary> /// </summary>
public virtual TKey Id { get; set; } [AllowNull, MaybeNull]
public virtual TKey Id { get; set; } = default!;
/// <summary> /// <summary>
/// Gets or sets the permissions associated with the /// Gets or sets the permissions associated with the
/// current application, serialized as a JSON array. /// current application, serialized as a JSON array.
/// </summary> /// </summary>
public virtual string Permissions { get; set; } public virtual string? Permissions { get; set; }
/// <summary> /// <summary>
/// Gets or sets the logout callback URLs associated with /// Gets or sets the logout callback URLs associated with
/// the current application, serialized as a JSON array. /// the current application, serialized as a JSON array.
/// </summary> /// </summary>
public virtual string PostLogoutRedirectUris { get; set; } public virtual string? PostLogoutRedirectUris { get; set; }
/// <summary> /// <summary>
/// Gets or sets the additional properties serialized as a JSON object, /// Gets or sets the additional properties serialized as a JSON object,
/// or <c>null</c> if no bag was associated with the current application. /// or <c>null</c> if no bag was associated with the current application.
/// </summary> /// </summary>
public virtual string Properties { get; set; } public virtual string? Properties { get; set; }
/// <summary> /// <summary>
/// Gets or sets the callback URLs associated with the /// Gets or sets the callback URLs associated with the
/// current application, serialized as a JSON array. /// current application, serialized as a JSON array.
/// </summary> /// </summary>
public virtual string RedirectUris { get; set; } public virtual string? RedirectUris { get; set; }
/// <summary> /// <summary>
/// Gets or sets the requirements associated with the /// Gets or sets the requirements associated with the
/// current application, serialized as a JSON array. /// current application, serialized as a JSON array.
/// </summary> /// </summary>
public virtual string Requirements { get; set; } public virtual string? Requirements { get; set; }
/// <summary> /// <summary>
/// Gets the list of the tokens associated with this application. /// Gets the list of the tokens associated with this application.
@ -112,9 +113,8 @@ namespace OpenIddict.EntityFramework.Models
public virtual ICollection<TToken> Tokens { get; } = new HashSet<TToken>(); public virtual ICollection<TToken> Tokens { get; } = new HashSet<TToken>();
/// <summary> /// <summary>
/// Gets or sets the application type /// Gets or sets the application type associated with the current application.
/// associated with the current application.
/// </summary> /// </summary>
public virtual string Type { get; set; } public virtual string? Type { get; set; }
} }
} }

26
src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkAuthorization.cs

@ -7,6 +7,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace OpenIddict.EntityFramework.Models namespace OpenIddict.EntityFramework.Models
{ {
@ -26,45 +27,48 @@ namespace OpenIddict.EntityFramework.Models
/// Represents an OpenIddict authorization. /// Represents an OpenIddict authorization.
/// </summary> /// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; Subject = {Subject,nq} ; Type = {Type,nq} ; Status = {Status,nq}")] [DebuggerDisplay("Id = {Id.ToString(),nq} ; Subject = {Subject,nq} ; Type = {Type,nq} ; Status = {Status,nq}")]
public class OpenIddictEntityFrameworkAuthorization<TKey, TApplication, TToken> where TKey : IEquatable<TKey> public class OpenIddictEntityFrameworkAuthorization<TKey, TApplication, TToken>
where TKey : notnull, IEquatable<TKey>
where TApplication : class
where TToken : class
{ {
/// <summary> /// <summary>
/// Gets or sets the application associated with the current authorization. /// Gets or sets the application associated with the current authorization.
/// </summary> /// </summary>
public virtual TApplication Application { get; set; } public virtual TApplication? Application { get; set; }
/// <summary> /// <summary>
/// Gets or sets the concurrency token. /// Gets or sets the concurrency token.
/// </summary> /// </summary>
public virtual string ConcurrencyToken { get; set; } = Guid.NewGuid().ToString(); public virtual string? ConcurrencyToken { get; set; } = Guid.NewGuid().ToString();
/// <summary> /// <summary>
/// Gets or sets the unique identifier /// Gets or sets the unique identifier associated with the current authorization.
/// associated with the current authorization.
/// </summary> /// </summary>
public virtual TKey Id { get; set; } [AllowNull, MaybeNull]
public virtual TKey Id { get; set; } = default!;
/// <summary> /// <summary>
/// Gets or sets the additional properties serialized as a JSON object, /// Gets or sets the additional properties serialized as a JSON object,
/// or <c>null</c> if no bag was associated with the current authorization. /// or <c>null</c> if no bag was associated with the current authorization.
/// </summary> /// </summary>
public virtual string Properties { get; set; } public virtual string? Properties { get; set; }
/// <summary> /// <summary>
/// Gets or sets the scopes associated with the current /// Gets or sets the scopes associated with the current
/// authorization, serialized as a JSON array. /// authorization, serialized as a JSON array.
/// </summary> /// </summary>
public virtual string Scopes { get; set; } public virtual string? Scopes { get; set; }
/// <summary> /// <summary>
/// Gets or sets the status of the current authorization. /// Gets or sets the status of the current authorization.
/// </summary> /// </summary>
public virtual string Status { get; set; } public virtual string? Status { get; set; }
/// <summary> /// <summary>
/// Gets or sets the subject associated with the current authorization. /// Gets or sets the subject associated with the current authorization.
/// </summary> /// </summary>
public virtual string Subject { get; set; } public virtual string? Subject { get; set; }
/// <summary> /// <summary>
/// Gets the list of tokens associated with the current authorization. /// Gets the list of tokens associated with the current authorization.
@ -74,6 +78,6 @@ namespace OpenIddict.EntityFramework.Models
/// <summary> /// <summary>
/// Gets or sets the type of the current authorization. /// Gets or sets the type of the current authorization.
/// </summary> /// </summary>
public virtual string Type { get; set; } public virtual string? Type { get; set; }
} }
} }

34
src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkScope.cs

@ -6,6 +6,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace OpenIddict.EntityFramework.Models namespace OpenIddict.EntityFramework.Models
{ {
@ -25,60 +26,57 @@ namespace OpenIddict.EntityFramework.Models
/// Represents an OpenIddict scope. /// Represents an OpenIddict scope.
/// </summary> /// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; Name = {Name,nq}")] [DebuggerDisplay("Id = {Id.ToString(),nq} ; Name = {Name,nq}")]
public class OpenIddictEntityFrameworkScope<TKey> where TKey : IEquatable<TKey> public class OpenIddictEntityFrameworkScope<TKey> where TKey : notnull, IEquatable<TKey>
{ {
/// <summary> /// <summary>
/// Gets or sets the concurrency token. /// Gets or sets the concurrency token.
/// </summary> /// </summary>
public virtual string ConcurrencyToken { get; set; } = Guid.NewGuid().ToString(); public virtual string? ConcurrencyToken { get; set; } = Guid.NewGuid().ToString();
/// <summary> /// <summary>
/// Gets or sets the public description /// Gets or sets the public description associated with the current scope.
/// associated with the current scope.
/// </summary> /// </summary>
public virtual string Description { get; set; } public virtual string? Description { get; set; }
/// <summary> /// <summary>
/// Gets or sets the localized public descriptions associated /// Gets or sets the localized public descriptions associated
/// with the current scope, serialized as a JSON object. /// with the current scope, serialized as a JSON object.
/// </summary> /// </summary>
public virtual string Descriptions { get; set; } public virtual string? Descriptions { get; set; }
/// <summary> /// <summary>
/// Gets or sets the display name /// Gets or sets the display name associated with the current scope.
/// associated with the current scope.
/// </summary> /// </summary>
public virtual string DisplayName { get; set; } public virtual string? DisplayName { get; set; }
/// <summary> /// <summary>
/// Gets or sets the localized display names /// Gets or sets the localized display names
/// associated with the current application, /// associated with the current application,
/// serialized as a JSON object. /// serialized as a JSON object.
/// </summary> /// </summary>
public virtual string DisplayNames { get; set; } public virtual string? DisplayNames { get; set; }
/// <summary> /// <summary>
/// Gets or sets the unique identifier /// Gets or sets the unique identifier associated with the current scope.
/// associated with the current scope.
/// </summary> /// </summary>
public virtual TKey Id { get; set; } [AllowNull, MaybeNull]
public virtual TKey Id { get; set; } = default!;
/// <summary> /// <summary>
/// Gets or sets the unique name /// Gets or sets the unique name associated with the current scope.
/// associated with the current scope.
/// </summary> /// </summary>
public virtual string Name { get; set; } public virtual string? Name { get; set; }
/// <summary> /// <summary>
/// Gets or sets the additional properties serialized as a JSON object, /// Gets or sets the additional properties serialized as a JSON object,
/// or <c>null</c> if no bag was associated with the current scope. /// or <c>null</c> if no bag was associated with the current scope.
/// </summary> /// </summary>
public virtual string Properties { get; set; } public virtual string? Properties { get; set; }
/// <summary> /// <summary>
/// Gets or sets the resources associated with the /// Gets or sets the resources associated with the
/// current scope, serialized as a JSON array. /// current scope, serialized as a JSON array.
/// </summary> /// </summary>
public virtual string Resources { get; set; } public virtual string? Resources { get; set; }
} }
} }

36
src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkToken.cs

@ -6,6 +6,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace OpenIddict.EntityFramework.Models namespace OpenIddict.EntityFramework.Models
{ {
@ -25,53 +26,54 @@ namespace OpenIddict.EntityFramework.Models
/// Represents an OpenIddict token. /// Represents an OpenIddict token.
/// </summary> /// </summary>
[DebuggerDisplay("Id = {Id.ToString(),nq} ; Subject = {Subject,nq} ; Type = {Type,nq} ; Status = {Status,nq}")] [DebuggerDisplay("Id = {Id.ToString(),nq} ; Subject = {Subject,nq} ; Type = {Type,nq} ; Status = {Status,nq}")]
public class OpenIddictEntityFrameworkToken<TKey, TApplication, TAuthorization> where TKey : IEquatable<TKey> public class OpenIddictEntityFrameworkToken<TKey, TApplication, TAuthorization>
where TKey : notnull, IEquatable<TKey>
where TApplication : class
where TAuthorization : class
{ {
/// <summary> /// <summary>
/// Gets or sets the application associated with the current token. /// Gets or sets the application associated with the current token.
/// </summary> /// </summary>
public virtual TApplication Application { get; set; } public virtual TApplication? Application { get; set; }
/// <summary> /// <summary>
/// Gets or sets the authorization associated with the current token. /// Gets or sets the authorization associated with the current token.
/// </summary> /// </summary>
public virtual TAuthorization Authorization { get; set; } public virtual TAuthorization? Authorization { get; set; }
/// <summary> /// <summary>
/// Gets or sets the concurrency token. /// Gets or sets the concurrency token.
/// </summary> /// </summary>
public virtual string ConcurrencyToken { get; set; } = Guid.NewGuid().ToString(); public virtual string? ConcurrencyToken { get; set; } = Guid.NewGuid().ToString();
/// <summary> /// <summary>
/// Gets or sets the date on which the token /// Gets or sets the date on which the token will start to be considered valid.
/// will start to be considered valid.
/// </summary> /// </summary>
public virtual DateTimeOffset? CreationDate { get; set; } public virtual DateTimeOffset? CreationDate { get; set; }
/// <summary> /// <summary>
/// Gets or sets the date on which the token /// Gets or sets the date on which the token will no longer be considered valid.
/// will no longer be considered valid.
/// </summary> /// </summary>
public virtual DateTimeOffset? ExpirationDate { get; set; } public virtual DateTimeOffset? ExpirationDate { get; set; }
/// <summary> /// <summary>
/// Gets or sets the unique identifier /// Gets or sets the unique identifier associated with the current token.
/// associated with the current token.
/// </summary> /// </summary>
public virtual TKey Id { get; set; } [AllowNull, MaybeNull]
public virtual TKey Id { get; set; } = default!;
/// <summary> /// <summary>
/// Gets or sets the payload of the current token, if applicable. /// Gets or sets the payload of the current token, if applicable.
/// Note: this property is only used for reference tokens /// Note: this property is only used for reference tokens
/// and may be encrypted for security reasons. /// and may be encrypted for security reasons.
/// </summary> /// </summary>
public virtual string Payload { get; set; } public virtual string? Payload { get; set; }
/// <summary> /// <summary>
/// Gets or sets the additional properties serialized as a JSON object, /// Gets or sets the additional properties serialized as a JSON object,
/// or <c>null</c> if no bag was associated with the current token. /// or <c>null</c> if no bag was associated with the current token.
/// </summary> /// </summary>
public virtual string Properties { get; set; } public virtual string? Properties { get; set; }
/// <summary> /// <summary>
/// Gets or sets the reference identifier associated /// Gets or sets the reference identifier associated
@ -79,21 +81,21 @@ namespace OpenIddict.EntityFramework.Models
/// Note: this property is only used for reference tokens /// Note: this property is only used for reference tokens
/// and may be hashed or encrypted for security reasons. /// and may be hashed or encrypted for security reasons.
/// </summary> /// </summary>
public virtual string ReferenceId { get; set; } public virtual string? ReferenceId { get; set; }
/// <summary> /// <summary>
/// Gets or sets the status of the current token. /// Gets or sets the status of the current token.
/// </summary> /// </summary>
public virtual string Status { get; set; } public virtual string? Status { get; set; }
/// <summary> /// <summary>
/// Gets or sets the subject associated with the current token. /// Gets or sets the subject associated with the current token.
/// </summary> /// </summary>
public virtual string Subject { get; set; } public virtual string? Subject { get; set; }
/// <summary> /// <summary>
/// Gets or sets the type of the current token. /// Gets or sets the type of the current token.
/// </summary> /// </summary>
public virtual string Type { get; set; } public virtual string? Type { get; set; }
} }
} }

8
src/OpenIddict.EntityFramework/Configurations/OpenIddictEntityFrameworkApplicationConfiguration.cs

@ -37,7 +37,6 @@ namespace OpenIddict.EntityFramework
Property(application => application.ClientId) Property(application => application.ClientId)
.HasMaxLength(100) .HasMaxLength(100)
.IsRequired()
.HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute .HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute
{ {
IsUnique = true IsUnique = true
@ -48,11 +47,10 @@ namespace OpenIddict.EntityFramework
.IsConcurrencyToken(); .IsConcurrencyToken();
Property(application => application.Type) Property(application => application.Type)
.HasMaxLength(25) .HasMaxLength(25);
.IsRequired();
HasMany(application => application.Authorizations) HasMany(application => application.Authorizations)
.WithOptional(authorization => authorization.Application) .WithOptional(authorization => authorization.Application!)
.Map(association => .Map(association =>
{ {
association.MapKey(nameof(OpenIddictEntityFrameworkAuthorization.Application) + association.MapKey(nameof(OpenIddictEntityFrameworkAuthorization.Application) +
@ -60,7 +58,7 @@ namespace OpenIddict.EntityFramework
}); });
HasMany(application => application.Tokens) HasMany(application => application.Tokens)
.WithOptional(token => token.Application) .WithOptional(token => token.Application!)
.Map(association => .Map(association =>
{ {
association.MapKey(nameof(OpenIddictEntityFrameworkToken.Application) + association.MapKey(nameof(OpenIddictEntityFrameworkToken.Application) +

8
src/OpenIddict.EntityFramework/Configurations/OpenIddictEntityFrameworkAuthorizationConfiguration.cs

@ -38,18 +38,16 @@ namespace OpenIddict.EntityFramework
.IsConcurrencyToken(); .IsConcurrencyToken();
Property(authorization => authorization.Status) Property(authorization => authorization.Status)
.HasMaxLength(25) .HasMaxLength(25);
.IsRequired();
Property(authorization => authorization.Subject) Property(authorization => authorization.Subject)
.HasMaxLength(450); .HasMaxLength(450);
Property(authorization => authorization.Type) Property(authorization => authorization.Type)
.HasMaxLength(25) .HasMaxLength(25);
.IsRequired();
HasMany(authorization => authorization.Tokens) HasMany(authorization => authorization.Tokens)
.WithOptional(token => token.Authorization) .WithOptional(token => token.Authorization!)
.Map(association => association.MapKey(nameof(OpenIddictEntityFrameworkToken.Authorization) + .Map(association => association.MapKey(nameof(OpenIddictEntityFrameworkToken.Authorization) +
nameof(OpenIddictEntityFrameworkAuthorization.Id))) nameof(OpenIddictEntityFrameworkAuthorization.Id)))
.WillCascadeOnDelete(); .WillCascadeOnDelete();

1
src/OpenIddict.EntityFramework/Configurations/OpenIddictEntityFrameworkScopeConfiguration.cs

@ -37,7 +37,6 @@ namespace OpenIddict.EntityFramework
Property(scope => scope.Name) Property(scope => scope.Name)
.HasMaxLength(200) .HasMaxLength(200)
.IsRequired()
.HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute .HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute
{ {
IsUnique = true IsUnique = true

6
src/OpenIddict.EntityFramework/Configurations/OpenIddictEntityFrameworkTokenConfiguration.cs

@ -47,15 +47,13 @@ namespace OpenIddict.EntityFramework
.HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute())); .HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute()));
Property(token => token.Status) Property(token => token.Status)
.HasMaxLength(25) .HasMaxLength(25);
.IsRequired();
Property(token => token.Subject) Property(token => token.Subject)
.HasMaxLength(450); .HasMaxLength(450);
Property(token => token.Type) Property(token => token.Type)
.HasMaxLength(25) .HasMaxLength(25);
.IsRequired();
ToTable("OpenIddictTokens"); ToTable("OpenIddictTokens");
} }

Loading…
Cancel
Save