Skip to content

Commit

Permalink
Merge pull request #919 from RSuter/master
Browse files Browse the repository at this point in the history
Release v9.13.22
  • Loading branch information
RicoSuter committed Mar 3, 2019
2 parents 2ef102e + 3b5d785 commit 082b6e4
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.3;netstandard2.0;net451</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.13.21</Version>
<Version>9.13.22</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2018</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public async Task When_property_is_readonly_then_ts_property_is_also_readonly()
var schema = await JsonSchema4.FromTypeAsync<Teacher>();
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings
{
TypeStyle = TypeScriptTypeStyle.Interface,
TypeStyle = TypeScriptTypeStyle.Interface,
TypeScriptVersion = 2.0m
});

Expand Down Expand Up @@ -255,5 +255,95 @@ public async Task When_patternProperties_is_set_with_string_value_type_then_corr
Assert.Contains("dict: { [key: string] : string; };", code); // property not nullable
Assert.Contains("this.dict = {};", code); // must be initialized with {}
}

[Fact]
public async Task When_default_is_generated_then_no_liquid_error_is_in_output()
{
var json = @"{
""type"": ""object"",
""properties"": {
""foo"": {
""$ref"": ""#/definitions/Person""
}
},
""definitions"": {
""Person"": {
""type"": ""object"",
""discriminator"": ""discriminator"",
""additionalProperties"": false,
""required"": [
""Id"",
""FirstName"",
""LastName"",
""Gender"",
""DateOfBirth"",
""Weight"",
""Height"",
""Age"",
""AverageSleepTime"",
""Address"",
""Children"",
""discriminator""
],
""properties"": {
""Id"": {
""type"": ""string"",
""format"": ""guid""
},
""FirstName"": {
""type"": ""string"",
""description"": ""Gets or sets the first name."",
""minLength"": 2
},
""LastName"": {
""type"": ""string"",
""description"": ""Gets or sets the last name."",
""minLength"": 1
},
""DateOfBirth"": {
""type"": ""string"",
""format"": ""date-time""
},
""Weight"": {
""type"": ""number"",
""format"": ""decimal""
},
""Height"": {
""type"": ""number"",
""format"": ""double""
},
""Age"": {
""type"": ""integer"",
""format"": ""int32"",
""maximum"": 99.0,
""minimum"": 5.0
},
""AverageSleepTime"": {
""type"": ""string"",
""format"": ""time-span""
},
""Children"": {
""type"": ""array"",
""items"": {
""$ref"": ""#/definitions/Person""
}
},
""discriminator"": {
""type"": ""string""
}
}
}
}
}";

var schema = await JsonSchema4.FromJsonAsync(json);

//// Act
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings { TypeStyle = TypeScriptTypeStyle.Class });
var code = generator.GenerateFile("MyClass");

//// Assert
Assert.DoesNotContain("Liquid error: ", code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.3;netstandard2.0;net451</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.13.21</Version>
<Version>9.13.22</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2018</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ public override string GetDefaultValue(JsonSchema4 schema, bool allowsNull, stri
var value = base.GetDefaultValue(schema, allowsNull, targetType, typeNameHint, useSchemaDefault, typeResolver);
if (value == null)
{
if (schema.Type.HasFlag(JsonObjectType.String) && _supportedFormatStrings.Contains(schema.Format))
if (schema.Default != null && useSchemaDefault)
{
return GetDefaultAsStringLiteral(schema);
if (schema.Type.HasFlag(JsonObjectType.String) &&
_supportedFormatStrings.Contains(schema.Format))
{
return GetDefaultAsStringLiteral(schema);
}
}

var isOptional = (schema as JsonProperty)?.IsRequired == false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.3;netstandard2.0;net451</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.13.21</Version>
<Version>9.13.22</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2018</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/NJsonSchema.Yaml/NJsonSchema.Yaml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.3;netstandard2.0;net45</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.13.21</Version>
<Version>9.13.22</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2018</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/NJsonSchema/NJsonSchema.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.0;netstandard2.0;net40;net45</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.13.21</Version>
<Version>9.13.22</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2018</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down

0 comments on commit 082b6e4

Please sign in to comment.