Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add definitions_path argument to __init__ for customization #179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions marshmallow_jsonschema/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def __init__(self, *args, **kwargs) -> None:
self._nested_schema_classes: typing.Dict[str, typing.Dict[str, typing.Any]] = {}
self.nested = kwargs.pop("nested", False)
self.props_ordered = kwargs.pop("props_ordered", False)
self.definitions_path = kwargs.pop("definitions_path", "definitions")
setattr(self.opts, "ordered", self.props_ordered)
super().__init__(*args, **kwargs)

Expand Down Expand Up @@ -326,7 +327,7 @@ def _from_nested_schema(self, obj, field):
self._nested_schema_classes.update(wrapped_nested._nested_schema_classes)

# and the schema is just a reference to the def
schema = {"type": "object", "$ref": "#/definitions/{}".format(name)}
schema = {"type": "object", "$ref": "#/{}/{}".format(self.definitions_path, name)}

# NOTE: doubled up to maintain backwards compatibility
metadata = field.metadata.get("metadata", {})
Expand Down Expand Up @@ -367,7 +368,7 @@ def wrap(self, data, **_) -> typing.Dict[str, typing.Any]:
self._nested_schema_classes[name] = data
root = {
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": self._nested_schema_classes,
"$ref": "#/definitions/{name}".format(name=name),
self.definitions_path: self._nested_schema_classes,
"$ref": "#/{path}/{name}".format(path=self.definitions_path, name=name),
}
return root
Loading