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
6 changes: 4 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ linters:
min-len: 2
min-occurrences: 3
cyclop:
max-complexity: 20
max-complexity: 25
gocyclo:
min-complexity: 20
min-complexity: 25
gocognit:
min-complexity: 35
exhaustive:
default-signifies-exhaustive: true
default-case-required: true
Expand Down
68 changes: 34 additions & 34 deletions analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ func New(doc *spec.Swagger) *Spec {
return a
}

// SecurityRequirement is a representation of a security requirement for an operation
// SecurityRequirement is a representation of a security requirement for an operation.
type SecurityRequirement struct {
Name string
Scopes []string
}

// SecurityRequirementsFor gets the security requirements for the operation
// SecurityRequirementsFor gets the security requirements for the operation.
func (s *Spec) SecurityRequirementsFor(operation *spec.Operation) [][]SecurityRequirement {
if s.spec.Security == nil && operation.Security == nil {
return nil
Expand Down Expand Up @@ -204,7 +204,7 @@ func (s *Spec) SecurityRequirementsFor(operation *spec.Operation) [][]SecurityRe
return result
}

// SecurityDefinitionsForRequirements gets the matching security definitions for a set of requirements
// SecurityDefinitionsForRequirements gets the matching security definitions for a set of requirements.
func (s *Spec) SecurityDefinitionsForRequirements(requirements []SecurityRequirement) map[string]spec.SecurityScheme {
result := make(map[string]spec.SecurityScheme)

Expand All @@ -219,7 +219,7 @@ func (s *Spec) SecurityDefinitionsForRequirements(requirements []SecurityRequire
return result
}

// SecurityDefinitionsFor gets the matching security definitions for a set of requirements
// SecurityDefinitionsFor gets the matching security definitions for a set of requirements.
func (s *Spec) SecurityDefinitionsFor(operation *spec.Operation) map[string]spec.SecurityScheme {
requirements := s.SecurityRequirementsFor(operation)
if len(requirements) == 0 {
Expand Down Expand Up @@ -250,7 +250,7 @@ func (s *Spec) SecurityDefinitionsFor(operation *spec.Operation) map[string]spec
return result
}

// ConsumesFor gets the mediatypes for the operation
// ConsumesFor gets the mediatypes for the operation.
func (s *Spec) ConsumesFor(operation *spec.Operation) []string {
if len(operation.Consumes) == 0 {
cons := make(map[string]struct{}, len(s.spec.Consumes))
Expand All @@ -269,7 +269,7 @@ func (s *Spec) ConsumesFor(operation *spec.Operation) []string {
return s.structMapKeys(cons)
}

// ProducesFor gets the mediatypes for the operation
// ProducesFor gets the mediatypes for the operation.
func (s *Spec) ProducesFor(operation *spec.Operation) []string {
if len(operation.Produces) == 0 {
prod := make(map[string]struct{}, len(s.spec.Produces))
Expand Down Expand Up @@ -400,7 +400,7 @@ func (s *Spec) SafeParamsFor(method, path string, callmeOnError ErrorOnParamFunc
return res
}

// OperationForName gets the operation for the given id
// OperationForName gets the operation for the given id.
func (s *Spec) OperationForName(operationID string) (string, string, *spec.Operation, bool) {
for method, pathItem := range s.operations {
for path, op := range pathItem {
Expand All @@ -413,7 +413,7 @@ func (s *Spec) OperationForName(operationID string) (string, string, *spec.Opera
return "", "", nil, false
}

// OperationFor the given method and path
// OperationFor the given method and path.
func (s *Spec) OperationFor(method, path string) (*spec.Operation, bool) {
if mp, ok := s.operations[strings.ToUpper(method)]; ok {
op, fn := mp[path]
Expand All @@ -424,12 +424,12 @@ func (s *Spec) OperationFor(method, path string) (*spec.Operation, bool) {
return nil, false
}

// Operations gathers all the operations specified in the spec document
// Operations gathers all the operations specified in the spec document.
func (s *Spec) Operations() map[string]map[string]*spec.Operation {
return s.operations
}

// AllPaths returns all the paths in the swagger spec
// AllPaths returns all the paths in the swagger spec.
func (s *Spec) AllPaths() map[string]spec.PathItem {
if s.spec == nil || s.spec.Paths == nil {
return nil
Expand All @@ -438,7 +438,7 @@ func (s *Spec) AllPaths() map[string]spec.PathItem {
return s.spec.Paths.Paths
}

// OperationIDs gets all the operation ids based on method an dpath
// OperationIDs gets all the operation ids based on method an dpath.
func (s *Spec) OperationIDs() []string {
if len(s.operations) == 0 {
return nil
Expand All @@ -458,7 +458,7 @@ func (s *Spec) OperationIDs() []string {
return result
}

// OperationMethodPaths gets all the operation ids based on method an dpath
// OperationMethodPaths gets all the operation ids based on method an dpath.
func (s *Spec) OperationMethodPaths() []string {
if len(s.operations) == 0 {
return nil
Expand All @@ -474,22 +474,22 @@ func (s *Spec) OperationMethodPaths() []string {
return result
}

// RequiredConsumes gets all the distinct consumes that are specified in the specification document
// RequiredConsumes gets all the distinct consumes that are specified in the specification document.
func (s *Spec) RequiredConsumes() []string {
return s.structMapKeys(s.consumes)
}

// RequiredProduces gets all the distinct produces that are specified in the specification document
// RequiredProduces gets all the distinct produces that are specified in the specification document.
func (s *Spec) RequiredProduces() []string {
return s.structMapKeys(s.produces)
}

// RequiredSecuritySchemes gets all the distinct security schemes that are specified in the swagger spec
// RequiredSecuritySchemes gets all the distinct security schemes that are specified in the swagger spec.
func (s *Spec) RequiredSecuritySchemes() []string {
return s.structMapKeys(s.authSchemes)
}

// SchemaRef is a reference to a schema
// SchemaRef is a reference to a schema.
type SchemaRef struct {
Name string
Ref spec.Ref
Expand All @@ -498,7 +498,7 @@ type SchemaRef struct {
}

// SchemasWithAllOf returns schema references to all schemas that are defined
// with an allOf key
// with an allOf key.
func (s *Spec) SchemasWithAllOf() (result []SchemaRef) {
for _, v := range s.allOfs {
result = append(result, v)
Expand All @@ -507,7 +507,7 @@ func (s *Spec) SchemasWithAllOf() (result []SchemaRef) {
return
}

// AllDefinitions returns schema references for all the definitions that were discovered
// AllDefinitions returns schema references for all the definitions that were discovered.
func (s *Spec) AllDefinitions() (result []SchemaRef) {
for _, v := range s.allSchemas {
result = append(result, v)
Expand All @@ -516,7 +516,7 @@ func (s *Spec) AllDefinitions() (result []SchemaRef) {
return
}

// AllDefinitionReferences returns json refs for all the discovered schemas
// AllDefinitionReferences returns json refs for all the discovered schemas.
func (s *Spec) AllDefinitionReferences() (result []string) {
for _, v := range s.references.schemas {
result = append(result, v.String())
Expand All @@ -525,7 +525,7 @@ func (s *Spec) AllDefinitionReferences() (result []string) {
return
}

// AllParameterReferences returns json refs for all the discovered parameters
// AllParameterReferences returns json refs for all the discovered parameters.
func (s *Spec) AllParameterReferences() (result []string) {
for _, v := range s.references.parameters {
result = append(result, v.String())
Expand All @@ -534,7 +534,7 @@ func (s *Spec) AllParameterReferences() (result []string) {
return
}

// AllResponseReferences returns json refs for all the discovered responses
// AllResponseReferences returns json refs for all the discovered responses.
func (s *Spec) AllResponseReferences() (result []string) {
for _, v := range s.references.responses {
result = append(result, v.String())
Expand All @@ -543,7 +543,7 @@ func (s *Spec) AllResponseReferences() (result []string) {
return
}

// AllPathItemReferences returns the references for all the items
// AllPathItemReferences returns the references for all the items.
func (s *Spec) AllPathItemReferences() (result []string) {
for _, v := range s.references.pathItems {
result = append(result, v.String())
Expand All @@ -564,7 +564,7 @@ func (s *Spec) AllItemsReferences() (result []string) {
return
}

// AllReferences returns all the references found in the document, with possible duplicates
// AllReferences returns all the references found in the document, with possible duplicates.
func (s *Spec) AllReferences() (result []string) {
for _, v := range s.references.allRefs {
result = append(result, v.String())
Expand All @@ -573,7 +573,7 @@ func (s *Spec) AllReferences() (result []string) {
return
}

// AllRefs returns all the unique references found in the document
// AllRefs returns all the unique references found in the document.
func (s *Spec) AllRefs() (result []spec.Ref) {
set := make(map[string]struct{})
for _, v := range s.references.allRefs {
Expand All @@ -592,61 +592,61 @@ func (s *Spec) AllRefs() (result []spec.Ref) {
}

// ParameterPatterns returns all the patterns found in parameters
// the map is cloned to avoid accidental changes
// the map is cloned to avoid accidental changes.
func (s *Spec) ParameterPatterns() map[string]string {
return cloneStringMap(s.patterns.parameters)
}

// HeaderPatterns returns all the patterns found in response headers
// the map is cloned to avoid accidental changes
// the map is cloned to avoid accidental changes.
func (s *Spec) HeaderPatterns() map[string]string {
return cloneStringMap(s.patterns.headers)
}

// ItemsPatterns returns all the patterns found in simple array items
// the map is cloned to avoid accidental changes
// the map is cloned to avoid accidental changes.
func (s *Spec) ItemsPatterns() map[string]string {
return cloneStringMap(s.patterns.items)
}

// SchemaPatterns returns all the patterns found in schemas
// the map is cloned to avoid accidental changes
// the map is cloned to avoid accidental changes.
func (s *Spec) SchemaPatterns() map[string]string {
return cloneStringMap(s.patterns.schemas)
}

// AllPatterns returns all the patterns found in the spec
// the map is cloned to avoid accidental changes
// the map is cloned to avoid accidental changes.
func (s *Spec) AllPatterns() map[string]string {
return cloneStringMap(s.patterns.allPatterns)
}

// ParameterEnums returns all the enums found in parameters
// the map is cloned to avoid accidental changes
// the map is cloned to avoid accidental changes.
func (s *Spec) ParameterEnums() map[string][]any {
return cloneEnumMap(s.enums.parameters)
}

// HeaderEnums returns all the enums found in response headers
// the map is cloned to avoid accidental changes
// the map is cloned to avoid accidental changes.
func (s *Spec) HeaderEnums() map[string][]any {
return cloneEnumMap(s.enums.headers)
}

// ItemsEnums returns all the enums found in simple array items
// the map is cloned to avoid accidental changes
// the map is cloned to avoid accidental changes.
func (s *Spec) ItemsEnums() map[string][]any {
return cloneEnumMap(s.enums.items)
}

// SchemaEnums returns all the enums found in schemas
// the map is cloned to avoid accidental changes
// the map is cloned to avoid accidental changes.
func (s *Spec) SchemaEnums() map[string][]any {
return cloneEnumMap(s.enums.schemas)
}

// AllEnums returns all the enums found in the spec
// the map is cloned to avoid accidental changes
// the map is cloned to avoid accidental changes.
func (s *Spec) AllEnums() map[string][]any {
return cloneEnumMap(s.enums.allEnums)
}
Expand Down
2 changes: 1 addition & 1 deletion debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ import (
"github.com/go-openapi/analysis/internal/debug"
)

var debugLog = debug.GetLogger("analysis", os.Getenv("SWAGGER_DEBUG") != "")
var debugLog = debug.GetLogger("analysis", os.Getenv("SWAGGER_DEBUG") != "") //nolint:gochecknoglobals // it's okay to use a private global for logging
8 changes: 4 additions & 4 deletions flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

const definitionsPath = "#/definitions"

// newRef stores information about refs created during the flattening process
// newRef stores information about refs created during the flattening process.
type newRef struct {
key string
newName string
Expand All @@ -32,7 +32,7 @@ type newRef struct {
parents []string
}

// context stores intermediary results from flatten
// context stores intermediary results from flatten.
type context struct {
newRefs map[string]*newRef
warnings []string
Expand Down Expand Up @@ -169,7 +169,7 @@ func expand(opts *FlattenOpts) error {
}

// normalizeRef strips the current file from any absolute file $ref. This works around issue go-openapi/spec#76:
// leading absolute file in $ref is stripped
// leading absolute file in $ref is stripped.
func normalizeRef(opts *FlattenOpts) error {
debugLog("normalizeRef")

Expand Down Expand Up @@ -521,7 +521,7 @@ func stripOAIGen(opts *FlattenOpts) (bool, error) {
return replacedWithComplex, nil
}

// updateRefParents updates all parents of an updated $ref
// updateRefParents updates all parents of an updated $ref.
func updateRefParents(allRefs map[string]spec.Ref, r *newRef) {
if !r.isOAIGen || r.resolved { // bail on already resolved entries (avoid looping)
return
Expand Down
8 changes: 4 additions & 4 deletions flatten_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import (
"github.com/go-openapi/swag/mangling"
)

// InlineSchemaNamer finds a new name for an inlined type
// InlineSchemaNamer finds a new name for an inlined type.
type InlineSchemaNamer struct {
Spec *spec.Swagger
Operations map[string]operations.OpRef
flattenContext *context
opts *FlattenOpts
}

// Name yields a new name for the inline schema
// Name yields a new name for the inline schema.
func (isn *InlineSchemaNamer) Name(key string, schema *spec.Schema, aschema *AnalyzedSchema) error {
debugLog("naming inlined schema at %s", key)

Expand Down Expand Up @@ -108,7 +108,7 @@ func (isn *InlineSchemaNamer) Name(key string, schema *spec.Schema, aschema *Ana
return nil
}

// uniqifyName yields a unique name for a definition
// uniqifyName yields a unique name for a definition.
func uniqifyName(definitions spec.Definitions, name string) (string, bool) {
isOAIGen := false
if name == "" {
Expand Down Expand Up @@ -244,7 +244,7 @@ func namesForDefinition(parts sortref.SplitKey) ([][]string, int) {
return [][]string{}, 0
}

// partAdder knows how to interpret a schema when it comes to build a name from parts
// partAdder knows how to interpret a schema when it comes to build a name from parts.
func partAdder(aschema *AnalyzedSchema) sortref.PartAdder {
return func(part string) []string {
segments := make([]string, 0, minSegments)
Expand Down
Loading