diff --git a/src/main.py b/src/main.py
index 3470ecf..42eef3b 100644
--- a/src/main.py
+++ b/src/main.py
@@ -28,59 +28,8 @@ def validate_dataclass_patterns(obj) -> None:
validate_dataclass_patterns(item)
def main():
- # Success - just use object() since it's defined as Optional[object]
- success = object()
-
- # Now we need to create the missing nested classes that aren't fully defined
- # Let's create minimal implementations for the empty classes
-
- # Create basic implementations for the empty nested classes
- class RoomType(ab.BaseModel):
- room_type_code: str = "A"
- room_classification_code: str = "5"
- room_type: str = "8"
-
- class GuestCount(ab.BaseModel):
- count: int = 1
-
- class TimeSpanImpl(ab.BaseModel):
- start: str
- end: str
-
- class PersonName(ab.BaseModel):
- given_name: str
- surname: str
-
- class Customer(ab.BaseModel):
- language: str = "de"
- gender: str = "Male" # Use valid gender
- person_name: PersonName
-
- class Profile(ab.BaseModel):
- customer: Customer
-
- class ProfileInfo(ab.BaseModel):
- profile: Profile
-
- class Profiles(ab.BaseModel):
- profile_info: ProfileInfo
-
- class ResGuest(ab.BaseModel):
- profiles: Profiles
-
- class HotelReservationId(ab.BaseModel):
- res_id_type: str
- res_id_source_context: str
- res_id_value: str
- res_id_source: str
-
- # Build the structure using the Pydantic models
- person_name = PersonName(given_name="Otto", surname="Mustermann")
- customer = Customer(person_name=person_name)
- profile = Profile(customer=customer)
- profile_info = ProfileInfo(profile=profile)
- profiles = Profiles(profile_info=profile_info)
- res_guest = ResGuest(profiles=profiles)
+ # Success - use None instead of object() for cleaner XML output
+ success = None
# UniqueID
unique_id = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.UniqueId(
@@ -88,28 +37,70 @@ def main():
id="6b34fe24ac2ff811"
)
+ # TimeSpan - use the actual nested class
+ time_span = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.RoomStays.RoomStay.TimeSpan()
+
+ # RoomStay with TimeSpan
+ room_stay = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.RoomStays.RoomStay(
+ time_span=time_span
+ )
+ room_stays = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.RoomStays(
+ room_stay=[room_stay]
+ )
+
+ profile = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGuests.ResGuest.Profiles.ProfileInfo.Profile(
+ customer=ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGuests.ResGuest.Profiles.ProfileInfo.Profile.Customer(
+ person_name=ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGuests.ResGuest.Profiles.ProfileInfo.Profile.Customer.PersonName(
+ given_name="John",
+ surname="Doe"
+ )
+ )
+ )
+
+ # Use the actual nested Profiles class
+
+
+ profile_info = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGuests.ResGuest.Profiles.ProfileInfo(
+ profile=profile)
+
+ profiles = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGuests.ResGuest.Profiles(profile_info=profile_info)
+
+ # ResGuest
+ res_guest = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGuests.ResGuest(
+ profiles=profiles
+ )
+ res_guests = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGuests(
+ res_guest=res_guest
+ )
+
+ # Use the actual nested HotelReservationIds class
+ hotel_res_ids = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo.HotelReservationIds(
+ hotel_reservation_id=[]
+ )
+
# Basic property info
basic_property_info = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo.BasicPropertyInfo(
hotel_code="123",
hotel_name="Frangart Inn"
)
- # Build a minimal reservation structure
+ # ResGlobalInfo
+ res_global_info = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo(
+ hotel_reservation_ids=hotel_res_ids,
+ basic_property_info=basic_property_info
+ )
+
+ # Hotel Reservation
hotel_reservation = ab.OtaResRetrieveRs.ReservationsList.HotelReservation(
create_date_time=datetime.now(timezone.utc).isoformat(),
res_status=ab.HotelReservationResStatus.REQUESTED,
room_stay_reservation="true",
- unique_id=unique_id
+ unique_id=unique_id,
+ room_stays=room_stays,
+ res_guests=res_guests,
+ res_global_info=res_global_info
)
- # Add the basic property info to res_global_info
- res_global_info = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo(
- basic_property_info=basic_property_info
- )
-
- # Update the hotel reservation with all required fields
- hotel_reservation.res_global_info = res_global_info
-
reservations_list = ab.OtaResRetrieveRs.ReservationsList(hotel_reservation=[hotel_reservation])
# Root element
@@ -135,7 +126,10 @@ def main():
)
serializer = XmlSerializer(config=config)
- xml_string = serializer.render(ota_res_retrieve_rs)
+
+ # Use ns_map to control namespace prefixes - set default namespace
+ ns_map = {None: "http://www.opentravel.org/OTA/2003/05"}
+ xml_string = serializer.render(ota_res_retrieve_rs, ns_map=ns_map)
with open('output.xml', 'w', encoding='utf-8') as outfile:
outfile.write(xml_string)
@@ -156,12 +150,11 @@ def main():
parsed_result = parser.from_string(xml_content, ab.OtaResRetrieveRs)
print("✅ Round-trip validation successful!")
- print(f"Parsed reservation status: {parsed_result.res_status}")
+ print(f"Parsed reservation status: {parsed_result.reservations_list.hotel_reservation[0].res_status}")
except Exception as e:
print(f"❌ Validation/Serialization failed: {e}")
-
if __name__ == "__main__":
main()
\ No newline at end of file
diff --git a/src/output.xml b/src/output.xml
index a8c0571..8b22f0d 100644
--- a/src/output.xml
+++ b/src/output.xml
@@ -1,12 +1,33 @@
-
- <object object at 0x7fd2fa5a0f40>
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ John
+ Doe
+
+
+
+
+
+
+
+
+
+
+
+
+
+