diff --git a/datamodel/high/base/schema_proxy.go b/datamodel/high/base/schema_proxy.go index 701e5f6..54cd1ff 100644 --- a/datamodel/high/base/schema_proxy.go +++ b/datamodel/high/base/schema_proxy.go @@ -76,7 +76,7 @@ func CreateSchemaProxyRef(ref string) *SchemaProxy { // If there is a problem building the Schema, then this method will return nil. Use GetBuildError to gain access // to that building error. func (sp *SchemaProxy) Schema() *Schema { - if sp == nil { + if sp == nil || sp.lock == nil { return nil } sp.lock.Lock() diff --git a/datamodel/high/base/schema_proxy_test.go b/datamodel/high/base/schema_proxy_test.go index 46dcac6..51ebac1 100644 --- a/datamodel/high/base/schema_proxy_test.go +++ b/datamodel/high/base/schema_proxy_test.go @@ -60,6 +60,11 @@ func TestSchemaProxy_MarshalYAML(t *testing.T) { assert.Equal(t, "$ref: '#/components/schemas/nice'", strings.TrimSpace(string(rend))) } +func TestCreateSchemaProxy_Fail(t *testing.T) { + proxy := &SchemaProxy{} + assert.Nil(t, proxy.Schema()) +} + func TestCreateSchemaProxy(t *testing.T) { sp := CreateSchemaProxy(&Schema{Description: "iAmASchema"}) assert.Equal(t, "iAmASchema", sp.rendered.Description) diff --git a/document_test.go b/document_test.go index b8c3e4f..0d90764 100644 --- a/document_test.go +++ b/document_test.go @@ -59,6 +59,13 @@ definitions: assert.Nil(t, v2Doc) } +func TestLoadDocument_WrongDoc(t *testing.T) { + yml := `IAmNotAnOpenAPI: 3.1.0` + doc, err := NewDocument([]byte(yml)) + assert.Error(t, err) + assert.Nil(t, doc) +} + func TestLoadDocument_Simple_V3_Error(t *testing.T) { yml := `openapi: 3.0.1` doc, err := NewDocument([]byte(yml))