Change override_schema_name to schema_name
This commit is contained in:
parent
42013cff01
commit
2e580cb914
2 changed files with 5 additions and 9 deletions
|
@ -47,7 +47,7 @@ impl SchemaGenerator {
|
||||||
let schema = T::make_schema(self);
|
let schema = T::make_schema(self);
|
||||||
if let Schema::Object(mut o) = schema {
|
if let Schema::Object(mut o) = schema {
|
||||||
o.schema = Some("http://json-schema.org/draft-07/schema#".to_owned());
|
o.schema = Some("http://json-schema.org/draft-07/schema#".to_owned());
|
||||||
o.title = Some(Self::schema_name::<T>());
|
o.title = Some(T::schema_name());
|
||||||
for (_, (name, schema)) in self.definitions.iter() {
|
for (_, (name, schema)) in self.definitions.iter() {
|
||||||
o.definitions.insert(name.clone(), schema.clone());
|
o.definitions.insert(name.clone(), schema.clone());
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ impl SchemaGenerator {
|
||||||
let schema = T::make_schema(&mut self);
|
let schema = T::make_schema(&mut self);
|
||||||
if let Schema::Object(mut o) = schema {
|
if let Schema::Object(mut o) = schema {
|
||||||
o.schema = Some("http://json-schema.org/draft-07/schema#".to_owned());
|
o.schema = Some("http://json-schema.org/draft-07/schema#".to_owned());
|
||||||
o.title = Some(Self::schema_name::<T>());
|
o.title = Some(T::schema_name());
|
||||||
for (_, (name, schema)) in self.definitions {
|
for (_, (name, schema)) in self.definitions {
|
||||||
o.definitions.insert(name, schema);
|
o.definitions.insert(name, schema);
|
||||||
}
|
}
|
||||||
|
@ -69,12 +69,8 @@ impl SchemaGenerator {
|
||||||
schema
|
schema
|
||||||
}
|
}
|
||||||
|
|
||||||
fn schema_name<T: MakeSchema>() -> String {
|
|
||||||
T::override_schema_name().unwrap_or_else(|| type_name::<T>().to_owned())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn make_unique_name<T: MakeSchema>(&mut self) -> String {
|
fn make_unique_name<T: MakeSchema>(&mut self) -> String {
|
||||||
Self::schema_name::<T>()
|
T::schema_name()
|
||||||
// TODO remove namespace, remove special chars
|
// TODO remove namespace, remove special chars
|
||||||
// TODO enforce uniqueness
|
// TODO enforce uniqueness
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ use serde_json::json;
|
||||||
use std::collections::BTreeMap as Map;
|
use std::collections::BTreeMap as Map;
|
||||||
|
|
||||||
pub trait MakeSchema {
|
pub trait MakeSchema {
|
||||||
fn override_schema_name() -> Option<String> {
|
fn schema_name() -> String {
|
||||||
None
|
core::any::type_name::<Self>().to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generates_ref_schema() -> bool {
|
fn generates_ref_schema() -> bool {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue