Skip to content

feature: support of pydantic-xml #40

@dmanuel64

Description

@dmanuel64

Is your feature request related to a problem? Please describe.

Similar to #27, it would be beneficial to add support for pydantic-xml within griffe-pydantic.

Currently, griffe-pydantic only handles Pydantic BaseModel classes, but does not recognize or enrich pydantic_xml.BaseXmlModel subclasses.

Describe the solution you'd like

Extend griffe-pydantic so subclasses of pydantic_xml.BaseXmlModel are treated like BaseModel subclasses, exposing their fields in extra metadata and rendering them through mkdocstrings templates.

At a minimum:

  • Compatibility with existing griffe-pydantic templates

Ideally (nice-to-have):

  • Extraction of XML binding metadata (from pydantic-xml field markers)

    • attr(...) → attribute
    • element(...) / default field → element
    • wrapped(...) → nested element
    • text(...) → text node
    • namespace / root element info when available

Describe alternatives you've considered

  • Documenting these models manually in Markdown.
  • Falling back to plain BaseModel for docs (but losing the built-in XML support)

Additional context

Here’s a small example that illustrates the bindings:

from pydantic_xml import BaseXmlModel, attr, element, text, wrapped

class Item(BaseXmlModel, tag="Item"):
    id: int = attr(name="id")
    name: str = element(name="Name")
    description: str | None = text()
    long_description: str | None = wrapped('LongDescription/Text')

It would be great if griffe-pydantic could expose both the normal Pydantic field info and the XML mapping (id → attribute, name → element, description → text).

Metadata

Metadata

Assignees

Labels

featureNew feature or requestgriffe extensionCan be solved with a Griffe extension

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions