diff --git a/schemars/src/json_schema_impls.rs b/schemars/src/json_schema_impls.rs index dae6098..6d9e8f1 100644 --- a/schemars/src/json_schema_impls.rs +++ b/schemars/src/json_schema_impls.rs @@ -272,9 +272,11 @@ impl JsonSchema for Option { } fn json_schema(gen: &mut SchemaGenerator) -> Result { - // FIXME this may produce a subschema that is not referenced in the final schema, - // e.g. SingleOrVec_For_InstanceType in schema-openapi3.json - let mut schema = gen.subschema_for::()?; + let mut schema = if gen.settings().option_nullable { + T::json_schema(gen)? + } else { + gen.subschema_for::()? + }; if gen.settings().option_add_null_type { schema = match schema { Schema::Bool(true) => Schema::Bool(true), diff --git a/schemars/tests/expected/schema-openapi3.json b/schemars/tests/expected/schema-openapi3.json index fa32d86..9176340 100644 --- a/schemars/tests/expected/schema-openapi3.json +++ b/schemars/tests/expected/schema-openapi3.json @@ -24,6 +24,17 @@ "integer" ] }, + "Ref": { + "type": "object", + "properties": { + "$ref": { + "type": "string" + } + }, + "required": [ + "$ref" + ] + }, "Schema": { "anyOf": [ { @@ -144,43 +155,6 @@ } }, "additionalProperties": true - }, - "Ref": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ] - }, - "SingleOrVec_For_InstanceType": { - "anyOf": [ - { - "$ref": "#/components/schemas/InstanceType" - }, - { - "type": "array", - "items": { - "$ref": "#/components/schemas/InstanceType" - } - } - ] - }, - "SingleOrVec_For_Schema": { - "anyOf": [ - { - "$ref": "#/components/schemas/Schema" - }, - { - "type": "array", - "items": { - "$ref": "#/components/schemas/Schema" - } - } - ] } } } \ No newline at end of file