Generalize handling of Base/Conformance properties that changed type#47
Merged
Generalize handling of Base/Conformance properties that changed type#47
Conversation
…of .net primitive.
# Conflicts: # src/Microsoft.Health.Fhir.CodeGen/Language/Firely/CSharpFirely2.cs
…ct-shared-properties # Conflicts: # src/Microsoft.Health.Fhir.CodeGen/Language/Firely/CSharpFirely2.cs
Kasdejong
approved these changes
Dec 3, 2024
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change makes sure that, in base/conformance, if we have a (primitive) property that changed type from version to version (like Attachment.size), the property is now of the abstract subclass PrimitiveType. (this PR actually would handle non-primitives too, but there isn't yet anything to test that with).
For such elements:
Integer64for Attachtment.size) to a base class (in the case of primitive properties, toPrimitiveType)Note that the generated code is smart enough to know that, when generating helper getters, the actual type of the backing element does not matter, as long as they have the same .NET primitive constants. In all other cases, the helper getters will throw if the backing element has the wrong type.
The setters for the helper properties will always create the correct type in the backing element property.
E.g. if we're talking about
Attachment.size, the accessor returning alongrequires theSizeElementto be a FHIR Integer64. If it encounters an UnsignedInt there, the getter will throw. But forElementDefinition.description, the getter of both versions (one for markdown one for FHIR string) will work, as bothMarkdownandFhirStringhave astringin theirValueproperty.I have also added
[AllowedTypes]to such changed properties, as the abstract property type allows too many types. Obviously, the allowedtypes are exactly the sum of the types declared per version. We could make this validation more precise, if the validation attributes would be sensitive to FHIR version, which they are not yet. I have created an isse (FirelyTeam/firely-net-sdk#2982) to fix this in the future. For now, I generate these attributes with a "since" as comment lines.To be able to generate these
[AllowedTypes]attributes, I had to refactor the code a bit to avoid re-duplicating the existing code that generates this attribute for choicetypes.