Debian Codegraph @

src/specification/ids.rs

raw symbols SCIP
1 //! Extracting schema ID.
2 use serde_json::Value;
3
4 pub(crate) fn dollar_id(contents: &Value) -> Option<&str> {
5 contents
6 .as_object()
7 .and_then(|obj| obj.get("$id"))
8 .and_then(|id| id.as_str())
9 }
10
11 pub(crate) fn legacy_dollar_id(contents: &Value) -> Option<&str> {
12 let object = contents.as_object()?;
13 if object.contains_key("$ref") {
14 return None;
15 }
16 if let Some(id) = contents.get("$id").and_then(|id| id.as_str()) {
17 if !id.starts_with('#') {
18 return Some(id);
19 }
20 }
21 None
22 }
23
24 pub(crate) fn legacy_id(contents: &Value) -> Option<&str> {
25 let object = contents.as_object()?;
26 if object.contains_key("$ref") {
27 return None;
28 }
29 if let Some(id) = object.get("id").and_then(|id| id.as_str()) {
30 if !id.starts_with('#') {
31 return Some(id);
32 }
33 }
34 None
35 }