Add schema_id(), handles different types with the same name (#247)

This commit is contained in:
Graham Esau 2023-09-17 20:36:52 +01:00 committed by GitHub
parent 53bb51cb25
commit 342b2dff33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 415 additions and 34 deletions

View file

@ -0,0 +1,41 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Config2",
"type": "object",
"required": [
"a_cfg",
"b_cfg"
],
"properties": {
"a_cfg": {
"$ref": "#/definitions/Config"
},
"b_cfg": {
"$ref": "#/definitions/Config2"
}
},
"definitions": {
"Config": {
"type": "object",
"required": [
"test"
],
"properties": {
"test": {
"type": "string"
}
}
},
"Config2": {
"type": "object",
"required": [
"test2"
],
"properties": {
"test2": {
"type": "string"
}
}
}
}
}

View file

@ -0,0 +1,35 @@
mod util;
use schemars::JsonSchema;
use util::*;
mod a {
use super::*;
#[allow(dead_code)]
#[derive(JsonSchema)]
pub struct Config {
test: String,
}
}
mod b {
use super::*;
#[allow(dead_code)]
#[derive(JsonSchema)]
pub struct Config {
test2: String,
}
}
#[allow(dead_code)]
#[derive(JsonSchema)]
pub struct Config2 {
a_cfg: a::Config,
b_cfg: b::Config,
}
#[test]
fn same_name() -> TestResult {
test_default_generated_schema::<Config2>("same_name")
}