Skip to content
Merged
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
5 changes: 3 additions & 2 deletions src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Text.Json.Nodes;
using Microsoft.OpenApi.Interfaces;

Expand All @@ -19,7 +20,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiSerializable
/// <summary>
/// $schema, a JSON Schema dialect identifier. Value must be a URI
/// </summary>
public string Schema { get; }
public Uri Schema { get; }

/// <summary>
/// $id - Identifies a schema resource with its canonical URI.
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
/// <summary>
/// The default value for the $schema keyword within Schema Objects contained within this OAS document. This MUST be in the form of a URI.
/// </summary>
public string? JsonSchemaDialect { get; set; }
public Uri? JsonSchemaDialect { get; set; }

/// <summary>
/// An array of Server Objects, which provide connectivity information to a target server.
Expand Down Expand Up @@ -161,7 +161,7 @@
writer.WriteProperty(OpenApiConstants.OpenApi, "3.1.1");

// jsonSchemaDialect
writer.WriteProperty(OpenApiConstants.JsonSchemaDialect, JsonSchemaDialect);
writer.WriteProperty(OpenApiConstants.JsonSchemaDialect, JsonSchemaDialect?.ToString());

SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_1, (w, element) => element.SerializeAsV31(w));

Expand Down Expand Up @@ -239,7 +239,7 @@
/// <summary>
/// Serialize <see cref="OpenApiDocument"/> to OpenAPI object V2.0.
/// </summary>
public void SerializeAsV2(IOpenApiWriter writer)

Check warning on line 242 in src/Microsoft.OpenApi/Models/OpenApiDocument.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 30 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 242 in src/Microsoft.OpenApi/Models/OpenApiDocument.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 30 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
Utils.CheckArgumentNull(writer);

