Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editoast: add ToSchema to all infra schemas #7306

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions editoast/editoast_schemas/src/infra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,27 @@ pub use track_section_source_extension::TrackSectionSourceExtension;
pub use waypoint::Waypoint;

editoast_common::schemas! {
track_offset::schemas(),
direction::schemas(),
track_location::schemas(),
applicable_directions::schemas(),
applicable_directions_track_range::schemas(),
buffer_stop::schemas(),
detector::schemas(),
directional_track_range::schemas(),
direction::schemas(),
electrical_profiles::schemas(),
electrification::schemas(),
endpoint::schemas(),
loading_gauge_limit::schemas(),
neutral_section::schemas(),
operational_point::schemas(),
route::schemas(),
side::schemas(),
signal::schemas(),
sign::schemas(),
speed_section::schemas(),
switch::schemas(),
switch_type::schemas(),
track_endpoint::schemas(),
track_location::schemas(),
track_offset::schemas(),
track_section::schemas(),
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use derivative::Derivative;
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

#[derive(Debug, Derivative, Copy, Clone, Deserialize, Serialize, PartialEq, Eq)]
editoast_common::schemas! {
ApplicableDirections,
}

#[derive(Debug, Derivative, Copy, Clone, Deserialize, Serialize, PartialEq, Eq, ToSchema)]
#[derivative(Default)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ApplicableDirections {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
use derivative::Derivative;
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

use super::ApplicableDirections;
use crate::primitives::Identifier;

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq)]
editoast_common::schemas! {
ApplicableDirectionsTrackRange,
}

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, ToSchema)]
#[serde(deny_unknown_fields)]
#[derivative(Default)]
pub struct ApplicableDirectionsTrackRange {
#[derivative(Default(value = r#""InvalidRef".into()"#))]
#[schema(inline)]
pub track: Identifier,
pub begin: f64,
#[derivative(Default(value = "100."))]
Expand Down
15 changes: 12 additions & 3 deletions editoast/editoast_schemas/src/infra/buffer_stop.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
use derivative::Derivative;
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

use crate::primitives::Identifier;
use crate::primitives::OSRDIdentified;
use crate::primitives::OSRDTyped;
use crate::primitives::ObjectType;

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq)]
editoast_common::schemas! {
BufferStop,
}

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, ToSchema)]
#[serde(deny_unknown_fields)]
#[derivative(Default)]
pub struct BufferStop {
#[schema(inline)]
pub id: Identifier,
#[derivative(Default(value = r#""InvalidRef".into()"#))]
#[schema(inline)]
pub track: Identifier,
pub position: f64,
#[serde(default)]
#[schema(inline)]
pub extensions: BufferStopExtension,
}

Expand All @@ -31,13 +39,14 @@ impl OSRDIdentified for BufferStop {
}
}

#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct BufferStopExtension {
#[schema(inline)]
pub sncf: Option<BufferStopSncfExtension>,
}

#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct BufferStopSncfExtension {
pub kp: String,
Expand Down
15 changes: 12 additions & 3 deletions editoast/editoast_schemas/src/infra/detector.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
use derivative::Derivative;
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

use crate::primitives::Identifier;
use crate::primitives::OSRDIdentified;
use crate::primitives::OSRDTyped;
use crate::primitives::ObjectType;

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq)]
editoast_common::schemas! {
Detector,
}

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, ToSchema)]
#[serde(deny_unknown_fields)]
#[derivative(Default)]
pub struct Detector {
#[schema(inline)]
pub id: Identifier,
#[derivative(Default(value = r#""InvalidRef".into()"#))]
#[schema(inline)]
pub track: Identifier,
pub position: f64,
#[serde(default)]
#[schema(inline)]
pub extensions: DetectorExtension,
}

Expand All @@ -31,13 +39,14 @@ impl OSRDIdentified for Detector {
}
}

#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct DetectorExtension {
#[schema(inline)]
pub sncf: DetectorSncfExtension,
}

#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct DetectorSncfExtension {
pub kp: String,
Expand Down
9 changes: 8 additions & 1 deletion editoast/editoast_schemas/src/infra/electrification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ use crate::primitives::NonBlankString;
use derivative::Derivative;
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

use super::ApplicableDirectionsTrackRange;
use crate::primitives::Identifier;
use crate::primitives::OSRDIdentified;
use crate::primitives::OSRDTyped;
use crate::primitives::ObjectType;

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq)]
editoast_common::schemas! {
Electrification,
}

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, ToSchema)]
#[serde(deny_unknown_fields)]
#[derivative(Default)]
pub struct Electrification {
#[schema(inline)]
pub id: Identifier,
#[schema(inline)]
pub voltage: NonBlankString,
pub track_ranges: Vec<ApplicableDirectionsTrackRange>,
}
Expand Down
7 changes: 6 additions & 1 deletion editoast/editoast_schemas/src/infra/endpoint.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, Hash)]
editoast_common::schemas! {
Endpoint,
}

