diff --git a/openapi2conv/openapi2_conv.go b/openapi2conv/openapi2_conv.go index 53b4b40cc..8c082053f 100644 --- a/openapi2conv/openapi2_conv.go +++ b/openapi2conv/openapi2_conv.go @@ -485,6 +485,16 @@ func ToV3SchemaRef(schema *openapi3.SchemaRef) *openapi3.SchemaRef { for i, v := range schema.Value.AllOf { schema.Value.AllOf[i] = ToV3SchemaRef(v) } + if val, ok := schema.Value.Extensions["x-nullable"]; ok { + var nullable bool + + if err := json.Unmarshal(val.(json.RawMessage), &nullable); err == nil { + schema.Value.Nullable = nullable + } + + delete(schema.Value.Extensions, "x-nullable") + } + return schema } @@ -824,6 +834,11 @@ func FromV3SchemaRef(schema *openapi3.SchemaRef, components *openapi3.Components for i, v := range schema.Value.AllOf { schema.Value.AllOf[i], _ = FromV3SchemaRef(v, components) } + if schema.Value.Nullable { + schema.Value.Nullable = false + schema.Value.Extensions["x-nullable"] = true + } + return schema, nil } diff --git a/openapi2conv/openapi2_conv_test.go b/openapi2conv/openapi2_conv_test.go index 9edce54de..317772152 100644 --- a/openapi2conv/openapi2_conv_test.go +++ b/openapi2conv/openapi2_conv_test.go @@ -89,7 +89,8 @@ const exampleV2 = ` "additionalProperties": true, "properties": { "foo": { - "type": "string" + "type": "string", + "x-nullable": true }, "quux": { "$ref": "#/definitions/ItemExtension" @@ -463,7 +464,8 @@ const exampleV3 = ` "additionalProperties": true, "properties": { "foo": { - "type": "string" + "type": "string", + "nullable": true }, "quux": { "$ref": "#/components/schemas/ItemExtension"