admin管理员组文章数量:1122846
I am trying to create the following JSON Schema
from pydantic import BaseModel, Field
class VendorInfo(BaseModel):
vendor_name: str = Field("", description= "Vendor Name")
vendor_vat_no: str = Field("", description= "Vendor VAT Number")
class InvoiceHeader(BaseModel):
invoice_number: str = Field("", description= "The unique invoice number")
invoice_date: str = Field("", description= "The date invoice was created")
vendor_info: VendorInfo = Field("", description= "Description of the vendor")
print(json.dumps(InvoiceHeader.model_json_schema(), indent=2))
This gives following output with $defs and $ref. How to remove them from schema?
{"$defs": {"VendorInfo": {"properties": {"vendor_name": {"default": "","description": "Vendor Name","title": "Vendor Name","type": "string"},"vendor_vat_no": {"default": "","description": "Vendor VAT Number","title": "Vendor Vat No","type": "string"}},"title": "VendorInfo","type": "object"}},"properties": {"invoice_number": {"default": "","description": "The unique invoice number","title": "Invoice Number","type": "string"},"invoice_date": {"default": "","description": "The date invoice was created","title": "Invoice Date","type": "string"},"vendor_info": {"$ref": "#/$defs/VendorInfo","default": "","description": "Description of the vendor"}},"title": "InvoiceHeader","type": "object"}
本文标签: jsonschemaHow to remove defs and ref when creating a nested JSON Schema using PydanticStack Overflow
版权声明:本文标题:jsonschema - How to remove $defs and $ref when creating a nested JSON Schema using Pydantic? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303404a1931874.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论