Skip to content
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
29 changes: 10 additions & 19 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,17 @@ version: "2"
linters:
default: all
disable:
- cyclop
- depguard
- errchkjson
- errorlint
- exhaustruct
- forcetypeassert
- funlen
- gochecknoglobals
- gochecknoinits
- gocognit
- godot
- godox
- gosmopolitan
- inamedparam
#- intrange # disabled while < go1.22
- ireturn
- lll
- musttag
- nestif
- exhaustruct
- nlreturn
- nonamedreturns
- noinlineerr
- paralleltest
- recvcheck
- testpackage
- thelper
- tparallel
- unparam
- varnamelen
- whitespace
- wrapcheck
Expand All @@ -41,8 +24,15 @@ linters:
goconst:
min-len: 2
min-occurrences: 3
cyclop:
max-complexity: 20
gocyclo:
min-complexity: 45
min-complexity: 20
exhaustive:
default-signifies-exhaustive: true
default-case-required: true
lll:
line-length: 180
exclusions:
generated: lax
presets:
Expand All @@ -58,6 +48,7 @@ formatters:
enable:
- gofmt
- goimports
- gofumpt
exclusions:
generated: lax
paths:
Expand Down
8 changes: 5 additions & 3 deletions internal/normalize_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ const (
defaultHTTPSPort = ":443"
)

// Regular expressions used by the normalizations
var rxPort = regexp.MustCompile(`(:\d+)/?$`)
var rxDupSlashes = regexp.MustCompile(`/{2,}`)
// Regular expressions used by the normalizations.
var (
rxPort = regexp.MustCompile(`(:\d+)/?$`)
rxDupSlashes = regexp.MustCompile(`/{2,}`)
)

// NormalizeURL will normalize the specified URL
// This was added to replace a previous call to the no longer maintained purell library:
Expand Down
20 changes: 10 additions & 10 deletions reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (

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

// Ref represents a json reference object
// Ref represents a json reference object.
type Ref struct {
referenceURL *url.URL
referencePointer jsonpointer.Pointer
Expand All @@ -30,15 +30,15 @@ type Ref struct {
HasFullFilePath bool
}

// New creates a new reference for the given string
// 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.
// Use the New method for a version that returns an error
// Use the New method for a version that returns an error.
func MustCreateRef(ref string) Ref {
r, err := New(ref)
if err != nil {
Expand All @@ -48,17 +48,17 @@ func MustCreateRef(ref string) Ref {
return r
}

// GetURL gets the URL for this reference
// GetURL gets the URL for this reference.
func (r *Ref) GetURL() *url.URL {
return r.referenceURL
}

// GetPointer gets the json pointer for this reference
// GetPointer gets the json pointer for this reference.
func (r *Ref) GetPointer() *jsonpointer.Pointer {
return &r.referencePointer
}

// String returns the best version of the url for this reference
// 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 @@ -71,21 +71,21 @@ func (r *Ref) String() string {
return r.referencePointer.String()
}

// IsRoot returns true if this reference is a root document
// IsRoot returns true if this reference is a root document.
func (r *Ref) IsRoot() bool {
return r.referenceURL != nil &&
!r.IsCanonical() &&
!r.HasURLPathOnly &&
r.referenceURL.Fragment == ""
}

// IsCanonical returns true when this pointer starts with http(s):// or file://
// IsCanonical returns true when this pointer starts with http(s):// or file://.
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
// 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()
Expand All @@ -103,7 +103,7 @@ func (r *Ref) Inherits(child Ref) (*Ref, error) {
return &ref, nil
}

// "Constructor", parses the given string JSON reference
// "Constructor", parses the given string JSON reference.
func (r *Ref) parse(jsonReferenceString string) error {
parsed, err := url.Parse(jsonReferenceString)
if err != nil {
Expand Down
Loading