Skip to content

Commit

Permalink
applied PR requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasdejong committed Oct 17, 2024
1 parent a75232a commit e8556e2
Show file tree
Hide file tree
Showing 21 changed files with 106 additions and 25 deletions.
56 changes: 56 additions & 0 deletions src/Hl7.Fhir.Base/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,60 @@
<Left>lib/netstandard2.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Serialization.IFhirSerializationEngine.SerializeToXml(Hl7.Fhir.Model.Resource)</Target>
<Left>lib/net8.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Serialization.SerializationEngineExtensions.SerializeReaderToXml(Hl7.Fhir.Serialization.IFhirSerializationEngine,System.Xml.XmlReader)</Target>
<Left>lib/net8.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Serialization.SerializationEngineExtensions.SerializeToXmlWriter(Hl7.Fhir.Serialization.IFhirSerializationEngine,Hl7.Fhir.Model.Resource,System.Xml.XmlWriter)</Target>
<Left>lib/net8.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Serialization.IFhirSerializationEngine.SerializeToXml(Hl7.Fhir.Model.Resource)</Target>
<Left>lib/netstandard2.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/netstandard2.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Serialization.SerializationEngineExtensions.SerializeReaderToXml(Hl7.Fhir.Serialization.IFhirSerializationEngine,System.Xml.XmlReader)</Target>
<Left>lib/netstandard2.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/netstandard2.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Hl7.Fhir.Serialization.SerializationEngineExtensions.SerializeToXmlWriter(Hl7.Fhir.Serialization.IFhirSerializationEngine,Hl7.Fhir.Model.Resource,System.Xml.XmlWriter)</Target>
<Left>lib/netstandard2.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/netstandard2.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0006</DiagnosticId>
<Target>M:Hl7.Fhir.Serialization.IFhirSerializationEngine.SerializeToXml(Hl7.Fhir.Model.Base)</Target>
<Left>lib/net8.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/net8.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0006</DiagnosticId>
<Target>M:Hl7.Fhir.Serialization.IFhirSerializationEngine.SerializeToXml(Hl7.Fhir.Model.Base)</Target>
<Left>lib/netstandard2.0/Hl7.Fhir.Base.dll</Left>
<Right>lib/netstandard2.0/Hl7.Fhir.Base.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
</Suppressions>
2 changes: 1 addition & 1 deletion src/Hl7.Fhir.Base/ElementModel/PocoElementNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private PocoElementNode(ModelInspector inspector, Base instance, PocoElementNode
InstanceType = ((IStructureDefinitionSummary)_myClassMapping).TypeName;
Definition = definition ?? throw Error.ArgumentNull(nameof(definition));

// ExceptionHandler = parent.ExceptionHandler;
ExceptionHandler = parent.ExceptionHandler;
Location = location;
ShortPath = shortPath;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Hl7.Fhir.Base/ElementModel/TypedElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Hl7.Fhir.Model;
using System;
using System.Linq;
using System.Runtime.CompilerServices;

namespace Hl7.Fhir.ElementModel
{
Expand All @@ -26,6 +27,7 @@ public static class TypedElementExtensions
/// <param name="modelInspector">The <see cref="ModelInspector"/> containing the POCO classes to be used for deserialization.</param>
/// <param name="rootName"></param>
/// <returns></returns>
[TemporarilyChanged]
public static ITypedElement ToTypedElement(this Base @base, ModelInspector modelInspector, string? rootName = null)
=> new PocoElementNode(modelInspector, @base, rootName: rootName);

Expand Down
1 change: 0 additions & 1 deletion src/Hl7.Fhir.Base/FhirPath/CompiledExpression.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#nullable enable

using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.FhirPath.Functions;
using System.Collections.Generic;
using System.Linq;
Expand Down
4 changes: 0 additions & 4 deletions src/Hl7.Fhir.Base/FhirPath/Expressions/Closure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@


using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Dynamic;
using System.Linq;

namespace Hl7.FhirPath.Expressions
{
Expand Down
1 change: 0 additions & 1 deletion src/Hl7.Fhir.Base/FhirPath/FhirPathCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.FhirPath.Expressions;
using Hl7.FhirPath.Parser;
using Hl7.FhirPath.Sprache;
Expand Down
14 changes: 7 additions & 7 deletions src/Hl7.Fhir.Base/Model/Base.TypedElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
using Hl7.Fhir.Introspection;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Specification;
using Hl7.Fhir.Utility;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using P=Hl7.Fhir.ElementModel.Types;

namespace Hl7.Fhir.Model;
Expand Down Expand Up @@ -42,18 +41,19 @@ public interface IScopedNode : ITypedElement, IShortPathGenerator
// string Location { get; }
}

internal record ScopeInformation(IScopedNode? Parent, string Name, int? Index);
// name can technically be null when uninitialized, but we never allow it to be null upon accessing it.
internal record struct ScopeInformation(IScopedNode? Parent, string Name, int? Index);


public abstract partial class Base : IScopedNode,
IFhirValueProvider, IResourceTypeSupplier
{
[NonSerialized]
private ScopeInformation? _scopeInfo;
// we set name to null by default, but it can never be null upon accessing it, as the setter will initialize it.
[NonSerialized] private ScopeInformation _scopeInfo = new (null, null!, null);

private ScopeInformation ScopeInfo
{
get => LazyInitializer.EnsureInitialized(ref _scopeInfo, () => BuildRoot())!;
get => _scopeInfo.Name is null ? BuildRoot() : _scopeInfo;
set => _scopeInfo = value;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Hl7.Fhir.Base/Model/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public abstract partial class Base : IDeepCopyable, IDeepComparable,

public IEnumerable<object> Annotations(Type type)
{
if (type == typeof(ITypedElement) || type == typeof(IShortPathGenerator))
if (type == typeof(ITypedElement) || type == typeof(IShortPathGenerator) || type == typeof(IScopedNode))
return new[] { this };
else if (type == typeof(IFhirValueProvider))
return new[] { this };
Expand Down
4 changes: 2 additions & 2 deletions src/Hl7.Fhir.Base/Rest/HttpContentParsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public static async Task<Binary> ReadBinaryDataFromMessage(this HttpResponseMess
return ContentType.GetResourceFormatFromContentType(contentType) switch
{
ResourceFormat.Xml when bodyText is not null && SerializationUtil.ProbeIsXml(bodyText) =>
ser.DeserializeFromXml(bodyText) as Resource,
ser.DeserializeFromXml(bodyText),
ResourceFormat.Json when bodyText is not null && SerializationUtil.ProbeIsJson(bodyText) =>
ser.DeserializeFromJson(bodyText),
ResourceFormat.Xml or ResourceFormat.Json =>
Expand Down Expand Up @@ -275,7 +275,7 @@ public static async Task<Binary> ReadBinaryDataFromMessage(this HttpResponseMess
return ContentType.GetResourceFormatFromContentType(contentType) switch
{
ResourceFormat.Xml when bodyText is not null && SerializationUtil.ProbeIsFhirXml(bodyText) =>
ser.DeserializeFromXml(bodyText) as Resource,
ser.DeserializeFromXml(bodyText),
ResourceFormat.Json when bodyText is not null && SerializationUtil.ProbeIsFhirJson(bodyText) =>
ser.DeserializeFromJson(bodyText),
_ => default
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Serialization/FhirJsonBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace Hl7.Fhir.Serialization
Expand Down Expand Up @@ -54,6 +55,7 @@ public static JObject ToJObject(this ITypedElement source, FhirJsonSerialization
new FhirJsonBuilder(settings).Build(source);

/// <inheritdoc cref="ToJsonAsync(ITypedElement, FhirJsonSerializationSettings)" />
[TemporarilyChanged]
public static string ToJson(this ITypedElement source, FhirJsonSerializationSettings settings = null)
{
if (source is not Resource resource)
Expand All @@ -63,6 +65,7 @@ public static string ToJson(this ITypedElement source, FhirJsonSerializationSett
return engine.SerializeToJson(resource);
}

[TemporarilyChanged]
public static async Task<string> ToJsonAsync(this ITypedElement source, FhirJsonSerializationSettings settings = null)
{
if (source is not Resource resource)
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Base/Serialization/FhirXmlBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Hl7.Fhir.Model;
using Hl7.Fhir.Utility;
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
Expand Down Expand Up @@ -66,6 +67,7 @@ public static async Task<string> ToXmlAsync(this ISourceNode source, FhirXmlSeri
=> await SerializationUtil.WriteXmlToStringAsync(async writer => await source.WriteToAsync(writer, settings).ConfigureAwait(false), settings?.Pretty ?? false, settings?.AppendNewLine ?? false).ConfigureAwait(false);

/// <inheritdoc cref="ToXmlAsync(ITypedElement, FhirXmlSerializationSettings)" />
[TemporarilyChanged]
public static string ToXml(this ITypedElement source, FhirXmlSerializationSettings settings = null)
{
if (source is not Base b)
Expand All @@ -75,6 +77,7 @@ public static string ToXml(this ITypedElement source, FhirXmlSerializationSettin
return ((PocoSerializationEngine)engine).SerializeToXml(b);
}

[TemporarilyChanged]
public static async Task<string> ToXmlAsync(this ITypedElement source, FhirXmlSerializationSettings settings = null)
{
if (source is not Base b)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public static bool TryUnpackElementModelException(DeserializationFailedException
}
}

public Base DeserializeFromXml(string data) => deserialize(() => FhirXmlNode.Parse(data, settings: _xmlSettings));
internal Base DeserializeBaseFromXml(string data) => deserialize(() => FhirXmlNode.Parse(data, settings: _xmlSettings));
public Resource DeserializeFromXml(string data) => deserialize(() => FhirXmlNode.Parse(data, settings: _xmlSettings));

public Resource DeserializeFromJson(string data) => deserialize(() => FhirJsonNode.Parse(data, settings: _jsonSettings));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface IFhirSerializationEngine
/// </summary>
/// <exception cref="DeserializationFailedException">Thrown when the deserializer encountered one or more errors in the FHIR Xml format.</exception>
/// <returns>Null if the data did not contain a resource, but another FHIR datatype.</returns>
public Base? DeserializeFromXml(string data);
public Resource? DeserializeFromXml(string data);

/// <summary>
/// Serialize a FHIR Resource POCO into a string of Xml.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,23 @@ private BaseFhirXmlPocoSerializer getXmlSerializer() =>
_xmlSerializer ??= new BaseFhirXmlPocoSerializer(_inspector.FhirRelease);

/// <inheritdoc />
public Base DeserializeFromXml(string data)
public Resource DeserializeFromXml(string data)
{
return (Resource)deserializeAndFilterErrors(() =>
{
_ = getXmlDeserializer().TryDeserializeResource(data, out var instance, out var issues);
return (instance, issues);
});
}

internal Base DeserializeBaseFromXml(string data)
{
return deserializeAndFilterErrors(() =>
{
_ = getXmlDeserializer().TryDeserializeResource(data, out var instance, out var issues);
return (instance, issues);
});
}

/// <inheritdoc />
public string SerializeToXml(Base instance) => getXmlSerializer().SerializeToString(instance);
Expand All @@ -41,9 +50,9 @@ public Base DeserializeFromXml(string data)
/// </summary>
/// <param name="reader">The XML reader</param>
/// <returns>The parsed resource</returns>
public Base DeserializeFromXml(XmlReader reader)
public Resource DeserializeFromXml(XmlReader reader)
{
return deserializeAndFilterErrors(() =>
return (Resource)deserializeAndFilterErrors(() =>
{
_ = getXmlDeserializer().TryDeserializeResource(reader, out var instance, out var issues);
return (instance, issues);
Expand Down
4 changes: 4 additions & 0 deletions src/Hl7.Fhir.Base/Utility/TemporarilyChangedAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace System.Runtime.CompilerServices;

[AttributeUsage(AttributeTargets.All, Inherited = false)]
public class TemporarilyChangedAttribute : Attribute;
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.Json;
using Tasks = System.Threading.Tasks;

Expand Down Expand Up @@ -129,6 +130,7 @@ public async Tasks.Task TestSummary()

[TestMethod]
[Ignore("Masking node is not supported for serialization of the new poco interfaces")]
[TemporarilyChanged]
public async Tasks.Task TestIncludeMandatory()
{
var l = new Library();
Expand Down
3 changes: 3 additions & 0 deletions src/Hl7.Fhir.Serialization.R4.Tests/RoundtripSignature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using System.Runtime.CompilerServices;

namespace Hl7.Fhir.Serialization.Tests
{
Expand Down Expand Up @@ -45,6 +46,7 @@ private void validateEDS(IElementDefinitionSummary eds)

[TestMethod]
[Ignore("We stopped supporting ITypedElement.Definition on POCO.ToTypedElement")]
[TemporarilyChanged]
public void TypedElementHasCorrectInfo()
{
var cls = new Signature() { Who = new ResourceReference("http://nu.nl") }.ToTypedElement();
Expand All @@ -57,6 +59,7 @@ public void TypedElementHasCorrectInfo()

[TestMethod]
[Ignore("These should not be exactly equal!")]
[TemporarilyChanged]
public void WorksWithTypedElementSerializers()
{
var sig = new Bundle() { Signature = new Signature() { Who = new ResourceReference("http://nu.nl") } };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public string RoundTripXml(string original) =>
engine.SerializeToXml(
engine.DeserializeFromJson(
engine.SerializeToJson(
(engine.DeserializeFromXml(original) as Resource)!))!);
(engine.DeserializeFromXml(original))!))!);
public string RoundTripJson(string original) =>
engine.SerializeToJson(
(engine.DeserializeFromXml(
engine.SerializeToXml(
engine.DeserializeFromJson(original)!)) as Resource)!);
engine.DeserializeFromJson(original)!)))!);
}

internal class TypedElementBasedRoundtripper(IStructureDefinitionSummaryProvider provider) : IRoundTripper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using Tasks = System.Threading.Tasks;

namespace Hl7.Fhir.Core.Tests.ElementModel
Expand Down Expand Up @@ -197,6 +198,7 @@ public async Tasks.Task ValidateFiveWs()

[TestMethod]
[Ignore("This design is still under discussion")]
[TemporarilyChanged]
public void CheckTypeOfElementDefinitionMembers()
{
#if !R5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.Json;
using Tasks = System.Threading.Tasks;

Expand Down Expand Up @@ -129,6 +130,7 @@ public async Tasks.Task TestSummary()

[TestMethod]
[Ignore("This test uses masking node, which we cannot support on our new model")]
[TemporarilyChanged]
public async Tasks.Task TestIncludeMandatory()
{
var l = new Library();
Expand Down
2 changes: 1 addition & 1 deletion src/firely-net-sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Configurations>Debug;Release;FullDebug</Configurations>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnablePackageValidation>false</EnablePackageValidation> <!-- Disable package validation for now -->
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>5.10.3</PackageValidationBaselineVersion>
</PropertyGroup>

Expand Down

0 comments on commit e8556e2

Please sign in to comment.