# Buggy code
def parse_ref(self, obj: JsonSchemaObject) -> None:
    if obj.ref:
        ref: str = obj.ref
        # https://swagger.io/docs/specification/using-ref/
        if obj.ref.startswith("#"):
            # Local Reference – $ref: '#/definitions/myElement'
            pass
        elif "://" in ref:
            # URL Reference – $ref: 'http://path/to/your/resource' Uses the whole document located on the different server.
            raise NotImplementedError(f"URL Reference is not supported. $ref:{ref}")

        else:
            # Remote Reference – $ref: 'document.json' Uses the whole document located on the same server and in the same location.
            # TODO treat edge case
            relative_path, object_path = ref.split("#/")
            full_path = self.base_path / relative_path
            with full_path.open() as f:
                if full_path.suffix.lower() == ".json":
                    import json

                    ref_body: Dict[str, Any] = json.load(f)
                else:
                    # expect yaml
                    import yaml

                    ref_body = yaml.safe_load(f)
                object_parents = object_path.split("/")
                ref_path = str(full_path) + "#/" + object_path
                if ref_path not in self.excludes_ref_path:
                    self.excludes_ref_path.add(str(full_path) + "#/" + object_path)
                    model = get_model_by_path(ref_body, object_parents)
                    self.parse_raw_obj(object_parents[-1], model)

    if obj.items:
        if isinstance(obj.items, JsonSchemaObject):
            self.parse_ref(obj.items)
        else:
            for item in obj.items:
                self.parse_ref(item)
    if isinstance(obj.additionalProperties, JsonSchemaObject):
        self.parse_ref(obj.additionalProperties)
    for item in obj.anyOf:
        self.parse_ref(item)
    for item in obj.allOf:
        self.parse_ref(item)
    if obj.properties:
        for value in obj.properties.values():
            self.parse_ref(value)


# Traceback (pydantic.error_wrappers.ValidationError)
Traceback (most recent call last):
File "/proj/.venv/bin/datamodel-codegen", line 8, in <module>
sys.exit(main())
File "/proj/.venv/lib/python3.7/site-packages/datamodel_code_generator/__main__.py", line 168, in main
result = parser.parse()
File "/proj/.venv/lib/python3.7/site-packages/datamodel_code_generator/parser/base.py", line 164, in parse
self.parse_raw()
File "/proj/.venv/lib/python3.7/site-packages/datamodel_code_generator/parser/jsonschema.py", line 472, in parse_raw
self.parse_raw_obj(obj_name, raw_obj)
File "/proj/.venv/lib/python3.7/site-packages/datamodel_code_generator/parser/jsonschema.py", line 455, in parse_raw_obj
obj = JsonSchemaObject.parse_obj(raw)
File "/proj/.venv/lib/python3.7/site-packages/pydantic/main.py", line 402, in parse_obj
return cls(**obj)
File "/proj/.venv/lib/python3.7/site-packages/pydantic/main.py", line 283, in __init__
raise validation_error
pydantic.error_wrappers.ValidationError: 2 validation errors for JsonSchemaObject
properties -> apiVersion -> type
str type expected (type=type_error.str)
properties -> kind -> type
str type expected (type=type_error.str)

# Fixed code
def parse_ref(self, obj: JsonSchemaObject) -> None:
    if obj.ref:
        ref: str = obj.ref
        # https://swagger.io/docs/specification/using-ref/
        if obj.ref.startswith("#"):
            # Local Reference – $ref: '#/definitions/myElement'
            pass
        elif "://" in ref:
            # URL Reference – $ref: 'http://path/to/your/resource' Uses the whole document located on the different server.
            raise NotImplementedError(f"URL Reference is not supported. $ref:{ref}")

        else:
            # Remote Reference – $ref: 'document.json' Uses the whole document located on the same server and in the same location.
            # TODO treat edge case
            relative_path, object_path = ref.split("#/")
            full_path = self.base_path / relative_path
            with full_path.open() as f:
                if full_path.suffix.lower() == ".json":
                    import json

                    ref_body: Dict[str, Any] = json.load(f)
                else:
                    # expect yaml
                    import yaml

                    ref_body = yaml.safe_load(f)
                object_parents = object_path.split("/")
                ref_path = str(full_path) + "#/" + "/".join(object_parents[:-1])
                if ref_path not in self.excludes_ref_path:
                    self.excludes_ref_path.add(ref_path)
                    models = get_model_by_path(ref_body, object_parents[:-1])
                    for model_name, model in models.items():
                        self.parse_raw_obj(model_name, model)

    if obj.items:
        if isinstance(obj.items, JsonSchemaObject):
            self.parse_ref(obj.items)
        else:
            for item in obj.items:
                self.parse_ref(item)
    if isinstance(obj.additionalProperties, JsonSchemaObject):
        self.parse_ref(obj.additionalProperties)
    for item in obj.anyOf:
        self.parse_ref(item)
    for item in obj.allOf:
        self.parse_ref(item)
    if obj.properties:
        for value in obj.properties.values():
            self.parse_ref(value)