Skip to content

chore(lint): updated linters, relinted code #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ linters:
- nestif
- nlreturn
- nonamedreturns
- noinlineerr
- paralleltest
- recvcheck
- testpackage
- thelper
- tparallel
Expand All @@ -31,6 +33,7 @@ linters:
- whitespace
- wrapcheck
- wsl
- wsl_v5
settings:
dupl:
threshold: 200
Expand Down
67 changes: 32 additions & 35 deletions reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,23 @@ const (

var ErrChildURL = errors.New("child url is nil")

// Ref represents a json reference object
type Ref struct {
referenceURL *url.URL
referencePointer jsonpointer.Pointer

HasFullURL bool
HasURLPathOnly bool
HasFragmentOnly bool
HasFileScheme bool
HasFullFilePath bool
}

// New creates a new reference for the given string
func New(jsonReferenceString string) (Ref, error) {

var r Ref
err := r.parse(jsonReferenceString)
return r, err

}

// MustCreateRef parses the ref string and panics when it's invalid.
Expand All @@ -56,19 +66,8 @@ func MustCreateRef(ref string) Ref {
if err != nil {
panic(err)
}
return r
}

// Ref represents a json reference object
type Ref struct {
referenceURL *url.URL
referencePointer jsonpointer.Pointer

HasFullURL bool
HasURLPathOnly bool
HasFragmentOnly bool
HasFileScheme bool
HasFullFilePath bool
return r
}

// GetURL gets the URL for this reference
Expand All @@ -83,7 +82,6 @@ func (r *Ref) GetPointer() *jsonpointer.Pointer {

// String returns the best version of the url for this reference
func (r *Ref) String() string {

if r.referenceURL != nil {
return r.referenceURL.String()
}
Expand All @@ -108,9 +106,27 @@ func (r *Ref) IsCanonical() bool {
return (r.HasFileScheme && r.HasFullFilePath) || (!r.HasFileScheme && r.HasFullURL)
}

// Inherits creates a new reference from a parent and a child
// If the child cannot inherit from the parent, an error is returned
func (r *Ref) Inherits(child Ref) (*Ref, error) {
childURL := child.GetURL()
parentURL := r.GetURL()
if childURL == nil {
return nil, ErrChildURL
}
if parentURL == nil {
return &child, nil
}

ref, err := New(parentURL.ResolveReference(childURL).String())
if err != nil {
return nil, err
}
return &ref, nil
}

// "Constructor", parses the given string JSON reference
func (r *Ref) parse(jsonReferenceString string) error {

parsed, err := url.Parse(jsonReferenceString)
if err != nil {
return err
Expand Down Expand Up @@ -139,22 +155,3 @@ func (r *Ref) parse(jsonReferenceString string) error {

return nil
}

// Inherits creates a new reference from a parent and a child
// If the child cannot inherit from the parent, an error is returned
func (r *Ref) Inherits(child Ref) (*Ref, error) {
childURL := child.GetURL()
parentURL := r.GetURL()
if childURL == nil {
return nil, ErrChildURL
}
if parentURL == nil {
return &child, nil
}

ref, err := New(parentURL.ResolveReference(childURL).String())
if err != nil {
return nil, err
}
return &ref, nil
}
Loading