File: codegen.rst

package info (click to toggle)
python-xsdata 24.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,936 kB
  • sloc: python: 29,257; xml: 404; makefile: 27; sh: 6
file content (146 lines) | stat: -rw-r--r-- 3,440 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
============
Command Line
============


Make sure the cli requirements are installed.

.. code-block:: console

    $ pip install xsdata[cli]


.. cli:: xsdata --help


Generate Code
=============

.. cli:: xsdata generate --help

.. admonition:: See also
    :class: hint

    - :ref:`Compound fields <Type: Elements>`
    - :ref:`Docstring styles`
    - :ref:`Dataclasses Features`


.. code-block:: console
    :caption: Scan directory for xsd, dtd, wsdl, xml or json files

    $ xsdata amadeus/schemas --package amadeus.models


.. code-block:: console
    :caption: Convert a local schema

    $ xsdata air_v48_0/AirReqRsp.xsd --package travelport.models


.. code-block:: console
    :caption: Convert a remote schema

    $ xsdata http://www.gstatic.com/localfeed/local_feed.xsd --package feeds --print

.. code-block:: console
    :caption: Convert a remote xml file

    $ xsdata https://musicbrainz.org/ws/2/artist/1f9df192-a621-4f54-8850-2c5373b7eac9 --print


Output plugins
--------------

- `PlantUML <https://github.com/tefra/xsdata-plantuml>`_ class diagrams


Circular imports
----------------

Python is vulnerable to xsd circular imports. xsData by default groups all classes
by the schema location they are defined. This works well for schemas that avoid circular
imports. If you get import errors you should try one of the alternative structure
styles.

**clusters**

This style will identify the strongly connected classes and will group them together,
creating as many modules as possible. The modules are named after the the main class
of the group.

.. code-block:: console

    $ xsdata schema.xsd --package models --structure-style clusters


**namespaces**

This style will group classes by the target namespace they were originally defined. It
works well when the types of a namespace are spread across multiple schemas eg.
type substitutions, redefines.

.. code-block:: console

    $ xsdata schema.xsd --package models --structure-style namespaces


Since v21.8, the generator converts namespaces to packages similar to jaxb in order
to facilitate runs against multiple schemas from the same vendor.

.. list-table::
    :widths: 20 20
    :header-rows: 1

    * - Examples (before naming conventions)
      -
    * - http://www.w3.org/XML/1998/namespace
      - org.w3.xml.1998.namespace
    * - myNS.tempuri.org
      - org.tempuri.myNS
    * - urn:xmlns:25hoursaday-com:address
      - com.25hoursaday.address


**namespace-clusters**

This style combines the clusters and the namespace styles. It will fail if there
are strongly connected classes in the same graph from different namespaces.

.. code-block:: console

    $ xsdata schema.xsd --package models --structure-style namespace-clusters


**single-package**

This style will group all classes together into a single package eliminating imports
altogether.

.. code-block:: console

    $ xsdata schema.xsd --package models --structure-style single-package


Initialize Config
=================

Initialize a project configuration with more advanced features, see
:ref:`more <Generator Config>`.

.. cli:: xsdata init-config --help

.. code-block:: console

    $ xsdata amadeus/schemas --config amadeus/.xsdata.xml


Download Schemas
================

.. cli:: xsdata download --help

.. admonition:: Examples
    :class: hint

    Check the :doc:`examples` and the `samples repo <https://github.com/tefra/xsdata-samples>`_ for more ✨✨✨