Ejemplo n.º 1
0
    def check_merge_result(self, first, second, expected):
        first_copy = first.copy()
        second_copy = second.copy()

        merged = merge_schema(first, second)
        merged_reversed = merge_schema(second, first)

        self.assertEqual(merged, expected)
        self.assertEqual(merged_reversed, expected)
        self.assertEqual(merged, merged_reversed)

        # ensuring we're not touching the originals:
        self.assertEqual(first, first_copy)
        self.assertEqual(second, second_copy)
Ejemplo n.º 2
0
    def check_merge_result(self, first, second, expected):
        first_copy = first.copy()
        second_copy = second.copy()

        merged = merge_schema(first, second)
        merged_reversed = merge_schema(second, first)

        self.assertEqual(merged, expected)
        self.assertEqual(merged_reversed, expected)
        self.assertEqual(merged, merged_reversed)

        # ensuring we're not touching the originals:
        self.assertEqual(first, first_copy)
        self.assertEqual(second, second_copy)
Ejemplo n.º 3
0
def generate_and_merge_schemas(samples):
    """Iterates through the given samples, generating schemas
    and merging them, returning the resulting merged schema.

    """
    merged = generate_schema_for_sample(next(iter(samples)))

    for sample in samples:
        merged = merge_schema(merged, generate_schema_for_sample(sample))

    return merged
Ejemplo n.º 4
0
def generate_and_merge_schemas(samples):
    """Iterates through the given samples, generating schemas
    and merging them, returning the resulting merged schema.

    """
    merged = generate_schema_for_sample(next(iter(samples)))

    for sample in samples:
        merged = merge_schema(merged, generate_schema_for_sample(sample))

    return merged
Ejemplo n.º 5
0
 def test_merge_anyof(self):
     schema_with_anyof = {
         '$schema': 'http://json-schema.org/draft-04/schema',
         'type': 'object',
         'required': ['something'],
         'properties': {
             'something': {
                 'anyOf': [
                     {'type': 'string'},
                     {'type': 'null'},
                 ]
             }
         }
     }
     merged = merge_schema(fixtures.REQUIRING_SOME_PROPERTY, schema_with_anyof)
     self.assertSchemaEqual(merged, schema_with_anyof)
Ejemplo n.º 6
0
 def test_merge_string_and_null(self):
     merged = merge_schema(
         fixtures.REQUIRING_NULL_PROPERTY,
         fixtures.REQUIRING_SOME_PROPERTY,
     )
     expected = {
         '$schema': 'http://json-schema.org/draft-04/schema',
         'type': 'object',
         'required': ['something'],
         'properties': {
             'something': {
                 'anyOf': [
                     {'type': 'string'},
                     {'type': 'null'},
                 ]
             }
         }
     }
     self.assertSchemaEqual(merged, expected)
Ejemplo n.º 7
0
 def test_merge_anyof(self):
     schema_with_anyof = {
         '$schema': 'http://json-schema.org/draft-04/schema',
         'type': 'object',
         'required': ['something'],
         'properties': {
             'something': {
                 'anyOf': [
                     {
                         'type': 'string'
                     },
                     {
                         'type': 'null'
                     },
                 ]
             }
         }
     }
     merged = merge_schema(fixtures.REQUIRING_SOME_PROPERTY,
                           schema_with_anyof)
     self.assertSchemaEqual(merged, schema_with_anyof)
Ejemplo n.º 8
0
 def test_merge_string_and_null(self):
     merged = merge_schema(
         fixtures.REQUIRING_NULL_PROPERTY,
         fixtures.REQUIRING_SOME_PROPERTY,
     )
     expected = {
         '$schema': 'http://json-schema.org/draft-04/schema',
         'type': 'object',
         'required': ['something'],
         'properties': {
             'something': {
                 'anyOf': [
                     {
                         'type': 'string'
                     },
                     {
                         'type': 'null'
                     },
                 ]
             }
         }
     }
     self.assertSchemaEqual(merged, expected)