private string HandleJsonTypes(JsonSchema jSchema) { TypeKeyword type = jSchema.Get <TypeKeyword>(); if (type != null) { switch (type.Value) { case JsonSchemaType.String: { FormatKeyword format = jSchema.Get <FormatKeyword>(); if (format != null && format.Value != null && !string.IsNullOrEmpty(format.Value)) { return(HandleFormatTypes(format.Value)); } return("string"); } case JsonSchemaType.Boolean: return("boolean"); case JsonSchemaType.Number: return("decimal"); case JsonSchemaType.Integer: { double?minimum = jSchema.Minimum(); if (minimum > 0.0) { return("positiveInteger"); } else if (minimum == 0.0) { return("nonNegativeInteger"); } else { return("integer"); } } } } return(null); }
private XmlSchemaSimpleTypeRestriction ExtractStringFacets(JsonSchema jSchema) { XmlSchemaSimpleTypeRestriction content = new XmlSchemaSimpleTypeRestriction { BaseTypeName = new XmlQualifiedName("string", XML_SCHEMA_NS), }; EnumKeyword enumKeyword = jSchema.Get<EnumKeyword>(); if (enumKeyword != null) { foreach (JsonValue enumValue in GetterExtensions.Enum(jSchema)) { XmlSchemaEnumerationFacet enumFacet = new XmlSchemaEnumerationFacet { Value = enumValue.String, }; content.Facets.Add(enumFacet); } } MinLengthKeyword minLength = jSchema.Get<MinLengthKeyword>(); MaxLengthKeyword maxLength = jSchema.Get<MaxLengthKeyword>(); if (minLength != null && maxLength != null && minLength.Value == maxLength.Value) { // special rule that maps equal min and max lengths to xsd length facet XmlSchemaLengthFacet lengthFacet = new XmlSchemaLengthFacet { Value = minLength.Value.ToString(), }; content.Facets.Add(lengthFacet); } else { if (minLength != null) { XmlSchemaMinLengthFacet minLengthFacet = new XmlSchemaMinLengthFacet { Value = minLength.Value.ToString(), }; content.Facets.Add(minLengthFacet); } if (maxLength != null) { XmlSchemaMaxLengthFacet maxLengthFacet = new XmlSchemaMaxLengthFacet { Value = maxLength.Value.ToString(), }; content.Facets.Add(maxLengthFacet); } } PatternKeyword pattern = jSchema.Get<PatternKeyword>(); if (pattern != null) { XmlSchemaPatternFacet patternFacet = new XmlSchemaPatternFacet { Value = pattern.Value.ToString(), }; content.Facets.Add(patternFacet); } FormatKeyword format = jSchema.Get<FormatKeyword>(); if (format != null && format.Value != null && !string.IsNullOrEmpty(format.Value.Key)) { content.BaseTypeName = ExtractBaseTypeNameFromFormat(format.Value.Key); } return content; }
private static void KeywordEqual(FormatKeyword expected, FormatKeyword actual) { Assert.Equal(expected.Value.Key, actual.Value.Key); Assert.Equal(expected.Value, actual.Value); }