Skip to content

Commit 76bf3ca

Browse files
committed
Fixed typo
1 parent 5b4ca2a commit 76bf3ca

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

utoipa/src/openapi/defs.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ use super::{
1414
AllOf, Array, Components, Object, OneOf, OpenApi, RefOr, Schema,
1515
};
1616

17+
18+
const DEFS_PREFIX: &str = "#/$defs/";
19+
const COMPONENTS_PREFIX: &str = "#/components/schemas/";
20+
1721
builder! {
1822
DefsBuilder;
1923

@@ -137,23 +141,23 @@ impl Schema {
137141
}
138142
}
139143

140-
/// Used to replace /#defs/ with openapi /components/schemas/<schema-name>
144+
/// Used to replace #/$defs/ with openapi /components/schemas/<schema-name>
141145
/// for schema (recursively)
142146
///
143147
/// See also: [`RefOr::refs_to_openapi_format`]
144148
///
145149
/// e.g.
146150
/// ```json
147151
/// {
148-
/// "$ref": "/#defs/a/b
152+
/// "$ref": "#/$defs/a/b
149153
/// }
150154
/// ```
151155
///
152156
/// becomes
153157
///
154158
/// ```json
155159
/// {
156-
/// "$ref": /#components/schemas/<schema-name>/a/b"
160+
/// "$ref": #/components/schemas/<schema-name>/a/b"
157161
/// }
158162
/// ```
159163
pub fn refs_to_openapi_format<SN: AsRef<str>>(&mut self, schema_name: Option<SN>) -> &mut Self {
@@ -364,23 +368,23 @@ impl OpenApi {
364368
self
365369
}
366370

367-
/// Used to replace /#defs/ with openapi /components/schemas/<schema-name>
371+
/// Used to replace #/$defs/ with openapi /components/schemas/<schema-name>
368372
/// for all components schemas (recursively)
369373
///
370374
/// See also: [`RefOr::refs_to_openapi_format`]
371375
///
372376
/// e.g.
373377
/// ```json
374378
/// {
375-
/// "$ref": "/#defs/a/b
379+
/// "$ref": "#/$defs/a/b
376380
/// }
377381
/// ```
378382
///
379383
/// becomes
380384
///
381385
/// ```json
382386
/// {
383-
/// "$ref": /#components/schemas/<schema-name>/a/b"
387+
/// "$ref": #/components/schemas/<schema-name>/a/b"
384388
/// }
385389
/// ```
386390
pub fn refs_to_openapi_format<SN: AsRef<str>>(&mut self, schema_name: Option<SN>) -> &mut Self {
@@ -399,24 +403,21 @@ impl OpenApi {
399403
}
400404
}
401405

402-
const DEFS_PREFIX: &str = "/#defs/";
403-
const COMPONENTS_PREFIX: &str = "/#components/schemas/";
404-
405406
impl RefOr<Schema> {
406-
/// Used to replace /#defs/ with openapi /components/schemas/<schema-name>
407+
/// Used to replace #/$defs/ with openapi /components/schemas/<schema-name>
407408
///
408409
/// e.g.
409410
/// ```json
410411
/// {
411-
/// "$ref": "/#defs/a/b
412+
/// "$ref": "#/$defs/a/b
412413
/// }
413414
/// ```
414415
///
415416
/// becomes
416417
///
417418
/// ```json
418419
/// {
419-
/// "$ref": /#components/schemas/<schema-name>/a/b"
420+
/// "$ref": #/components/schemas/<schema-name>/a/b"
420421
/// }
421422
/// ```
422423
pub fn refs_to_openapi_format<SN: AsRef<str>>(
@@ -720,14 +721,14 @@ pub mod test {
720721
fn refs_to_openapi_format_simple_ref() {
721722
let mut simple_ref: RefOr<Schema> = RefOr::Ref(
722723
RefBuilder::new()
723-
.ref_location("/#defs/MyStruct".into())
724+
.ref_location("#/$defs/MyStruct".into())
724725
.into(),
725726
);
726727

727728
simple_ref.refs_to_openapi_format(Option::<&str>::None);
728729

729730
match simple_ref {
730-
RefOr::Ref(x) => assert_eq!(x.ref_location, "/#components/schemas/MyStruct"),
731+
RefOr::Ref(x) => assert_eq!(x.ref_location, "#/components/schemas/MyStruct"),
731732
RefOr::T(_) => unreachable!(),
732733
}
733734
}
@@ -736,7 +737,7 @@ pub mod test {
736737
fn refs_to_openapi_format_on_schema() {
737738
let simple_ref: RefOr<Schema> = RefOr::Ref(
738739
RefBuilder::new()
739-
.ref_location("/#defs/MyStruct".into())
740+
.ref_location("#/$defs/MyStruct".into())
740741
.into(),
741742
);
742743

@@ -756,7 +757,7 @@ pub mod test {
756757

757758
assert_eq!(items.len(), 1);
758759
match items.first().unwrap() {
759-
RefOr::Ref(ref_) => assert_eq!(ref_.ref_location, "/#components/schemas/MyStruct"),
760+
RefOr::Ref(ref_) => assert_eq!(ref_.ref_location, "#/components/schemas/MyStruct"),
760761
RefOr::T(_) => unreachable!(),
761762
}
762763
}
@@ -765,7 +766,7 @@ pub mod test {
765766
fn refs_to_openapi_format_on_openapi() {
766767
let simple_ref: RefOr<Schema> = RefOr::Ref(
767768
RefBuilder::new()
768-
.ref_location("/#defs/MyStruct".into())
769+
.ref_location("#/$defs/MyStruct".into())
769770
.into(),
770771
);
771772

0 commit comments

Comments
 (0)