-
-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract annotations into own package (#1641)
* Add NJsonSchema.Annotations.csproj * Reference NJsonSchema.Annotations.csproj in NJsonSchema.csproj * Update usings * Fix AnnotationsGenerationTests * Fix ReflectionServiceBase * Resolve NUKE build deprecation * Update usings * Fix comparing with line endings
- Loading branch information
Showing
79 changed files
with
698 additions
and
538 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
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, [email protected]</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, [email protected]</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, [email protected]</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, [email protected]</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, [email protected]</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.