Skip to content

Commit

Permalink
fix: Add typeName check for AnyURI mapped to string in csharp (#13969)
Browse files Browse the repository at this point in the history
Co-authored-by: Erling Hauan <[email protected]>
  • Loading branch information
standeren and ErlingHauan authored Nov 6, 2024
1 parent fa78ece commit e845708
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ or BaseValueType.GMonth
or BaseValueType.Time
or BaseValueType.TimePeriod
or BaseValueType.Date
or BaseValueType.AnyURI
or null => ("string", false),
BaseValueType.Int => ("int", true),
BaseValueType.Short => ("short", true),
Expand Down
11 changes: 11 additions & 0 deletions backend/tests/DataModeling.Tests/CsharpEnd2EndGenerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ public void JsonSchemaShouldConvertToXsdAndCSharp(string jsonSchemaPath, params
.Then.ConvertedXsdSchema.Should().NotBeNull();
}

[Theory]
[InlineData("Model/JsonSchema/General/StringUriFormat.json")]
public void JsonSchemaWithStringFieldInUriFormatShouldConvertToCSharp(string jsonSchemaPath)
{
Given.That.JsonSchemaLoaded(jsonSchemaPath)
.When.LoadedJsonSchemaConvertedToModelMetadata()
.And.ModelMetadataConvertedToCsharpClass()
.And.CSharpClassesCompiledToAssembly()
.Then.CompiledAssembly.Should().NotBeNull();
}

private void GeneratedClassesShouldBeEquivalentToExpected(string expectedCsharpClassPath)
{
string expectedClasses = SharedResourcesHelper.LoadTestDataAsString(expectedCsharpClassPath);
Expand Down
27 changes: 27 additions & 0 deletions testdata/Model/JsonSchema/General/StringUriFormat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "schema.json",
"type": "object",
"@xsdNamespaces": {
"xsd": "http://www.w3.org/2001/XMLSchema",
"xsi": "http://www.w3.org/2001/XMLSchema-instance"
},
"@xsdSchemaAttributes": {
"AttributeFormDefault": "Unqualified",
"ElementFormDefault": "Qualified",
"BlockDefault": "None",
"FinalDefault": "None"
},
"@xsdRootElement": "Root",
"oneOf": [
{
"properties": {
"uriField": {
"type": "string",
"format": "uri",
"@xsdType": "string"
}
}
}
]
}

0 comments on commit e845708

Please sign in to comment.