Exemplo n.º 1
0
        public static void IsEquivalentTo(JsonSchema expected, JsonSchema actual)
        {
            if (expected.Keywords == null)
            {
                Assert.Null(actual.Keywords);
                return;
            }

            foreach (IJsonSchemaKeyword expectedKeyword in expected.Keywords)
            {
                IJsonSchemaKeyword actualKeyword = actual.Keywords !.SingleOrDefault(kw => string.Equals(expectedKeyword.Keyword(), kw.Keyword()));
                if (actualKeyword == null)
                {
                    throw new ContainsException(expectedKeyword.Keyword(), actual.Keywords);
                }

                IsEquivalentTo(expectedKeyword, actualKeyword);
            }

            foreach (IJsonSchemaKeyword actualKeyword in actual.Keywords !)
            {
                IJsonSchemaKeyword expectedKeyword = expected.Keywords.SingleOrDefault(kw => string.Equals(actualKeyword.Keyword(), kw.Keyword()));
                if (expectedKeyword == null)
                {
                    throw new DoesNotContainException(expected.Keywords, actualKeyword.Keyword());
                }

                IsEquivalentTo(expectedKeyword, actualKeyword);
            }
        }
Exemplo n.º 2
0
        private void ProcessKeyword(JsonPointer path, IJsonSchemaKeyword keyword, SchemaContext context)
        {
            switch (keyword)
            {
            // We only travese the actual schema and their referenced/used sub-schemas.
            // This means that there might be types defined in $def/definitions that is
            // not included in the generated model - which is fine since they are not in use.
            case SchemaKeyword:
            case IdKeyword:
            case TypeKeyword:
            case ConstKeyword:
            case XsdNamespacesKeyword:
            case XsdSchemaAttributesKeyword:
            case XsdUnhandledAttributesKeyword:
            case XsdUnhandledEnumAttributesKeyword:
            case XsdTypeKeyword:
            case XsdAttributeKeyword:
            case XsdAnyAttributeKeyword:
            case InfoKeyword:
            case RequiredKeyword:
            case EnumKeyword:
            case DefinitionsKeyword:
            case DefsKeyword:
                break;

            case RefKeyword k:
                ProcessRefKeyword(path, k, context);
                break;

            case OneOfKeyword k:
                ProcessOneOfKeyword(path, k, context);
                break;

            case AllOfKeyword k:
                ProcessAllOfKeyword(path, k, context);
                break;

            case AnyOfKeyword k:
                ProcessAnyOfKeyword(path, k, context);
                break;

            case PropertiesKeyword k:
                ProcessPropertiesKeyword(path, k, context);
                break;

            default:
                throw new NotImplementedException($"Keyword {keyword.Keyword()} not processed!");
            }

            OnKeywordProcessed(new KeywordProcessedEventArgs()
            {
                Path = path, Keyword = keyword
            });
        }
Exemplo n.º 3
0
 /// <summary>
 /// Adds a new keyword.
 /// </summary>
 /// <param name="keyword">The keyword to add.</param>
 public void Add(IJsonSchemaKeyword keyword)
 {
     _keywords[keyword.Keyword()] = keyword;
 }
