Added in high level schema type ref #215

Missed capturing the high level schema. Added test to document to capture use case permanently.

Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
quobix
2023-12-18 10:35:00 -05:00
parent 9cf06d3986
commit 0b7f809ac6
2 changed files with 793 additions and 757 deletions

View File

@@ -113,6 +113,9 @@ func NewSchema(schema *base.Schema) *Schema {
s := new(Schema)
s.low = schema
s.Title = schema.Title.Value
if !schema.SchemaTypeRef.IsEmpty() {
s.SchemaTypeRef = schema.SchemaTypeRef.Value
}
if !schema.MultipleOf.IsEmpty() {
s.MultipleOf = &schema.MultipleOf.Value
}

View File

@@ -1249,3 +1249,36 @@ func TestDocument_LoadDocTwice(t *testing.T) {
_, errs = doc.BuildV3Model()
require.Empty(t, errs)
}
func TestSchemaTypeRef_Issue215(t *testing.T) {
docBytes := []byte(`
openapi: 3.1.0
components:
schemas:
Foo:
$schema: https://example.com/custom-json-schema-dialect
type: string`)
doc, err := NewDocument(docBytes)
if err != nil {
panic(err)
}
model, errs := doc.BuildV3Model()
if len(errs) > 0 {
panic(errs)
}
schema := model.Model.Components.Schemas.GetOrZero("Foo").Schema()
schemaLow := schema.GoLow()
// works as expected
if v := schemaLow.SchemaTypeRef.Value; v != "https://example.com/custom-json-schema-dialect" {
t.Errorf("low model: expected $schema to be 'https://example.com/custom-json-schema-dialect', but got '%v'", v)
}
// high model: expected $schema to be 'https://example.com/custom-json-schema-dialect', but got ''
if v := schema.SchemaTypeRef; v != "https://example.com/custom-json-schema-dialect" {
t.Errorf("high model: expected $schema to be 'https://example.com/custom-json-schema-dialect', but got '%v'", v)
}
}