-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
Extract annotations into own package #1641
Merged
RicoSuter
merged 8 commits into
RicoSuter:master
from
trejjam:feature/annotations-package
Oct 31, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
584d295
Add NJsonSchema.Annotations.csproj
trejjam d989f06
Reference NJsonSchema.Annotations.csproj in NJsonSchema.csproj
trejjam ef28945
Update usings
trejjam fce2fb7
Fix AnnotationsGenerationTests
trejjam 19f1934
Fix ReflectionServiceBase
trejjam 32cab60
Resolve NUKE build deprecation
trejjam d9c995e
Update usings
trejjam 8b30fcd
Fix comparing with line endings
trejjam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="CanBeNullAttribute.cs" company="NJsonSchema"> | ||
// Copyright (c) Rico Suter. All rights reserved. | ||
// </copyright> | ||
// <license>https://github.com/RicoSuter/NJsonSchema/blob/master/LICENSE.md</license> | ||
// <author>Rico Suter, mail@rsuter.com</author> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
|
||
namespace NJsonSchema.Annotations; | ||
|
||
/// <summary>Indicates that the value of the marked element is nullable.</summary> | ||
[AttributeUsage( | ||
AttributeTargets.Method | | ||
AttributeTargets.Parameter | | ||
AttributeTargets.Property | | ||
AttributeTargets.ReturnValue | | ||
AttributeTargets.Delegate | | ||
AttributeTargets.Field | | ||
AttributeTargets.Event)] | ||
public class CanBeNullAttribute : Attribute | ||
{ | ||
} |
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,84 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="JsonFormatStrings.cs" company="NJsonSchema"> | ||
// Copyright (c) Rico Suter. All rights reserved. | ||
// </copyright> | ||
// <license>https://github.com/RicoSuter/NJsonSchema/blob/master/LICENSE.md</license> | ||
// <author>Rico Suter, mail@rsuter.com</author> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
|
||
namespace NJsonSchema.Annotations; | ||
|
||
/// <summary>Class containing the constants available as format string. </summary> | ||
public static class JsonFormatStrings | ||
{ | ||
/// <summary>Format for a <see cref="System.DateTime"/>. </summary> | ||
public const string DateTime = "date-time"; | ||
|
||
/// <summary>Non-standard Format for a duration (time span)<see cref="TimeSpan"/>. </summary> | ||
public const string TimeSpan = "time-span"; | ||
|
||
/// <summary>Format for a duration (time span) as of 2019-09 <see cref="TimeSpan"/>. </summary> | ||
public const string Duration = "duration"; | ||
|
||
/// <summary>Format for an email. </summary> | ||
public const string Email = "email"; | ||
|
||
/// <summary>Format for an URI. </summary> | ||
public const string Uri = "uri"; | ||
|
||
/// <summary>Format for an GUID. </summary> | ||
public const string Guid = "guid"; | ||
|
||
/// <summary>Format for an UUID (same as GUID). </summary> | ||
[Obsolete("Now made redundant. Use \"guid\" instead.")] | ||
public const string Uuid = "uuid"; | ||
|
||
/// <summary>Format for an integer. </summary> | ||
public const string Integer = "int32"; | ||
|
||
/// <summary>Format for a long integer. </summary> | ||
public const string Long = "int64"; | ||
|
||
/// <summary>Format for a unsigned long integer. </summary> | ||
public const string ULong = "uint64"; | ||
|
||
/// <summary>Format for a double number. </summary> | ||
public const string Double = "double"; | ||
|
||
/// <summary>Format for a float number. </summary> | ||
public const string Float = "float"; | ||
|
||
/// <summary>Format for a decimal number. </summary> | ||
public const string Decimal = "decimal"; | ||
|
||
/// <summary>Format for an IP v4 address. </summary> | ||
public const string IpV4 = "ipv4"; | ||
|
||
/// <summary>Format for an IP v6 address. </summary> | ||
public const string IpV6 = "ipv6"; | ||
|
||
/// <summary>Format for binary data encoded with Base64.</summary> | ||
/// <remarks>Should not be used. Prefer using Byte property of <see cref="JsonFormatStrings"/></remarks> | ||
[Obsolete("Now made redundant. Use \"byte\" instead.")] | ||
public const string Base64 = "base64"; | ||
|
||
/// <summary>Format for a byte if used with numeric type or for base64 encoded value otherwise.</summary> | ||
public const string Byte = "byte"; | ||
|
||
/// <summary>Format for a binary value.</summary> | ||
public const string Binary = "binary"; | ||
|
||
/// <summary>Format for a hostname (DNS name).</summary> | ||
public const string Hostname = "hostname"; | ||
|
||
/// <summary>Format for a phone number.</summary> | ||
public const string Phone = "phone"; | ||
|
||
/// <summary>Format for a full date per RFC3339 Section 5.6.</summary> | ||
public const string Date = "date"; | ||
|
||
/// <summary>Format for a full time per RFC3339 Section 5.6.</summary> | ||
public const string Time = "time"; | ||
} |
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,39 @@ | ||
using System; | ||
|
||
namespace NJsonSchema.Annotations; | ||
|
||
/// <summary> | ||
/// Enumeration of the possible object types. | ||
/// | ||
/// Keep in sync with NJsonSchema.JsonObjectType | ||
/// </summary> | ||
[Flags] | ||
public enum JsonObjectType | ||
{ | ||
/// <summary>No object type. </summary> | ||
None = 0, | ||
|
||
/// <summary>An array. </summary> | ||
Array = 1, | ||
|
||
/// <summary>A boolean value. </summary> | ||
Boolean = 2, | ||
|
||
/// <summary>An integer value. </summary> | ||
Integer = 4, | ||
|
||
/// <summary>A null. </summary> | ||
Null = 8, | ||
|
||
/// <summary>An number value. </summary> | ||
Number = 16, | ||
|
||
/// <summary>An object. </summary> | ||
Object = 32, | ||
|
||
/// <summary>A string. </summary> | ||
String = 64, | ||
|
||
/// <summary>A file (used in Swagger specifications). </summary> | ||
File = 128, | ||
} |
32 changes: 32 additions & 0 deletions
32
src/NJsonSchema.Annotations/JsonSchemaAbstractAttribute.cs
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,32 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="JsonSchemaDateAttribute.cs" company="NJsonSchema"> | ||
// Copyright (c) Rico Suter. All rights reserved. | ||
// </copyright> | ||
// <license>https://github.com/RicoSuter/NJsonSchema/blob/master/LICENSE.md</license> | ||
// <author>Rico Suter, mail@rsuter.com</author> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
|
||
namespace NJsonSchema.Annotations; | ||
|
||
/// <summary>Annotation to merge all inherited properties into this class/schema.</summary> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)] | ||
public class JsonSchemaAbstractAttribute : Attribute | ||
{ | ||
/// <summary>Initializes a new instance of the <see cref="JsonSchemaAbstractAttribute"/> class.</summary> | ||
public JsonSchemaAbstractAttribute() | ||
{ | ||
IsAbstract = true; | ||
} | ||
|
||
/// <summary>Initializes a new instance of the <see cref="JsonSchemaAbstractAttribute"/> class.</summary> | ||
/// <param name="isAbstract">The explicit flag to override the global setting (i.e. disable the generation for a type).</param> | ||
public JsonSchemaAbstractAttribute(bool isAbstract) | ||
{ | ||
IsAbstract = isAbstract; | ||
} | ||
|
||
/// <summary>Gets or sets a value indicating whether to set the x-abstract property for given type.</summary> | ||
public bool IsAbstract { get; } | ||
} |
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,49 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="JsonSchemaAttribute.cs" company="NJsonSchema"> | ||
// Copyright (c) Rico Suter. All rights reserved. | ||
// </copyright> | ||
// <license>https://github.com/RicoSuter/NJsonSchema/blob/master/LICENSE.md</license> | ||
// <author>Rico Suter, mail@rsuter.com</author> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
|
||
namespace NJsonSchema.Annotations; | ||
|
||
/// <summary>Annotation to specify the JSON Schema type for the given class.</summary> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Struct | | ||
AttributeTargets.Parameter | AttributeTargets.ReturnValue)] | ||
public class JsonSchemaAttribute : Attribute | ||
{ | ||
/// <summary>Initializes a new instance of the <see cref="JsonSchemaAttribute"/> class.</summary> | ||
public JsonSchemaAttribute() | ||
{ | ||
Type = JsonObjectType.None; | ||
} | ||
|
||
/// <summary>Initializes a new instance of the <see cref="JsonSchemaAttribute" /> class.</summary> | ||
/// <param name="name">The identifier of the schema which is used as key in the 'definitions' list.</param> | ||
public JsonSchemaAttribute(string name) : this() | ||
{ | ||
Name = name; | ||
} | ||
|
||
/// <summary>Initializes a new instance of the <see cref="JsonSchemaAttribute"/> class.</summary> | ||
/// <param name="type">The JSON Schema type.</param> | ||
public JsonSchemaAttribute(JsonObjectType type) | ||
{ | ||
Type = type; | ||
} | ||
|
||
/// <summary>Gets or sets the name identifier of the schema which is used as key in the 'definitions' list.</summary> | ||
public string? Name { get; set; } | ||
|
||
/// <summary>Gets the JSON Schema type (default: <see cref="JsonObjectType.None"/>, i.e. derived from <see cref="System.Type"/>).</summary> | ||
public JsonObjectType Type { get; private set; } | ||
|
||
/// <summary>Gets or sets the JSON format type (default: <c>null</c>, i.e. derived from <see cref="System.Type"/>).</summary> | ||
public string? Format { get; set; } | ||
|
||
/// <summary>Gets or sets the array item type.</summary> | ||
public Type? ArrayItem { get; set; } | ||
} |
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,20 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="JsonSchemaDateAttribute.cs" company="NJsonSchema"> | ||
// Copyright (c) Rico Suter. All rights reserved. | ||
// </copyright> | ||
// <license>https://github.com/RicoSuter/NJsonSchema/blob/master/LICENSE.md</license> | ||
// <author>Rico Suter, mail@rsuter.com</author> | ||
//----------------------------------------------------------------------- | ||
|
||
namespace NJsonSchema.Annotations; | ||
|
||
/// <summary>Annotation to mark a property or class as string type with format 'date'.</summary> | ||
public class JsonSchemaDateAttribute : JsonSchemaAttribute | ||
{ | ||
/// <summary>Initializes a new instance of the <see cref="JsonSchemaAttribute"/> class.</summary> | ||
public JsonSchemaDateAttribute() | ||
: base(JsonObjectType.String) | ||
{ | ||
Format = JsonFormatStrings.Date; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether we should put this in the NJsonSchema namespace but the NJsonSchema.Annotations pkg
and remove from NJsonSchema (and the same with JsonObjectType). What do you think? Might be confusing to have these two types twice... also I think it's not very nice/clean to have it twice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the motive, but it feels strange to exclude one attribute from the annotations package.
The duplicity is there because of the Newtonsoft attribute. I can solve it instead with JsonConverter for that type. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry no my propsal:
JsonFormatStrings: Keep in NJsonSchema.Annotations but with namespace NJsonSchema (remove in NJsonSchema pkg)
JsonObjectType: Keep in NJsonSchema.Annotations but with namespace NJsonSchema (remove in NJsonSchema pkg)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's ok for me. How do you prefer to handle these attributes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are from Newtonsoft package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These? Link seems to be broken...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These:
JsonPropertyAttribute
https://github.com/RicoSuter/NJsonSchema/blob/8b30fcd633389a56c10ac23c9287348775f849a8/src/NJsonSchema/JsonObjectType.cs#L26C1-L28C19
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems that these are not needed because of the magic here:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took me some time to find it :)