Exemplo n.º 4
0
        public static void IsEquivalentTo(IJsonSchemaKeyword expected, IJsonSchemaKeyword actual)
        {
            if (expected == null)
            {
                Assert.Null(actual);
                return;
            }

            Assert.NotNull(actual);

            Assert.IsType(expected.GetType(), actual);
            Assert.Equal(expected.Keyword(), actual.Keyword());

            switch (expected)
            {
            case AdditionalItemsKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (AdditionalItemsKeyword)actual);
                break;

            case AdditionalPropertiesKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (AdditionalPropertiesKeyword)actual);
                break;

            case AllOfKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (AllOfKeyword)actual);
                break;

            case AnchorKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (AnchorKeyword)actual);
                break;

            case AnyOfKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (AnyOfKeyword)actual);
                break;

            case CommentKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (CommentKeyword)actual);
                break;

            case ConstKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (ConstKeyword)actual);
                break;

            case ContainsKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (ContainsKeyword)actual);
                break;

            case ContentMediaEncodingKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (ContentMediaEncodingKeyword)actual);
                break;

            case ContentMediaTypeKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (ContentMediaTypeKeyword)actual);
                break;

            case ContentSchemaKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (ContentSchemaKeyword)actual);
                break;

            case DefaultKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (DefaultKeyword)actual);
                break;

            case DefinitionsKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (DefinitionsKeyword)actual);
                break;

            case DefsKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (DefsKeyword)actual);
                break;

            case DependenciesKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (DependenciesKeyword)actual);
                break;

            case DependentRequiredKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (DependentRequiredKeyword)actual);
                break;

            case DependentSchemasKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (DependentSchemasKeyword)actual);
                break;

            case DeprecatedKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (DeprecatedKeyword)actual);
                break;

            case DescriptionKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (DescriptionKeyword)actual);
                break;

            case DynamicAnchorKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (DynamicAnchorKeyword)actual);
                break;

            case DynamicRefKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (DynamicRefKeyword)actual);
                break;

            case ElseKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (ElseKeyword)actual);
                break;

            case EnumKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (EnumKeyword)actual);
                break;

            case ExamplesKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (ExamplesKeyword)actual);
                break;

            case ExclusiveMaximumKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (ExclusiveMaximumKeyword)actual);
                break;

            case ExclusiveMinimumKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (ExclusiveMinimumKeyword)actual);
                break;

            case FormatKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (FormatKeyword)actual);
                break;

            case IdKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (IdKeyword)actual);
                break;

            case IfKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (IfKeyword)actual);
                break;

            case ItemsKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (ItemsKeyword)actual);
                break;

            case MaxContainsKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (MaxContainsKeyword)actual);
                break;

            case MaximumKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (MaximumKeyword)actual);
                break;

            case MaxItemsKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (MaxItemsKeyword)actual);
                break;

            case MaxLengthKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (MaxLengthKeyword)actual);
                break;

            case MaxPropertiesKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (MaxPropertiesKeyword)actual);
                break;

            case MinContainsKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (MinContainsKeyword)actual);
                break;

            case MinimumKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (MinimumKeyword)actual);
                break;

            case MinItemsKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (MinItemsKeyword)actual);
                break;

            case MinLengthKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (MinLengthKeyword)actual);
                break;

            case MinPropertiesKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (MinPropertiesKeyword)actual);
                break;

            case MultipleOfKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (MultipleOfKeyword)actual);
                break;

            case NotKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (NotKeyword)actual);
                break;

            case OneOfKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (OneOfKeyword)actual);
                break;

            case PatternKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (PatternKeyword)actual);
                break;

            case PatternPropertiesKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (PatternPropertiesKeyword)actual);
                break;

            case PrefixItemsKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (PrefixItemsKeyword)actual);
                break;

            case PropertiesKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (PropertiesKeyword)actual);
                break;

            case PropertyNamesKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (PropertyNamesKeyword)actual);
                break;

            case ReadOnlyKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (ReadOnlyKeyword)actual);
                break;

            case RecursiveAnchorKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (RecursiveAnchorKeyword)actual);
                break;

            case RecursiveRefKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (RecursiveRefKeyword)actual);
                break;

            case RefKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (RefKeyword)actual);
                break;

            case RequiredKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (RequiredKeyword)actual);
                break;

            case SchemaKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (SchemaKeyword)actual);
                break;

            case ThenKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (ThenKeyword)actual);
                break;

            case TitleKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (TitleKeyword)actual);
                break;

            case TypeKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (TypeKeyword)actual);
                break;

            case UnevaluatedItemsKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (UnevaluatedItemsKeyword)actual);
                break;

            case UnevaluatedPropertiesKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (UnevaluatedPropertiesKeyword)actual);
                break;

            case UniqueItemsKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (UniqueItemsKeyword)actual);
                break;

            case VocabularyKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (VocabularyKeyword)actual);
                break;

            case WriteOnlyKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (WriteOnlyKeyword)actual);
                break;

            case InfoKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (InfoKeyword)actual);
                break;

            case XsdAnyAttributeKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (XsdAnyAttributeKeyword)actual);
                break;

            case XsdAnyKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (XsdAnyKeyword)actual);
                break;

            case XsdAttributeKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (XsdAttributeKeyword)actual);
                break;

            case XsdRestrictionsKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (XsdRestrictionsKeyword)actual);
                break;

            case XsdStructureKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (XsdStructureKeyword)actual);
                break;

            case XsdTypeKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (XsdTypeKeyword)actual);
                break;

            case XsdUnhandledAttributesKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (XsdUnhandledAttributesKeyword)actual);
                break;

            case XsdNamespacesKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (XsdNamespacesKeyword)actual);
                break;

            case XsdSchemaAttributesKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (XsdSchemaAttributesKeyword)actual);
                break;

            case XsdUnhandledEnumAttributesKeyword expectedKeyword:
                KeywordEqual(expectedKeyword, (XsdUnhandledEnumAttributesKeyword)actual);
                break;

            default:
                throw new ArgumentOutOfRangeException(expected.GetType().Name, "Unknown Json Schema Keyword");
            }
        }