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

draft: refactor away from custom JsonSchema to JsonSchema.net #160

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI.Bindings/AMQP/AMQPOperationBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace LEGO.AsyncAPI.Bindings.AMQP
using System;
using System.Collections.Generic;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers;
using LEGO.AsyncAPI.Readers.ParseNodes;
using LEGO.AsyncAPI.Writers;

Expand Down
3 changes: 2 additions & 1 deletion src/LEGO.AsyncAPI.Bindings/Http/HttpMessageBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LEGO.AsyncAPI.Bindings.Http
{
using System;
using Json.Schema;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers;
using LEGO.AsyncAPI.Readers.ParseNodes;
Expand All @@ -16,7 +17,7 @@ public class HttpMessageBinding : MessageBinding<HttpMessageBinding>
/// <summary>
/// A Schema object containing the definitions for HTTP-specific headers. This schema MUST be of type object and have a properties key.
/// </summary>
public AsyncApiSchema Headers { get; set; }
public JsonSchema Headers { get; set; }

/// <summary>
/// Serialize to AsyncAPI V2 document without using reference.
Expand Down
3 changes: 2 additions & 1 deletion src/LEGO.AsyncAPI.Bindings/Http/HttpOperationBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LEGO.AsyncAPI.Bindings.Http
{
using System;
using Json.Schema;
using LEGO.AsyncAPI.Attributes;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers;
Expand Down Expand Up @@ -36,7 +37,7 @@ public enum HttpOperationType
/// <summary>
/// A Schema object containing the definitions for each query parameter. This schema MUST be of type object and have a properties key.
/// </summary>
public AsyncApiSchema Query { get; set; }
public JsonSchema Query { get; set; }

/// <summary>
/// Serialize to AsyncAPI V2 document without using reference.
Expand Down
3 changes: 2 additions & 1 deletion src/LEGO.AsyncAPI.Bindings/Kafka/KafkaMessageBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LEGO.AsyncAPI.Bindings.Kafka
{
using System;
using Json.Schema;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers;
using LEGO.AsyncAPI.Readers.ParseNodes;
Expand All @@ -16,7 +17,7 @@ public class KafkaMessageBinding : MessageBinding<KafkaMessageBinding>
/// <summary>
/// The message key. NOTE: You can also use the <a href="https://www.asyncapi.com/docs/reference/specification/v2.4.0#referenceObject">reference object</a> way.
/// </summary>
public AsyncApiSchema Key { get; set; }
public JsonSchema Key { get; set; }

/// <summary>
/// If a Schema Registry is used when performing this operation, tells where the id of schema is stored (e.g. header or payload).
Expand Down
5 changes: 3 additions & 2 deletions src/LEGO.AsyncAPI.Bindings/Kafka/KafkaOperationBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LEGO.AsyncAPI.Bindings.Kafka
{
using System;
using Json.Schema;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers;
using LEGO.AsyncAPI.Readers.ParseNodes;
Expand All @@ -16,12 +17,12 @@ public class KafkaOperationBinding : OperationBinding<KafkaOperationBinding>
/// <summary>
/// Id of the consumer group.
/// </summary>
public AsyncApiSchema GroupId { get; set; }
public JsonSchema GroupId { get; set; }

/// <summary>
/// Id of the consumer inside a consumer group.
/// </summary>
public AsyncApiSchema ClientId { get; set; }
public JsonSchema ClientId { get; set; }

public override string BindingKey => "kafka";

Expand Down
3 changes: 2 additions & 1 deletion src/LEGO.AsyncAPI.Bindings/MQTT/MQTTMessageBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LEGO.AsyncAPI.Bindings.MQTT
{
using System;
using Json.Schema;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers;
using LEGO.AsyncAPI.Readers.ParseNodes;
Expand All @@ -22,7 +23,7 @@ public class MQTTMessageBinding : MessageBinding<MQTTMessageBinding>
/// <summary>
/// Correlation Data is used to identify the request the response message is for.
/// </summary>
public AsyncApiSchema CorrelationData { get; set; }
public JsonSchema CorrelationData { get; set; }

/// <summary>
/// String describing the content type of the message payload.
Expand Down
3 changes: 0 additions & 3 deletions src/LEGO.AsyncAPI.Bindings/MQTT/MQTTOperationBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
namespace LEGO.AsyncAPI.Bindings.MQTT
{
using System;
using System.Collections.Generic;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers;
using LEGO.AsyncAPI.Readers.ParseNodes;
using LEGO.AsyncAPI.Writers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class WebSocketsChannelBinding : ChannelBinding<WebSocketsChannelBinding>
/// <summary>
/// A Schema object containing the definitions for each query parameter. This schema MUST be of type 'object' and have a 'properties' key.
/// </summary>
public AsyncApiSchema Query { get; set; }
public JsonSchema Query { get; set; }

/// <summary>
/// A Schema object containing the definitions of the HTTP headers to use when establishing the connection. This schma MUST be of type 'object' and have a 'properties' key.
/// </summary>
public AsyncApiSchema Headers { get; set; }
public JsonSchema Headers { get; set; }

public override string BindingKey => "websockets";

Expand Down
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI.Readers/AsyncApiJsonDocumentReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace LEGO.AsyncAPI.Readers
using System.Threading;
using System.Threading.Tasks;
using LEGO.AsyncAPI.Exceptions;
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Readers.Interface;
Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Readers/BindingDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace LEGO.AsyncAPI.Readers
{
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Readers.ParseNodes;

Expand Down
1 change: 1 addition & 0 deletions src/LEGO.AsyncAPI.Readers/LEGO.AsyncAPI.Readers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="JsonSchema.Net" Version="6.0.7" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal class AnyFieldMapParameter<T>
public AnyFieldMapParameter(
Func<T, AsyncApiAny> propertyGetter,
Action<T, AsyncApiAny> propertySetter,
Func<T, AsyncApiSchema> schemaGetter)
Func<T, JsonSchema> schemaGetter)
{
this.PropertyGetter = propertyGetter;
this.PropertySetter = propertySetter;
Expand All @@ -21,6 +21,6 @@ public AnyFieldMapParameter(

public Action<T, AsyncApiAny> PropertySetter { get; }

public Func<T, AsyncApiSchema> SchemaGetter { get; }
public Func<T, JsonSchema> SchemaGetter { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ namespace LEGO.AsyncAPI.Readers.ParseNodes
{
using System;
using System.Collections.Generic;
using Json.Schema;
using LEGO.AsyncAPI.Models;

internal class AnyListFieldMapParameter<T>
{
public AnyListFieldMapParameter(
Func<T, IList<AsyncApiAny>> propertyGetter,
Action<T, IList<AsyncApiAny>> propertySetter,
Func<T, AsyncApiSchema> schemaGetter)
Func<T, JsonSchema> schemaGetter)
{
this.PropertyGetter = propertyGetter;
this.PropertySetter = propertySetter;
Expand All @@ -22,6 +23,6 @@ public AnyListFieldMapParameter(

public Action<T, IList<AsyncApiAny>> PropertySetter { get; }

public Func<T, AsyncApiSchema> SchemaGetter { get; }
public Func<T, JsonSchema> SchemaGetter { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace LEGO.AsyncAPI.Readers.ParseNodes
{
using System;
using System.Collections.Generic;
using Json.Schema;
using LEGO.AsyncAPI.Models;

internal class AnyMapFieldMapParameter<T, U>
Expand All @@ -12,7 +13,7 @@ public AnyMapFieldMapParameter(
Func<T, IDictionary<string, U>> propertyMapGetter,
Func<U, AsyncApiAny> propertyGetter,
Action<U, AsyncApiAny> propertySetter,
Func<T, AsyncApiSchema> schemaGetter)
Func<T, JsonSchema> schemaGetter)
{
this.PropertyMapGetter = propertyMapGetter;
this.PropertyGetter = propertyGetter;
Expand All @@ -26,6 +27,6 @@ public AnyMapFieldMapParameter(

public Action<U, AsyncApiAny> PropertySetter { get; }

public Func<T, AsyncApiSchema> SchemaGetter { get; }
public Func<T, JsonSchema> SchemaGetter { get; }
}
}
1 change: 1 addition & 0 deletions src/LEGO.AsyncAPI.Readers/ParseNodes/ValueNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class ValueNode : ParseNode
{
private readonly JsonNode node;
private string cachedScalarValue;

public ValueNode(ParsingContext context, JsonNode node)
: base(
context)
Expand Down
25 changes: 25 additions & 0 deletions src/LEGO.AsyncAPI.Readers/SchemaTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) The LEGO Group. All rights reserved.

namespace LEGO.AsyncAPI.Readers
{
using System;
using Json.Schema;

public static class SchemaTypeConverter
{
public static SchemaValueType ConvertToSchemaValueType(string value)
{
return value.ToLowerInvariant() switch
{
"string" => SchemaValueType.String,
"number" or "double" => SchemaValueType.Number,
"integer" => SchemaValueType.Integer,
"boolean" => SchemaValueType.Boolean,
"array" => SchemaValueType.Array,
"object" => SchemaValueType.Object,
"null" => SchemaValueType.Null,
_ => throw new NotSupportedException(),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace LEGO.AsyncAPI.Readers
{
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;

Expand Down
11 changes: 8 additions & 3 deletions src/LEGO.AsyncAPI.Readers/V2/AsyncApiComponentsDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace LEGO.AsyncAPI.Readers
{
using LEGO.AsyncAPI.Extensions;
using Json.Schema;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;
using System;

internal static partial class AsyncApiV2Deserializer
{
private static FixedFieldMap<AsyncApiComponents> componentsFixedFields = new()
{
{ "schemas", (a, n) => a.Schemas = n.CreateMapWithReference(ReferenceType.Schema, JsonSchemaDeserializer.LoadSchema) },
{ "schemas", (a, n) => a.Schemas = n.CreateMap(JsonSchemaDeserializer.LoadSchema) },
{ "servers", (a, n) => a.Servers = n.CreateMapWithReference(ReferenceType.Server, LoadServer) },
{ "channels", (a, n) => a.Channels = n.CreateMapWithReference(ReferenceType.Channel, LoadChannel) },
{ "messages", (a, n) => a.Messages = n.CreateMapWithReference(ReferenceType.Message, LoadMessage) },
Expand All @@ -37,7 +38,11 @@ public static AsyncApiComponents LoadComponents(ParseNode node)
var components = new AsyncApiComponents();

ParseMap(mapNode, components, componentsFixedFields, componentsPatternFields);

foreach (var schema in components.Schemas)
{
var refUri = new Uri(AsyncApiConstants.V2ReferenceUri + schema.Key);
SchemaRegistry.Global.Register(refUri, schema.Value);
}
return components;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LEGO.AsyncAPI.Readers
{
using System;
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace LEGO.AsyncAPI.Readers
{
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace LEGO.AsyncAPI.Readers
{
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace LEGO.AsyncAPI.Readers
{
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LEGO.AsyncAPI.Readers
{
using System;
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;

Expand Down
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI.Readers/V2/AsyncApiInfoDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LEGO.AsyncAPI.Readers
{
using System;
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LEGO.AsyncAPI.Readers
{
using System;
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LEGO.AsyncAPI.Readers
{
using LEGO.AsyncAPI.Exceptions;
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace LEGO.AsyncAPI.Readers
{
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LEGO.AsyncAPI.Readers
{
using System;
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace LEGO.AsyncAPI.Readers
{
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LEGO.AsyncAPI.Readers
{
using System.Collections.Generic;
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace LEGO.AsyncAPI.Readers
{
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.ParseNodes;

Expand Down
Loading
Loading