class BssProviderSerializer(serpy.DictSerializer): network = Field(schema_type=str, display_none=True) operators = jsonschema.Field(schema_type=str, display_none=True, many=True)
class MessageSerializer(PbNestedSerializer): text = jsonschema.Field(schema_type=str) channel = ChannelSerializer()
class AdminSerializer(PbGenericSerializer): level = jsonschema.Field(schema_type=int) zip_code = jsonschema.Field(schema_type=str, display_none=True) label = jsonschema.Field(schema_type=str) insee = jsonschema.Field(schema_type=str) coord = CoordSerializer(required=False)
class JourneyPatternPointSerializer(PbNestedSerializer): id = jsonschema.Field(attr='uri', display_none=True, schema_type=str) stop_point = StopPointSerializer(display_none=False)
class VJDisplayInformationSerializer(RouteDisplayInformationSerializer): description = jsonschema.Field(schema_type=str) physical_mode = jsonschema.Field(schema_type=str) equipments = Equipments(attr='has_equipments', display_none=True) headsign = jsonschema.Field(schema_type=str, display_none=True) headsigns = StringListField(display_none=False)
class RidesharingInformationSerializer(PbNestedSerializer): operator = jsonschema.Field(schema_type=str, display_none=True) network = jsonschema.Field(schema_type=str, display_none=True) driver = IndividualInformationSerializer(display_none=False) seats = SeatsDescriptionSerializer(display_none=False)
class DisruptionPropertySerializer(PbNestedSerializer): key = jsonschema.Field(schema_type=str) _type = jsonschema.Field(attr='type', label='type', schema_type=str) value = jsonschema.Field(schema_type=str)
class SectionGeoJsonSchema(serpy.Serializer): """used not as a serializer, but only for the schema""" type = StrField() coordinates = jsonschema.Field(schema_metadata=point_2D_schema)
class NoteSerializer(serpy.Serializer): type = jsonschema.Field(schema_type=str) id = jsonschema.Field(schema_type=str, display_none=True) value = jsonschema.Field(schema_type=str) category = jsonschema.Field(schema_type=str, schema_metadata={'enum': ['comment', 'terminus']})
class SeveritySerializer(PbNestedSerializer): name = jsonschema.Field(schema_type=str) effect = jsonschema.Field(schema_type=str) color = jsonschema.Field(schema_type=str) priority = jsonschema.Field(schema_type=int)
class CommentSerializer(serpy.Serializer): value = jsonschema.Field(schema_type=str) type = jsonschema.Field(schema_type=str)
class StopTimeSerializer(PbNestedSerializer): arrival_time = LocalTimeField() departure_time = LocalTimeField() headsign = jsonschema.Field(schema_type=str) journey_pattern_point = JourneyPatternPointSerializer() stop_point = StopPointSerializer()
class MultiLineStringSchema(serpy.Serializer): """used not as a serializer, but only for the schema""" type = StrField() coordinates = jsonschema.Field(schema_metadata={'type': 'array', 'items': point_2D_schema})
class FareZoneSerializer(serpy.Serializer): name = jsonschema.Field(schema_type=str)
class IndividualRatingSerializer(PbNestedSerializer): value = jsonschema.Field(schema_type=float, display_none=True) count = jsonschema.Field(schema_type=int, display_none=False) scale_min = jsonschema.Field(schema_type=float, display_none=False) scale_max = jsonschema.Field(schema_type=float, display_none=False)
class ExceptionSerializer(serpy.Serializer): type = jsonschema.Field(schema_type=str) id = jsonschema.Field(schema_type=str, display_none=True) date = Field(attr='date', schema_type=DateTimeType)
class IndividualInformationSerializer(PbNestedSerializer): alias = jsonschema.Field(schema_type=str, display_none=True) image = jsonschema.Field(schema_type=str, display_none=False) gender = EnumField(attr='gender', pb_type=GenderType) rating = IndividualRatingSerializer(display_none=False)
class PropertySerializer(serpy.Serializer): name = jsonschema.Field(schema_type=str) value = jsonschema.Field(schema_type=str)
class SectionSerializer(PbNestedSerializer): id = jsonschema.Field(schema_type=str, display_none=True) duration = jsonschema.Field( schema_type=int, display_none=True, description='Duration of the section (seconds)') co2_emission = AmountSerializer(display_none=True) transfer_type = EnumField(attr='transfer_type', pb_type=TransferType) departure_date_time = DateTimeField( attr='begin_date_time', description='Departure date and time of the section') arrival_date_time = DateTimeField( attr='end_date_time', description='Arrival date and time of the section') base_departure_date_time = DateTimeField( attr='base_begin_date_time', description='Base-schedule departure date and time of the section') base_arrival_date_time = DateTimeField( attr='base_end_date_time', description='Base-schedule arrival date and time of the section') data_freshness = EnumField(attr="realtime_level", pb_type=RTLevel, display_none=False) to = jsonschema.MethodField(schema_type=PlaceSerializer(), attr='destination') def get_to(self, obj): if obj.HasField(str('type')): enum = obj.DESCRIPTOR.fields_by_name[ 'type'].enum_type.values_by_number ret_value = enum[getattr(obj, 'type')].name if ret_value == 'WAITING': return None return PlaceSerializer(obj.destination).data _from = jsonschema.MethodField(schema_type=PlaceSerializer(), attr='origin', label='from') def get__from(self, obj): if obj.HasField(str('type')): enum = obj.DESCRIPTOR.fields_by_name[ 'type'].enum_type.values_by_number ret_value = enum[getattr(obj, 'type')].name if ret_value == 'WAITING': return None return PlaceSerializer(obj.origin).data additional_informations = EnumListField( attr='additional_informations', pb_type=SectionAdditionalInformationType) geojson = SectionGeoJsonField( display_none=False, description='GeoJSON of the shape of the section') mode = NestedEnumField(attr='street_network.mode', pb_type=StreetNetworkMode) type = SectionTypeEnum(attr='type', pb_type=SectionType) display_informations = VJDisplayInformationSerializer( attr='pt_display_informations', display_none=False) links = jsonschema.MethodField(display_none=True, schema_type=LinkSchema(many=True)) def get_links(self, obj): response = [] if obj.HasField(str("uris")): for type_, value in obj.uris.ListFields(): response.append({"type": type_.name, "id": value}) if obj.HasField(str('pt_display_informations')): response.extend(base.make_notes(obj.pt_display_informations.notes)) if obj.HasField(str('ridesharing_information')): response.extend([{ "type": "ridesharing_ad", "rel": l.key, "href": l.href, "internal": False } for l in obj.ridesharing_information.links]) return response stop_date_times = StopDateTimeSerializer(many=True) path = PathSerializer(attr="street_network.path_items", many=True, display_none=False) ridesharing_informations = RidesharingInformationSerializer( attr='ridesharing_information', display_none=False) ridesharing_journeys = jsonschema.MethodField( schema_type=lambda: JourneySerializer(display_none=False, many=True)) def get_ridesharing_journeys(self, obj): if not hasattr(obj, 'ridesharing_journeys') or not obj.ridesharing_journeys: return None return JourneySerializer(obj.ridesharing_journeys, display_none=False, many=True).data cycle_lane_length = PbIntField(display_none=False)
class CodeSerializer(serpy.Serializer): type = jsonschema.Field(schema_type=str) value = jsonschema.Field(schema_type=str)
class PtObjectSerializer(PbGenericSerializer): quality = jsonschema.Field(schema_type=int, required=False, display_none=True, deprecated=True) stop_area = jsonschema.MethodField( schema_type=lambda: StopAreaSerializer()) stop_point = jsonschema.MethodField( schema_type=lambda: StopPointSerializer()) line = jsonschema.MethodField(schema_type=lambda: LineSerializer()) network = jsonschema.MethodField(schema_type=lambda: NetworkSerializer()) route = jsonschema.MethodField(schema_type=lambda: RouteSerializer()) commercial_mode = jsonschema.MethodField( schema_type=lambda: CommercialModeSerializer()) trip = jsonschema.MethodField(schema_type=lambda: TripSerializer()) embedded_type = EnumField(attr='embedded_type', pb_type=NavitiaType, display_none=True) def get_trip(self, obj): if obj.HasField(str('trip')): return TripSerializer(obj.trip, display_none=False).data else: return None def get_commercial_mode(self, obj): if obj.HasField(str('commercial_mode')): return CommercialModeSerializer(obj.commercial_mode, display_none=False).data else: return None def get_route(self, obj): if obj.HasField(str('route')): return RouteSerializer(obj.route, display_none=False).data else: return None def get_network(self, obj): if obj.HasField(str('network')): return NetworkSerializer(obj.network, display_none=False).data else: return None def get_line(self, obj): if obj.HasField(str('line')): return LineSerializer(obj.line, display_none=False).data else: return None def get_stop_area(self, obj): if obj.HasField(str('stop_area')): return StopAreaSerializer(obj.stop_area, display_none=False).data else: return None def get_stop_point(self, obj): if obj.HasField(str('stop_point')): return StopPointSerializer(obj.stop_point, display_none=False).data else: return None
class CostSerializer(PbNestedSerializer): value = StrField() currency = jsonschema.Field(schema_type=str)
class ContributorSerializer(PbGenericSerializer): website = jsonschema.Field(schema_type=str) license = jsonschema.Field(schema_type=str)
class DurationsSerializer(PbNestedSerializer): total = jsonschema.Field(schema_type=int, display_none=True, description='Total duration of the journey (seconds)') walking = jsonschema.Field(schema_type=int, display_none=True, description='Walking total duration of the journey (seconds)')
class ChannelSerializer(PbNestedSerializer): content_type = jsonschema.Field(schema_type=str, display_none=True) id = jsonschema.Field(schema_type=str, display_none=True) name = jsonschema.Field(schema_type=str, display_none=True) types = EnumListField(attr='channel_types', pb_type=Channel.ChannelType) # type: ignore
class JsonchemaMetadata(serpy.Serializer): metadata = jsonschema.Field(schema_metadata={ "type": "string", "description": "meta" })
class SeveritySerializer(PbNestedSerializer): name = jsonschema.Field(schema_type=str) effect = EnumField(pb_type=Severity.Effect, lower_case=False) # type: ignore color = jsonschema.Field(schema_type=str) priority = jsonschema.Field(schema_type=int)
class PathSerializer(PbNestedSerializer): length = RoundedField(display_none=True) name = jsonschema.Field(schema_type=str, display_none=True) duration = RoundedField(display_none=True) direction = jsonschema.Field(schema_type=int, display_none=True)
class AddressSerializer(PbGenericSerializer): house_number = jsonschema.Field(schema_type=int, display_none=True) coord = CoordSerializer(required=False) label = jsonschema.Field(schema_type=str, display_none=False) administrative_regions = AdminSerializer(many=True, display_none=False)
class PbGenericSerializer(PbNestedSerializer): id = jsonschema.Field(schema_type=str, display_none=True, attr='uri', description='Identifier of the object') name = jsonschema.Field(schema_type=str, display_none=True, description='Name of the object')