mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 12:37:49 +00:00
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:
@@ -113,6 +113,9 @@ func NewSchema(schema *base.Schema) *Schema {
|
|||||||
s := new(Schema)
|
s := new(Schema)
|
||||||
s.low = schema
|
s.low = schema
|
||||||
s.Title = schema.Title.Value
|
s.Title = schema.Title.Value
|
||||||
|
if !schema.SchemaTypeRef.IsEmpty() {
|
||||||
|
s.SchemaTypeRef = schema.SchemaTypeRef.Value
|
||||||
|
}
|
||||||
if !schema.MultipleOf.IsEmpty() {
|
if !schema.MultipleOf.IsEmpty() {
|
||||||
s.MultipleOf = &schema.MultipleOf.Value
|
s.MultipleOf = &schema.MultipleOf.Value
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1249,3 +1249,36 @@ func TestDocument_LoadDocTwice(t *testing.T) {
|
|||||||
_, errs = doc.BuildV3Model()
|
_, errs = doc.BuildV3Model()
|
||||||
require.Empty(t, errs)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user