Expand Down Expand Up @@ -533,7 +533,7 @@
}
else
{
string relativePath = OpenApiConstants.ComponentsSegment + reference.Type.GetDisplayName() + "/" + reference.Id;

Check warning on line 536 in src/Microsoft.OpenApi/Models/OpenApiDocument.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this hardcoded path-delimiter. (https://rules.sonarsource.com/csharp/RSPEC-1075)

Check warning on line 536 in src/Microsoft.OpenApi/Models/OpenApiDocument.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this hardcoded path-delimiter. (https://rules.sonarsource.com/csharp/RSPEC-1075)

uriLocation = useExternal
? Workspace?.GetDocumentId(reference.ExternalResource)?.OriginalString + relativePath
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public string Title { get; set; }

/// <inheritdoc />
public string Schema { get; set; }
public Uri Schema { get; set; }

/// <inheritdoc />
public string Id { get; set; }
Expand Down Expand Up @@ -188,7 +188,7 @@
/// Initializes a copy of <see cref="IOpenApiSchema"/> object
/// </summary>
/// <param name="schema">The schema object to copy from.</param>
internal OpenApiSchema(IOpenApiSchema schema)

Check warning on line 191 in src/Microsoft.OpenApi/Models/OpenApiSchema.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this constructor to reduce its Cognitive Complexity from 19 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 191 in src/Microsoft.OpenApi/Models/OpenApiSchema.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this constructor to reduce its Cognitive Complexity from 19 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
Utils.CheckArgumentNull(schema);
Title = schema.Title ?? Title;
Expand Down Expand Up @@ -400,7 +400,7 @@
internal void WriteJsonSchemaKeywords(IOpenApiWriter writer)
{
writer.WriteProperty(OpenApiConstants.Id, Id);
writer.WriteProperty(OpenApiConstants.DollarSchema, Schema);
writer.WriteProperty(OpenApiConstants.DollarSchema, Schema?.ToString());
writer.WriteProperty(OpenApiConstants.Comment, Comment);
writer.WriteProperty(OpenApiConstants.Const, Const);
writer.WriteOptionalMap(OpenApiConstants.Vocabulary, Vocabulary, (w, s) => w.WriteValue(s));
Expand Down Expand Up @@ -631,7 +631,7 @@
writer.WriteEndObject();
}

private void SerializeTypeProperty(JsonSchemaType? type, IOpenApiWriter writer, OpenApiSpecVersion version)

Check warning on line 634 in src/Microsoft.OpenApi/Models/OpenApiSchema.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 21 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 634 in src/Microsoft.OpenApi/Models/OpenApiSchema.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 21 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
// check whether nullable is true for upcasting purposes
var isNullable = (Type.HasValue && Type.Value.HasFlag(JsonSchemaType.Null)) ||
Expand Down Expand Up @@ -725,7 +725,7 @@
private static readonly Array jsonSchemaTypeValues = System.Enum.GetValues(typeof(JsonSchemaType));
#endif

private void DowncastTypeArrayToV2OrV3(JsonSchemaType schemaType, IOpenApiWriter writer, OpenApiSpecVersion version)

Check warning on line 728 in src/Microsoft.OpenApi/Models/OpenApiSchema.cs

View workflow job for this annotation

GitHub Actions / Build

Make 'DowncastTypeArrayToV2OrV3' a static method. (https://rules.sonarsource.com/csharp/RSPEC-2325)

Check warning on line 728 in src/Microsoft.OpenApi/Models/OpenApiSchema.cs

View workflow job for this annotation

GitHub Actions / Build

Make 'DowncastTypeArrayToV2OrV3' a static method. (https://rules.sonarsource.com/csharp/RSPEC-2325)
{
/* If the array has one non-null value, emit Type as string
* If the array has one null value, emit x-nullable as true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public string Description
/// <inheritdoc/>
public string Title { get => Target?.Title; }
/// <inheritdoc/>
public string Schema { get => Target?.Schema; }
public Uri Schema { get => Target?.Schema; }
/// <inheritdoc/>
public string Id { get => Target?.Id; }
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static partial class OpenApiV31Deserializer
} /* Version is valid field but we already parsed it */
},
{"info", (o, n, _) => o.Info = LoadInfo(n, o)},
{"jsonSchemaDialect", (o, n, _) => o.JsonSchemaDialect = n.GetScalarValue() },
{"jsonSchemaDialect", (o, n, _) => { if (n.GetScalarValue() is string {} sjsd && Uri.TryCreate(sjsd, UriKind.Absolute, out var jsd)) {o.JsonSchemaDialect = jsd;}} },
{"servers", (o, n, _) => o.Servers = n.CreateList(LoadServer, o)},
{"paths", (o, n, _) => o.Paths = LoadPaths(n, o)},
{"webhooks", (o, n, _) => o.Webhooks = n.CreateMap(LoadPathItem, o)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal static partial class OpenApiV31Deserializer
},
{
"$schema",
(o, n, _) => o.Schema = n.GetScalarValue()
(o, n, _) => { if (n.GetScalarValue() is string {} sSchema && Uri.TryCreate(sSchema, UriKind.Absolute, out var schema)) {o.Schema = schema;}}
},
{
"$id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
Title = "Webhook Example",
Version = "1.0.0"
},
JsonSchemaDialect = "http://json-schema.org/draft-07/schema#",
JsonSchemaDialect = new Uri("http://json-schema.org/draft-07/schema#"),
Webhooks = new Dictionary<string, IOpenApiPathItem>
{
["pets"] = components.PathItems["pets"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task ParseBasicV31SchemaShouldSucceed()
var expectedObject = new OpenApiSchema()
{
Id = "https://example.com/arrays.schema.json",
Schema = "https://json-schema.org/draft/2020-12/schema",
Schema = new Uri("https://json-schema.org/draft/2020-12/schema"),
Description = "A representation of a person, company, organization, or place",
Type = JsonSchemaType.Object,
Properties = new Dictionary<string, IOpenApiSchema>
Expand Down Expand Up @@ -124,7 +124,7 @@ public void ParseSchemaWithTypeArrayWorks()
var expected = new OpenApiSchema()
{
Id = "https://example.com/arrays.schema.json",
Schema = "https://json-schema.org/draft/2020-12/schema",
Schema = new Uri("https://json-schema.org/draft/2020-12/schema"),
Description = "A representation of a person, company, organization, or place",
Type = JsonSchemaType.Object | JsonSchemaType.Null
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ public async Task SerializeDocumentWithRootJsonSchemaDialectPropertyWorks()
Title = "JsonSchemaDialectTest",
Version = "1.0.0"
},
JsonSchemaDialect = "http://json-schema.org/draft-07/schema#"
JsonSchemaDialect = new Uri("http://json-schema.org/draft-07/schema#")
};

var expected = @"openapi: '3.1.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ namespace Microsoft.OpenApi.Models.Interfaces
System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema> Properties { get; }
bool ReadOnly { get; }
System.Collections.Generic.ISet<string> Required { get; }
string Schema { get; }
System.Uri Schema { get; }
string Title { get; }
Microsoft.OpenApi.Models.JsonSchemaType? Type { get; }
bool UnEvaluatedProperties { get; }
Expand Down Expand Up @@ -718,7 +718,7 @@ namespace Microsoft.OpenApi.Models
public System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Interfaces.IOpenApiExtension>? Extensions { get; set; }
public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; }
public Microsoft.OpenApi.Models.OpenApiInfo Info { get; set; }
public string? JsonSchemaDialect { get; set; }
public System.Uri? JsonSchemaDialect { get; set; }
public Microsoft.OpenApi.Models.OpenApiPaths Paths { get; set; }
public System.Collections.Generic.IList<Microsoft.OpenApi.Models.OpenApiSecurityRequirement>? SecurityRequirements { get; set; }
public System.Collections.Generic.IList<Microsoft.OpenApi.Models.OpenApiServer>? Servers { get; set; }
Expand Down Expand Up @@ -1056,7 +1056,7 @@ namespace Microsoft.OpenApi.Models
public System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema> Properties { get; set; }
public bool ReadOnly { get; set; }
public System.Collections.Generic.ISet<string> Required { get; set; }
public string Schema { get; set; }
public System.Uri Schema { get; set; }
public string Title { get; set; }
public Microsoft.OpenApi.Models.JsonSchemaType? Type { get; set; }
public bool UnEvaluatedProperties { get; set; }
Expand Down Expand Up @@ -1409,7 +1409,7 @@ namespace Microsoft.OpenApi.Models.References
public System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema> Properties { get; }
public bool ReadOnly { get; }
public System.Collections.Generic.ISet<string> Required { get; }
public string Schema { get; }
public System.Uri Schema { get; }
public string Title { get; }
public Microsoft.OpenApi.Models.JsonSchemaType? Type { get; }
public bool UnEvaluatedProperties { get; }
Expand Down