Added a couple of null checks to v3 model

Asana spec was blowing up, now it's working as expected.
This commit is contained in:
Dave Shanley
2022-08-31 10:50:20 -04:00
parent 2d84cfd185
commit 68e90d16cc
3 changed files with 27 additions and 5 deletions

View File

@@ -350,6 +350,18 @@ func TestStripeAsDoc(t *testing.T) {
fmt.Println(d) fmt.Println(d)
} }
func TestAsanaAsDoc(t *testing.T) {
data, _ := ioutil.ReadFile("../../../test_specs/asana.yaml")
info, _ := datamodel.ExtractSpecInfo(data)
var err []error
doc, err = lowv3.CreateDocument(info)
if err != nil {
panic("broken something")
}
d := NewDocument(doc)
fmt.Println(d)
}
func TestCircularReferencesDoc(t *testing.T) { func TestCircularReferencesDoc(t *testing.T) {
data, _ := ioutil.ReadFile("../../../test_specs/circular-tests.yaml") data, _ := ioutil.ReadFile("../../../test_specs/circular-tests.yaml")
info, _ := datamodel.ExtractSpecInfo(data) info, _ := datamodel.ExtractSpecInfo(data)

View File

@@ -18,8 +18,12 @@ type ExternalDoc struct {
func NewExternalDoc(extDoc *low.ExternalDoc) *ExternalDoc { func NewExternalDoc(extDoc *low.ExternalDoc) *ExternalDoc {
d := new(ExternalDoc) d := new(ExternalDoc)
d.low = extDoc d.low = extDoc
if !extDoc.Description.IsEmpty() {
d.Description = extDoc.Description.Value d.Description = extDoc.Description.Value
}
if !extDoc.URL.IsEmpty() {
d.URL = extDoc.URL.Value d.URL = extDoc.URL.Value
}
d.Extensions = high.ExtractExtensions(extDoc.Extensions) d.Extensions = high.ExtractExtensions(extDoc.Extensions)
return d return d
} }

View File

@@ -19,9 +19,15 @@ type Tag struct {
func NewTag(tag *low.Tag) *Tag { func NewTag(tag *low.Tag) *Tag {
t := new(Tag) t := new(Tag)
t.low = tag t.low = tag
if !tag.Name.IsEmpty() {
t.Name = tag.Name.Value t.Name = tag.Name.Value
}
if !tag.Description.IsEmpty() {
t.Description = tag.Description.Value t.Description = tag.Description.Value
}
if !tag.ExternalDocs.IsEmpty() {
t.ExternalDocs = NewExternalDoc(tag.ExternalDocs.Value) t.ExternalDocs = NewExternalDoc(tag.ExternalDocs.Value)
}
t.Extensions = high.ExtractExtensions(tag.Extensions) t.Extensions = high.ExtractExtensions(tag.Extensions)
return t return t
} }