nv_redfish_schema/paths.rs
1// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Path constants and resolvers for the bundled CSDL schemas.
17//!
18//! Constants resolve to absolute paths inside this crate's source tree at the
19//! time the crate itself is compiled (via `env!("CARGO_MANIFEST_DIR")`). When
20//! consumed as a `[build-dependencies]`, they point at the unpacked schemas
21//! inside `~/.cargo/registry/src/.../nv-redfish-schema-<ver>/` for published
22//! builds, or at the in-tree submodule checkout for in-workspace builds.
23
24/// Directory holding the bundled DMTF Redfish CSDL schemas.
25///
26/// Mirrors the `csdl` subdirectory of the upstream
27/// [`DMTF/Redfish-Publications`](https://github.com/DMTF/Redfish-Publications)
28/// git submodule.
29pub const REDFISH_CSDL_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/redfish-csdl/csdl");
30
31/// Directory holding the bundled SNIA Swordfish CSDL schemas.
32///
33/// Mirrors the `csdl-schema` subdirectory of the upstream
34/// [`SNIA/Swordfish-Publications`](https://github.com/SNIA/Swordfish-Publications)
35/// git submodule.
36pub const SWORDFISH_CSDL_DIR: &str =
37 concat!(env!("CARGO_MANIFEST_DIR"), "/swordfish-csdl/csdl-schema");
38
39/// Directory holding the nv-redfish workspace's own OEM CSDL schemas.
40pub const OEM_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/oem");
41
42/// Resolve `name` (e.g. `"RedfishError_v1.xml"`) to an absolute path inside
43/// [`REDFISH_CSDL_DIR`].
44#[must_use]
45pub fn redfish_schema(name: &str) -> String {
46 format!("{REDFISH_CSDL_DIR}/{name}")
47}
48
49/// Resolve `name` to an absolute path inside [`SWORDFISH_CSDL_DIR`].
50#[must_use]
51pub fn swordfish_schema(name: &str) -> String {
52 format!("{SWORDFISH_CSDL_DIR}/{name}")
53}
54
55/// Resolve `name` inside the OEM directory `vendor` (e.g. `oem_schema("dell",
56/// "DellAttributes_v1.xml")`) to an absolute path inside [`OEM_DIR`].
57#[must_use]
58pub fn oem_schema(vendor: &str, name: &str) -> String {
59 format!("{OEM_DIR}/{vendor}/{name}")
60}
61
62/// Return absolute paths for every `*.xml` file directly inside
63/// [`REDFISH_CSDL_DIR`].
64#[must_use]
65pub fn glob_redfish_xml() -> Vec<String> {
66 glob_xml(REDFISH_CSDL_DIR)
67}
68
69/// Return absolute paths for every `*.xml` file directly inside
70/// [`SWORDFISH_CSDL_DIR`].
71#[must_use]
72pub fn glob_swordfish_xml() -> Vec<String> {
73 glob_xml(SWORDFISH_CSDL_DIR)
74}
75
76/// Return absolute paths for every `*.xml` file directly inside the OEM
77/// directory `vendor`.
78#[must_use]
79pub fn glob_oem_xml(vendor: &str) -> Vec<String> {
80 glob_xml(&format!("{OEM_DIR}/{vendor}"))
81}
82
83fn glob_xml(dir: &str) -> Vec<String> {
84 glob::glob(&format!("{dir}/*.xml"))
85 .expect("invalid glob pattern for bundled schemas")
86 .filter_map(Result::ok)
87 .map(|p| p.display().to_string())
88 .collect()
89}