Code Generator¶
CLI Entry Point¶
$ xsdata --help
Usage: xsdata [OPTIONS] XSD_PATH
Options:
--package TEXT Target Package [required]
--renderer [pydata|plantuml] Output renderer
--print Preview the resulting classes.
-v, --verbosity LVL Either CRITICAL, ERROR, WARNING, INFO or DEBUG
--help Show this message and exit.
XSD Path¶
The generator doesn’t work with urls only with local files, if the given schema includes other schemas with urls the generator will fail. Every schema is evaluated once and in the order they are defined.
Circular dependencies will probably work just fine :)
Package¶
The package option defines where the target module(s) will be created inside the current working directory.
If the main xsd has any parent include or import you should adjust the target package.
Example
Output directory
./api/models
Main xsd
./api/air/AirReqRsp.xsd` that includes ``../common/CommonReqRsp.xsd
Adjust the package from
api.models
toapi.models.air
because the generator has to also create thecommon.common_req_rsp
module.
Renderer¶
The renderer option changes the output format.
pydata
: Python lib dataclassesplantuml
: PlantUML class diagram
Verbosity¶
The verbosity option changes what messages will be printed.
Available options: CRITICAL
, ERROR
, WARNING
, INFO
or DEBUG
Print¶
The print flag overwrites the verbosity level to Error and print to stdOut the output result without writing to the target file.
Examples¶
Check the samples repo for more.
Basic¶
@dataclass
class AirSearchParameters:
"""Search Parameters.
:ivar no_advance_purchase:
:ivar refundable_fares:
:ivar non_penalty_fares:
:ivar un_restricted_fares:
"""
class Meta:
namespace = "http://www.travelport.com/schema/common_v48_0"
no_advance_purchase: Optional[bool] = field(
default=None,
metadata=dict(
name="NoAdvancePurchase",
type="Attribute"
)
)
refundable_fares: Optional[bool] = field(
default=None,
metadata=dict(
name="RefundableFares",
type="Attribute"
)
)
non_penalty_fares: Optional[bool] = field(
default=None,
metadata=dict(
name="NonPenaltyFares",
type="Attribute"
)
)
un_restricted_fares: Optional[bool] = field(
default=None,
metadata=dict(
name="UnRestrictedFares",
type="Attribute"
)
)
Enum¶
class ModificationType(Enum):
"""The modification types supported.
:cvar ADD_SEGMENT: Add a segment to the itinerary
:cvar REMOVE_SEGMENT: Delete a segment from the itinerary
:cvar REPLACE_SEGMENT: Replace a segment in the itinerary with a new segment
:cvar ADD_PASSENGER: Add a passenger to the itinerary
:cvar REMOVE_PASSENGER: Remove a passenger from the itinerary
:cvar OPTIONS_ONLY: Modification where only options are added / removed from the itinerary
:cvar OTHER: Other modification types
"""
ADD_SEGMENT = "AddSegment"
REMOVE_SEGMENT = "RemoveSegment"
REPLACE_SEGMENT = "ReplaceSegment"
ADD_PASSENGER = "AddPassenger"
REMOVE_PASSENGER = "RemovePassenger"
OPTIONS_ONLY = "OptionsOnly"
OTHER = "Other"
Inner Class¶
@dataclass
class Auxdata:
"""
:ivar entry:
"""
class Meta:
namespace = "http://www.travelport.com/schema/common_v48_0"
entry: List["Auxdata.Entry"] = field(
default_factory=list,
metadata=dict(
name="Entry",
type="Element",
min_occurs=1,
max_occurs=999
)
)
@dataclass
class Entry:
"""
:ivar reason:
:ivar description:
"""
reason: Optional[str] = field(
default=None,
metadata=dict(
name="Reason",
type="Element",
required=True
)
)
description: Optional[str] = field(
default=None,
metadata=dict(
name="Description",
type="Element",
required=True
)
)