Exemple #1
0
 def test_definitions_with_refs(self):
     loader = jsonschema2popo.JsonSchema2Popo(use_types=False,
                                              constructor_type_check=False)
     loader.process(
         json.loads("""{
         "definitions": {
             "ABcd": {
                 "type": "object",
                 "properties": {
                     "Child1": {
                         "type": "integer"
                     },
                     "Child2": {
                         "type": "string"
                     }
                 }
             },
             "SubRef": {
                 "type": "object",
                 "properties": {
                     "ChildA": {
                         "$ref": "#/definitions/ABcd"
                     }
                 }
             },
             "DirectRef": {
                 "$ref": "#/definitions/ABcd"
             }
         }
     }"""))
     loader.write_file(self.test_file)
     format_file(self.test_file)
     self.assertFileEqual(self.test_file,
                          "valid/test_definitions_with_refs.py")
Exemple #2
0
 def test_root_basic_generation(self):
     loader = jsonschema2popo.JsonSchema2Popo(use_types=False,
                                              constructor_type_check=False)
     loader.process(
         json.loads("""{
         "title": "ABcd",
         "type": "object",
         "properties": {
             "Int": {
                 "type": "integer"
             },
             "Float": {
                 "type": "number"
             },
             "ListInt": {
                 "type": "array",
                 "items": {
                     "type": "integer"
                 }
             },
             "String": {
                 "type": "string"
             },
             "Object": {
                 "type": "object"
             }
         }
     }"""))
     loader.write_file(self.test_file)
     format_file(self.test_file)
     self.assertFileEqual(self.test_file,
                          "valid/test_root_basic_generation.py")
Exemple #3
0
 def test_root_string_enum(self):
     loader = jsonschema2popo.JsonSchema2Popo(use_types=False,
                                              constructor_type_check=False)
     loader.process(
         json.loads("""{
         "title": "ABcd",
         "type": "string",
         "enum": ["A", "B", "C"]
     }"""))
     loader.write_file(self.test_file)
     format_file(self.test_file)
     self.assertFileEqual(self.test_file, "valid/test_root_string_enum.py")
Exemple #4
0
 def test_root_integer_enum(self):
     loader = jsonschema2popo.JsonSchema2Popo(use_types=False,
                                              constructor_type_check=False)
     loader.process(
         json.loads("""{
         "title": "ABcd",
         "type": "integer",
         "enum": [0, 1, 2, 3],
         "javaEnumNames": ["A", "B", "C", "D"]
     }"""))
     loader.write_file(self.test_file)
     format_file(self.test_file)
     self.assertFileEqual(self.test_file, "valid/test_root_integer_enum.py")
Exemple #5
0
 def test_definitions_nested_objects(self):
     loader = jsonschema2popo.JsonSchema2Popo(use_types=False,
                                              constructor_type_check=False)
     loader.process(
         json.loads("""{
         "definitions": {
             "ABcd": {
                 "type": "object",
                 "properties": {
                     "Child1": {
                         "type": "object",
                         "properties": {
                             "IntVal": {
                                 "type": "integer"
                             },
                             "Child2": {
                                 "type": "object",
                                 "properties": {
                                     "IntVal": {
                                         "type": "integer"
                                     },
                                     "ListVal": {
                                         "type": "array",
                                         "items": {
                                             "type": "string"
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }"""))
     loader.write_file(self.test_file)
     format_file(self.test_file)
     self.assertFileEqual(self.test_file,
                          "valid/test_definitions_nested_objects.py")