Skip to content

Commit 2567791

Browse files
committed
editoast: refacto path item location to add track and label information
Signed-off-by: Youness CHRIFI ALAOUI <[email protected]>
1 parent 1891f5b commit 2567791

File tree

8 files changed

+304
-76
lines changed

8 files changed

+304
-76
lines changed

editoast/editoast_schemas/src/train_schedule.rs

+3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ pub use schedule_item::ReceptionSignal;
77
pub use schedule_item::ScheduleItem;
88

99
mod path_item;
10+
pub use path_item::OperationalPointIdentifier;
11+
pub use path_item::OperationalPointReference;
1012
pub use path_item::PathItem;
1113
pub use path_item::PathItemLocation;
14+
pub use path_item::TrackReference;
1215

1316
mod train_schedule_options;
1417
pub use train_schedule_options::TrainScheduleOptions;

editoast/editoast_schemas/src/train_schedule/path_item.rs

+30
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use crate::infra::TrackOffset;
99
editoast_common::schemas! {
1010
PathItem,
1111
PathItemLocation,
12+
OperationalPointReference,
13+
TrackReference,
1214
}
1315

1416
/// A location on the path of a train
@@ -32,6 +34,34 @@ pub struct PathItem {
3234
#[serde(untagged, deny_unknown_fields)]
3335
pub enum PathItemLocation {
3436
TrackOffset(#[schema(inline)] TrackOffset),
37+
OperationalPointReference(#[schema(inline)] OperationalPointReference),
38+
}
39+
40+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema, Hash)]
41+
pub struct OperationalPointReference {
42+
#[serde(flatten)]
43+
#[schema(inline)]
44+
pub reference: OperationalPointIdentifier,
45+
#[serde(default)]
46+
pub track_reference: Option<TrackReference>,
47+
}
48+
49+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema, Hash)]
50+
#[serde(untagged, deny_unknown_fields)]
51+
pub enum TrackReference {
52+
Id {
53+
#[schema(inline)]
54+
track_id: Identifier,
55+
},
56+
Name {
57+
#[schema(inline)]
58+
track_name: NonBlankString,
59+
},
60+
}
61+
62+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema, Hash)]
63+
#[serde(untagged, deny_unknown_fields)]
64+
pub enum OperationalPointIdentifier {
3565
OperationalPointId {
3666
/// The object id of an operational point
3767
#[schema(inline)]

editoast/editoast_schemas/src/train_schedule/train_schedule_base.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ mod tests {
162162
use serde_json::from_str;
163163
use serde_json::to_string;
164164

165+
use crate::train_schedule::path_item::OperationalPointIdentifier::OperationalPointId;
166+
use crate::train_schedule::path_item::OperationalPointReference;
165167
use crate::train_schedule::schedule_item::ReceptionSignal;
166168
use crate::train_schedule::Margins;
167169
use crate::train_schedule::PathItemLocation;
@@ -180,9 +182,12 @@ mod tests {
180182
/// Test deserialize an invalid train schedule
181183
#[test]
182184
fn deserialize_duplicate_path_id_train_schedule() {
183-
let location = PathItemLocation::OperationalPointId {
184-
operational_point: "op".into(),
185-
};
185+
let location = PathItemLocation::OperationalPointReference(OperationalPointReference {
186+
reference: OperationalPointId {
187+
operational_point: "op".into(),
188+
},
189+
track_reference: None,
190+
});
186191
let path_item = PathItem {
187192
id: "a".into(),
188193
location,
@@ -235,9 +240,12 @@ mod tests {
235240
/// Test deserialize an invalid train schedule
236241
#[test]
237242
fn deserialize_duplicate_schedule_points_train_schedule() {
238-
let location = PathItemLocation::OperationalPointId {
239-
operational_point: "op".into(),
240-
};
243+
let location = PathItemLocation::OperationalPointReference(OperationalPointReference {
244+
reference: OperationalPointId {
245+
operational_point: "op".into(),
246+
},
247+
track_reference: None,
248+
});
241249
let path_item = PathItem {
242250
id: "a".into(),
243251
location,
@@ -270,9 +278,12 @@ mod tests {
270278
/// Test deserialize an invalid train schedule
271279
#[test]
272280
fn deserialize_arrival_time_first_waypoint_schedule_train_schedule() {
273-
let location = PathItemLocation::OperationalPointId {
274-
operational_point: "op".into(),
275-
};
281+
let location = PathItemLocation::OperationalPointReference(OperationalPointReference {
282+
reference: OperationalPointId {
283+
operational_point: "op".into(),
284+
},
285+
track_reference: None,
286+
});
276287
let path_item = PathItem {
277288
id: "a".into(),
278289
location,

editoast/openapi.yaml

+59-32
Original file line numberDiff line numberDiff line change
@@ -7375,6 +7375,47 @@ components:
73757375
maxLength: 255
73767376
minLength: 1
73777377
additionalProperties: false
7378+
OperationalPointReference:
7379+
allOf:
7380+
- oneOf:
7381+
- type: object
7382+
required:
7383+
- operational_point
7384+
properties:
7385+
operational_point:
7386+
type: string
7387+
maxLength: 255
7388+
minLength: 1
7389+
- type: object
7390+
required:
7391+
- trigram
7392+
properties:
7393+
secondary_code:
7394+
type: string
7395+
description: An optional secondary code to identify a more specific location
7396+
nullable: true
7397+
trigram:
7398+
type: string
7399+
minLength: 1
7400+
- type: object
7401+
required:
7402+
- uic
7403+
properties:
7404+
secondary_code:
7405+
type: string
7406+
description: An optional secondary code to identify a more specific location
7407+
nullable: true
7408+
uic:
7409+
type: integer
7410+
format: int32
7411+
description: The [UIC](https://en.wikipedia.org/wiki/List_of_UIC_country_codes) code of an operational point
7412+
minimum: 0
7413+
- type: object
7414+
properties:
7415+
track_reference:
7416+
allOf:
7417+
- $ref: '#/components/schemas/TrackReference'
7418+
nullable: true
73787419
Ordering:
73797420
type: string
73807421
enum:
@@ -7536,38 +7577,7 @@ components:
75367577
PathItemLocation:
75377578
oneOf:
75387579
- $ref: '#/components/schemas/TrackOffset'
7539-
- type: object
7540-
required:
7541-
- operational_point
7542-
properties:
7543-
operational_point:
7544-
type: string
7545-
maxLength: 255
7546-
minLength: 1
7547-
- type: object
7548-
required:
7549-
- trigram
7550-
properties:
7551-
secondary_code:
7552-
type: string
7553-
description: An optional secondary code to identify a more specific location
7554-
nullable: true
7555-
trigram:
7556-
type: string
7557-
minLength: 1
7558-
- type: object
7559-
required:
7560-
- uic
7561-
properties:
7562-
secondary_code:
7563-
type: string
7564-
description: An optional secondary code to identify a more specific location
7565-
nullable: true
7566-
uic:
7567-
type: integer
7568-
format: int32
7569-
description: The [UIC](https://en.wikipedia.org/wiki/List_of_UIC_country_codes) code of an operational point
7570-
minimum: 0
7580+
- $ref: '#/components/schemas/OperationalPointReference'
75717581
description: The location of a path waypoint
75727582
PathProperties:
75737583
type: object
@@ -10790,6 +10800,23 @@ components:
1079010800
type: string
1079110801
maxLength: 255
1079210802
minLength: 1
10803+
TrackReference:
10804+
oneOf:
10805+
- type: object
10806+
required:
10807+
- track_id
10808+
properties:
10809+
track_id:
10810+
type: string
10811+
maxLength: 255
10812+
minLength: 1
10813+
- type: object
10814+
required:
10815+
- track_name
10816+
properties:
10817+
track_name:
10818+
type: string
10819+
minLength: 1
1079310820
TrackSection:
1079410821
type: object
1079510822
required:

0 commit comments

Comments
 (0)