Skip to content

Commit

Permalink
Merge pull request #305 from FirelyTeam/dependabot/nuget/FirelySdkVer…
Browse files Browse the repository at this point in the history
…sion-5.8.0

Bump FirelySdkVersion from 5.7.0 to 5.8.1
  • Loading branch information
ewoutkramer authored May 15, 2024
2 parents 53aa12c + b24bb83 commit a03c248
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 22 deletions.
2 changes: 1 addition & 1 deletion firely-validator-api-tests.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<PropertyGroup>
<FirelySdkVersion>5.7.0</FirelySdkVersion>
<FirelySdkVersion>5.8.1</FirelySdkVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion firely-validator-api.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</PropertyGroup>

<PropertyGroup>
<FirelySdkVersion>5.7.0</FirelySdkVersion>
<FirelySdkVersion>5.8.1</FirelySdkVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down
3 changes: 3 additions & 0 deletions src/Firely.Fhir.Validation.Shared/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public Validator(

internal OperationOutcome Validate(IScopedNode sn, string? profile = null)
{
if (sn.InstanceType is null)
throw new ArgumentException($"Cannot validate the resource because {nameof(IScopedNode)} does not have an instance type.");

profile ??= Canonical.ForCoreType(sn.InstanceType).ToString();

#pragma warning disable CS0618 // Type or member is obsolete
Expand Down
2 changes: 1 addition & 1 deletion src/Firely.Fhir.Validation/Impl/CanonicalValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ResultReport IValidatable.Validate(IScopedNode input, ValidationSettings vc, Val
}
default:
return new IssueAssertion(Issue.CONTENT_ELEMENT_INVALID_PRIMITIVE_VALUE,
$"Primitive does not have the correct type ({input.Value.GetType()})").AsResult(state);
$"Primitive does not have the correct type ({input.Value?.GetType()})").AsResult(state);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Firely.Fhir.Validation/Impl/ChildrenValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Hl7.Fhir.Support;
using Hl7.Fhir.Utility;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -87,6 +88,9 @@ public JToken ToJson() =>
/// <inheritdoc />
ResultReport IValidatable.Validate(IScopedNode input, ValidationSettings vc, ValidationState state)
{
if (input.InstanceType is null)
throw new ArgumentException($"Cannot validate the resource because {nameof(IScopedNode)} does not have an instance type.");

var evidence = new List<ResultReport>();

// Listing children can be an expensive operation, so make sure we run it once.
Expand Down
5 changes: 5 additions & 0 deletions src/Firely.Fhir.Validation/Impl/DatatypeSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ internal override ResultReport ValidateInternal(IScopedNode input, ValidationSet
if (vc.ElementSchemaResolver is null)
throw new ArgumentException($"Cannot validate the resource because {nameof(ValidationSettings)} does not contain an ElementSchemaResolver.");

if (input.InstanceType is null)
{
throw new ArgumentException($"Cannot validate the resource because {nameof(IScopedNode)} does not have an instance type.");
}

var typeProfile = vc.TypeNameMapper.MapTypeName(input.InstanceType);
var fetchResult = FhirSchemaGroupAnalyzer.FetchSchema(vc.ElementSchemaResolver, state, typeProfile);
return fetchResult.Success ? fetchResult.Schema!.ValidateInternal(input, vc, state) : fetchResult.Error!;
Expand Down
4 changes: 4 additions & 0 deletions src/Firely.Fhir.Validation/Impl/FhirSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand Down Expand Up @@ -51,6 +52,9 @@ public FhirSchema(StructureDefinitionInformation structureDefinition, IEnumerabl
/// <inheritdoc/>
internal override ResultReport ValidateInternal(IScopedNode input, ValidationSettings vc, ValidationState state)
{
if (input.InstanceType is null)
throw new ArgumentException($"Cannot validate the resource because {nameof(IScopedNode)} does not have an instance type.");

state = state
.UpdateLocation(sp => sp.InvokeSchema(this))
.UpdateInstanceLocation(ip => ip.StartResource(input.InstanceType));
Expand Down
2 changes: 1 addition & 1 deletion src/Firely.Fhir.Validation/Impl/FhirStringValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ResultReport IValidatable.Validate(IScopedNode input, ValidationSettings vc, Val
}
default:
return new IssueAssertion(Issue.CONTENT_ELEMENT_INVALID_PRIMITIVE_VALUE,
$"Primitive does not have the correct type ({input.Value.GetType()})").AsResult(state);
$"Primitive does not have the correct type ({input.Value?.GetType()})").AsResult(state);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Firely.Fhir.Validation/Impl/FhirTxt2Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class FhirTxt2Validator : InvariantValidator
internal override (bool, ResultReport?) RunInvariant(IScopedNode input, ValidationSettings vc, ValidationState _)
{
//Check whether the narrative contains non-whitespace content.
return (!string.IsNullOrWhiteSpace(input.Value.ToString()), null);
return (!string.IsNullOrWhiteSpace(input.Value?.ToString()), null);
}

/// <inheritdoc/>
Expand Down
2 changes: 1 addition & 1 deletion src/Firely.Fhir.Validation/Impl/FixedValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ResultReport IValidatable.Validate(IScopedNode input, ValidationSettings _, Vali
return ResultReport.SUCCESS;

static string displayValue(ITypedElement te) =>
te.Children().Any() ? te.ToJson() : te.Value.ToString()!;
te.Children().Any() ? te.ToJson() : te.Value!.ToString()!;
}

/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion src/Firely.Fhir.Validation/Impl/PatternValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ResultReport IValidatable.Validate(IScopedNode input, ValidationSettings _, Vali
return result;

static string displayValue(ITypedElement te) =>
te.Children().Any() ? te.ToJson() : te.Value.ToString()!;
te.Children().Any() ? te.ToJson() : te.Value!.ToString()!;
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ ResultReport IValidatable.Validate(IScopedNode input, ValidationSettings vc, Val
if (vc.ElementSchemaResolver is null)
throw new ArgumentException($"Cannot validate because {nameof(ValidationSettings)} does not contain an ElementSchemaResolver.");

if (input.InstanceType is null)
throw new ArgumentException($"Cannot validate the resource because {nameof(IScopedNode)} does not have an instance type.");

if (!IsSupportedReferenceType(input.InstanceType))
return new IssueAssertion(Issue.CONTENT_REFERENCE_OF_INVALID_KIND,
$"Expected a reference type here (reference or canonical) not a {input.InstanceType}.")
Expand Down Expand Up @@ -127,7 +130,7 @@ private record ResolutionResult(ITypedElement? ReferencedResource, AggregationMo
// First, try to resolve within this instance (in contained, Bundle.entry)
resolveLocally(input.ToScopedNode(), reference, s, out var resolution)
];

// Now that we have tried to fetch the reference locally, we have also determined the kind of
// reference we are dealing with, so check it for aggregation and versioning rules.
if (HasAggregation && AggregationRules?.Any(a => a == resolution.ReferenceKind) == false)
Expand Down Expand Up @@ -258,9 +261,9 @@ public JToken ToJson()
/// <summary>
/// Whether this validator supports validating a given reference type.
/// </summary>
internal static bool IsSupportedReferenceType(string typeCode) =>
internal static bool IsSupportedReferenceType(string typeCode) =>
IsReferenceType(typeCode) && typeCode is not "canonical";

/// <summary>
/// Whether a type is a reference type.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Firely.Fhir.Validation/Impl/ResourceSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ internal override ResultReport ValidateInternal(IEnumerable<IScopedNode> input,
/// <inheritdoc />
internal override ResultReport ValidateInternal(IScopedNode input, ValidationSettings vc, ValidationState state)
{
if (input.InstanceType is null)
throw new ArgumentException($"Cannot validate the resource because {nameof(IScopedNode)} does not have an instance type.");

// FHIR specific rule about dealing with abstract datatypes (not profiles!): if this schema is an abstract datatype,
// we need to run validation against the schema for the actual type, not the abstract type.
if (StructureDefinition.IsAbstract && StructureDefinition.Derivation != StructureDefinitionInformation.TypeDerivationRule.Constraint)
Expand Down
4 changes: 2 additions & 2 deletions src/Firely.Fhir.Validation/Schema/ValueElementNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public ValueElementNode(IScopedNode wrapped)

public string Name => "value";

public string InstanceType => TypeSpecifier.ForNativeType(_wrapped.Value.GetType()).FullName;
public string? InstanceType => (_wrapped.Value is not null) ? TypeSpecifier.ForNativeType(_wrapped.Value.GetType()).FullName : null;

public object Value => _wrapped.Value;
public object? Value => _wrapped.Value;

public IEnumerable<IScopedNode> Children(string? name = null) => Enumerable.Empty<IScopedNode>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public ScopedNodeToTypedElementAdapter(IScopedNode adaptee)

public string Name => _adaptee.Name;

public string InstanceType => _adaptee.InstanceType;
public string? InstanceType => _adaptee.InstanceType;

public object Value => _adaptee.Value;
public object? Value => _adaptee.Value;

public IEnumerable<ITypedElement> Children(string? name = null) =>
_adaptee.Children(name).Select(n => new ScopedNodeToTypedElementAdapter(n));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ private TypedElementToIScopedNodeToAdapter(ITypedElement adaptee)

public string Name => _adaptee.Name;

public string InstanceType => _adaptee.InstanceType;
public string? InstanceType => _adaptee.InstanceType;

public object Value => _adaptee.Value;
public object? Value => _adaptee.Value;

IEnumerable<IScopedNode> IBaseElementNavigator<IScopedNode>.Children(string? name) =>
_adaptee.Children(name).Select(n => new TypedElementToIScopedNodeToAdapter(n));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ IEnumerable<string> getProfiles(ITypedElement node, string? profile = null)
yield return profile;
}

var instanceType = ModelInfo.CanonicalUriForFhirCoreType(node.InstanceType);
var instanceType = node.InstanceType is not null ? ModelInfo.CanonicalUriForFhirCoreType(node.InstanceType) : null;
if (instanceType is not null)
{
yield return instanceType!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ internal class ElementNodeAdapter : ITypedElement

public string Name => _elementNodeInstance.Name;

public string InstanceType => _elementNodeInstance.InstanceType;
public string InstanceType => _elementNodeInstance.InstanceType!;

public object Value => _elementNodeInstance.Value;
public object Value => _elementNodeInstance.Value!;

public string Location => _elementNodeInstance.Location;

public IElementDefinitionSummary Definition => _elementNodeInstance.Definition;
public IElementDefinitionSummary Definition => _elementNodeInstance.Definition!;

public static ElementNodeAdapter Root(string type, string? name = null, object? value = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static ITypedElement forObject(string name, object value, string locatio
else
{
_ = ElementNode.TryConvertToElementValue(value, out var primitive);
return new ConstantElement(name, ts.FullName, primitive, location);
return new ConstantElement(name, ts.FullName, primitive!, location);
}
}
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public IEnumerable<ITypedElement> Children(string? name) =>
Enumerable.Empty<ITypedElement>();
}

public IEnumerable<object>? Annotations(Type type) => type == typeof(IResourceTypeSupplier) ? (new[] { this }) : null;
public IEnumerable<object> Annotations(Type type) => type == typeof(IResourceTypeSupplier) ? (new[] { this }) : Enumerable.Empty<object>();

public string? ResourceType => TryGetValue("resourceType", out var rt) ? rt as string : null;

Expand Down

0 comments on commit a03c248

Please sign in to comment.