Add support to enforce inlining of all subschemas instead of using references. (#44)

This is needed to support use cases like openAPIV3Schema in Kubernetes CustomResourceDefinitions.


Co-authored-by: alex.berger@nexiot.ch <alex.berger@nexiot.ch>
This commit is contained in:
Alexander Berger 2020-09-25 19:50:54 +02:00 committed by GitHub
parent 40d9bfd517
commit 364d0e0192
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 1 deletions

View file

@ -0,0 +1,23 @@
{
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"properties": {
"spec": {
"properties": {
"replicas": {
"format": "uint32",
"minimum": 0,
"type": "integer"
}
},
"required": [
"replicas"
],
"type": "object"
}
},
"required": [
"spec"
],
"title": "MyJob",
"type": "object"
}

View file

@ -0,0 +1,21 @@
mod util;
use schemars::gen::SchemaSettings;
use schemars::JsonSchema;
use util::*;
#[derive(Debug, JsonSchema)]
pub struct MyJob {
pub spec: MyJobSpec,
}
#[derive(Debug, JsonSchema)]
pub struct MyJobSpec {
pub replicas: u32,
}
#[test]
fn struct_normal() -> TestResult {
let mut settings = SchemaSettings::openapi3();
settings.inline_subschemas = true;
test_generated_schema::<MyJob>("inline-subschemas", settings)
}