Code Generator

CLI Entry Point

$ xsdata --help
Usage: xsdata [OPTIONS] XSD_PATH

Options:
  --package TEXT       Target Package  [required]
  --renderer [pydata]  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 to api.models.air because the generator has to also create the common.common_req_rsp module.

Renderer

The renderer option changes the output format.

Print

The print flag bypasses the file writer and instead prints a quick preview of what the generator would create otherwise.

It’s a very useful option when the class building process changes with new features.

Example Output

samples.sabre.output.bargain_finder_max_common_types_v1_9_7.AdvResTicketingType()
    adv_res_ind: Optional[bool] = [('default', None)]
    adv_reservation: Optional["AdvResTicketingType.AdvReservation"] = [('default', None)]
    adv_ticketing: Optional["AdvResTicketingType.AdvTicketing"] = [('default', None)]
    adv_ticketing_ind: Optional[bool] = [('default', None)]

    samples.sabre.output.bargain_finder_max_common_types_v1_9_7.AdvResTicketingType.AdvReservation()
        latest_period: Optional[str] = [('default', None), ('pattern', '[0-9]{1,3}')]
        latest_time_of_day: Optional[str] = [('default', None)]
        latest_unit: Optional[StayUnitType] = [('default', None)]

    samples.sabre.output.bargain_finder_max_common_types_v1_9_7.AdvResTicketingType.AdvTicketing()
        from_depart_period: Optional[str] = [('default', None), ('pattern', '[0-9]{1,3}')]
        from_depart_time_of_day: Optional[str] = [('default', None)]
        from_depart_unit: Optional[StayUnitType] = [('default', None)]
        from_res_period: Optional[str] = [('default', None), ('pattern', '[0-9]{1,3}')]
        from_res_time_of_day: Optional[str] = [('default', None)]
        from_res_unit: Optional[StayUnitType] = [('default', None)]

samples.sabre.output.bargain_finder_max_common_types_v1_9_7.AirTripType(str)
    CIRCLE: xs:string = [('default', '"Circle"')]
    ONE_WAY: xs:string = [('default', '"OneWay"')]
    OPEN_JAW: xs:string = [('default', '"OpenJaw"')]
    OTHER: xs:string = [('default', '"Other"')]
    RETURN_VALUE: xs:string = [('default', '"Return"')]

Verbosity

The verbosity option changes what messages will be printed.

Available options: CRITICAL, ERROR, WARNING, INFO or DEBUG

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
            )
        )