#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, Hash, ToSchema)]
#[serde(rename_all = "UPPERCASE")]
pub enum Endpoint {
Begin,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

use crate::rolling_stock::LoadingGaugeType;

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
editoast_common::schemas! {
LoadingGaugeLimit,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct LoadingGaugeLimit {
pub category: LoadingGaugeType,
Expand Down
14 changes: 11 additions & 3 deletions editoast/editoast_schemas/src/infra/neutral_section.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use derivative::Derivative;
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

use super::DirectionalTrackRange;
use super::Sign;
Expand All @@ -9,30 +10,37 @@ use crate::primitives::OSRDIdentified;
use crate::primitives::OSRDTyped;
use crate::primitives::ObjectType;

editoast_common::schemas! {
NeutralSection,
}

/// Neutral sections are portions of track where trains aren't allowed to pull power from electrifications. They have to rely on inertia to cross such sections.
///
/// In practice, neutral sections are delimited by signs. In OSRD, neutral sections are directional to allow accounting for different sign placement depending on the direction.
///
/// For more details see [the documentation](https://osrd.fr/en/docs/explanation/neutral_sections/).
#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, ToSchema)]
#[serde(deny_unknown_fields)]
#[derivative(Default)]
pub struct NeutralSection {
#[schema(inline)]
pub id: Identifier,
pub announcement_track_ranges: Vec<DirectionalTrackRange>,
pub track_ranges: Vec<DirectionalTrackRange>,
pub lower_pantograph: bool, // Whether the trains need to lower their pantograph to cross this section
#[serde(default)]
#[schema(inline)]
pub extensions: NeutralSectionExtensions,
}

#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct NeutralSectionExtensions {
#[schema(inline)]
pub neutral_sncf: Option<NeutralSectionNeutralSncfExtension>,
}

#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct NeutralSectionNeutralSncfExtension {
announcement: Vec<Sign>,
Expand Down
6 changes: 6 additions & 0 deletions editoast/editoast_schemas/src/infra/operational_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ use crate::primitives::OSRDIdentified;
use crate::primitives::OSRDTyped;
use crate::primitives::ObjectType;

editoast_common::schemas! {
OperationalPoint,
OperationalPointPart,
}

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, ToSchema)]
#[serde(deny_unknown_fields)]
#[derivative(Default)]
Expand All @@ -18,6 +23,7 @@ pub struct OperationalPoint {
pub id: Identifier,
pub parts: Vec<OperationalPointPart>,
#[serde(default)]
#[schema(inline)]
pub extensions: OperationalPointExtensions,
}

Expand Down
10 changes: 9 additions & 1 deletion editoast/editoast_schemas/src/infra/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::primitives::Identifier;
use derivative::Derivative;
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

use super::Direction;
use super::DirectionalTrackRange;
Expand All @@ -12,16 +13,23 @@ use crate::primitives::OSRDIdentified;
use crate::primitives::OSRDTyped;
use crate::primitives::ObjectType;

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, Eq)]
editoast_common::schemas! {
Route,
}

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, Eq, ToSchema)]
#[serde(deny_unknown_fields)]
#[derivative(Default)]
pub struct Route {
#[schema(inline)]
pub id: Identifier,
pub entry_point: Waypoint,
#[derivative(Default(value = "Direction::StartToStop"))]
pub entry_point_direction: Direction,
pub exit_point: Waypoint,
#[schema(inline)]
pub release_detectors: Vec<Identifier>,
#[schema(inline)]
pub switches_directions: HashMap<Identifier, Identifier>,
}

Expand Down
7 changes: 6 additions & 1 deletion editoast/editoast_schemas/src/infra/side.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use derivative::Derivative;
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, Eq)]
editoast_common::schemas! {
Side,
}

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, Eq, ToSchema)]
#[derivative(Default)]
#[serde(rename_all = "UPPERCASE")]
pub enum Side {
Expand Down
9 changes: 8 additions & 1 deletion editoast/editoast_schemas/src/infra/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@ use crate::primitives::NonBlankString;
use derivative::Derivative;
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

use super::Direction;
use super::Side;

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq)]
editoast_common::schemas! {
Sign,
}

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, ToSchema)]
#[derivative(Default)]
#[serde(deny_unknown_fields)]
pub struct Sign {
#[derivative(Default(value = r#""InvalidRef".into()"#))]
#[schema(inline)]
pub track: Identifier,
pub position: f64,
pub side: Side,
#[derivative(Default(value = r#"Direction::StartToStop"#))]
pub direction: Direction,
#[serde(rename = "type")]
#[schema(inline)]
pub sign_type: NonBlankString,
pub value: String,
pub kp: String,
Expand Down
Loading
Loading