Skip to content

Commit

Permalink
Merge pull request #388 from snyk/fix/doc-version
Browse files Browse the repository at this point in the history
fix: get document version from filename to fix backstage cmds
  • Loading branch information
jgresty authored Oct 17, 2024
2 parents 4fd246d + 0b1ce42 commit 43e9f15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 3 additions & 5 deletions document.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,9 @@ func (d *Document) LoadReference(relPath, refPath string, target interface{}) (_

// Version returns the version of the document.
func (d *Document) Version() (Version, error) {
vs, err := ExtensionString(d.Extensions, ExtSnykApiVersion)
if err != nil {
return Version{}, err
}
return ParseVersion(vs)
versionDir := filepath.Dir(d.path)
versionStr := filepath.Base(versionDir)
return ParseVersion(versionStr)
}

// Lifecycle returns the lifecycle of the document.
Expand Down
10 changes: 10 additions & 0 deletions document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ func TestNewDocumentFile(t *testing.T) {
c.Assert(doc.Components.Schemas["HelloWorld"], qt.Not(qt.IsNil))
c.Assert(doc.Validate(context.TODO()), qt.IsNil)
}

func TestDocumentVersion(t *testing.T) {
c := qt.New(t)
doc, err := vervet.NewDocumentFile(testdata.Path("resources/_examples/hello-world/2021-06-01/spec.yaml"))
c.Assert(err, qt.IsNil)

version, err := doc.Version()
c.Assert(err, qt.IsNil)
c.Assert(version, qt.Equals, vervet.MustParseVersion("2021-06-01"))
}

0 comments on commit 43e9f15

Please sign in to comment.