-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
Feature Request
I would like to be able to generate more types of references than can be created via a simple ref_prefix. For example, referencing a schema that resides in another file.
{ "$ref": "/schemas/Foo.json#/}
https://json-schema.org/understanding-json-schema/structuring.html#reuse
https://docs.opis.io/json-schema/1.x/pointers.html
Example
import json
from pydantic import BaseModel
from pydantic.schema import schema
class Foo(BaseModel):
a: int
class Model(BaseModel):
a: Foo
# Default location for OpenAPI
model_schema = Model.schema(ref_template='/schemas/{name}.json#/')
print(json.dumps(model_schema , indent=2)){
"Model": {
"title": "Model",
"type": "object",
"properties": {
"a": {
"$ref": "/schemas/Foo.json#/"
}
},
"required": ["a"]
}
}I believe python's string.Template could be a good way to implement this (which I have attempted).
There are still some details that need to be worked out.