Skip to content

Commit 9f28936

Browse files
committed
chore(lint): relinted the codebase to meet updated linter config
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent 5229610 commit 9f28936

21 files changed

+287
-217
lines changed

.golangci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ linters:
2626
min-len: 2
2727
min-occurrences: 3
2828
cyclop:
29-
max-complexity: 20
29+
max-complexity: 25
3030
gocyclo:
31-
min-complexity: 20
31+
min-complexity: 25
32+
gocognit:
33+
min-complexity: 35
3234
exhaustive:
3335
default-signifies-exhaustive: true
3436
default-case-required: true

analyzer.go

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ func New(doc *spec.Swagger) *Spec {
164164
return a
165165
}
166166

167-
// SecurityRequirement is a representation of a security requirement for an operation
167+
// SecurityRequirement is a representation of a security requirement for an operation.
168168
type SecurityRequirement struct {
169169
Name string
170170
Scopes []string
171171
}
172172

173-
// SecurityRequirementsFor gets the security requirements for the operation
173+
// SecurityRequirementsFor gets the security requirements for the operation.
174174
func (s *Spec) SecurityRequirementsFor(operation *spec.Operation) [][]SecurityRequirement {
175175
if s.spec.Security == nil && operation.Security == nil {
176176
return nil
@@ -204,7 +204,7 @@ func (s *Spec) SecurityRequirementsFor(operation *spec.Operation) [][]SecurityRe
204204
return result
205205
}
206206

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

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

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

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

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

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

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

427-
// Operations gathers all the operations specified in the spec document
427+
// Operations gathers all the operations specified in the spec document.
428428
func (s *Spec) Operations() map[string]map[string]*spec.Operation {
429429
return s.operations
430430
}
431431

432-
// AllPaths returns all the paths in the swagger spec
432+
// AllPaths returns all the paths in the swagger spec.
433433
func (s *Spec) AllPaths() map[string]spec.PathItem {
434434
if s.spec == nil || s.spec.Paths == nil {
435435
return nil
@@ -438,7 +438,7 @@ func (s *Spec) AllPaths() map[string]spec.PathItem {
438438
return s.spec.Paths.Paths
439439
}
440440

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

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

477-
// RequiredConsumes gets all the distinct consumes that are specified in the specification document
477+
// RequiredConsumes gets all the distinct consumes that are specified in the specification document.
478478
func (s *Spec) RequiredConsumes() []string {
479479
return s.structMapKeys(s.consumes)
480480
}
481481

482-
// RequiredProduces gets all the distinct produces that are specified in the specification document
482+
// RequiredProduces gets all the distinct produces that are specified in the specification document.
483483
func (s *Spec) RequiredProduces() []string {
484484
return s.structMapKeys(s.produces)
485485
}
486486

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

492-
// SchemaRef is a reference to a schema
492+
// SchemaRef is a reference to a schema.
493493
type SchemaRef struct {
494494
Name string
495495
Ref spec.Ref
@@ -498,7 +498,7 @@ type SchemaRef struct {
498498
}
499499

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

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

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

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

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

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

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

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

594594
// ParameterPatterns returns all the patterns found in parameters
595-
// the map is cloned to avoid accidental changes
595+
// the map is cloned to avoid accidental changes.
596596
func (s *Spec) ParameterPatterns() map[string]string {
597597
return cloneStringMap(s.patterns.parameters)
598598
}
599599

600600
// HeaderPatterns returns all the patterns found in response headers
601-
// the map is cloned to avoid accidental changes
601+
// the map is cloned to avoid accidental changes.
602602
func (s *Spec) HeaderPatterns() map[string]string {
603603
return cloneStringMap(s.patterns.headers)
604604
}
605605

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

612612
// SchemaPatterns returns all the patterns found in schemas
613-
// the map is cloned to avoid accidental changes
613+
// the map is cloned to avoid accidental changes.
614614
func (s *Spec) SchemaPatterns() map[string]string {
615615
return cloneStringMap(s.patterns.schemas)
616616
}
617617

618618
// AllPatterns returns all the patterns found in the spec
619-
// the map is cloned to avoid accidental changes
619+
// the map is cloned to avoid accidental changes.
620620
func (s *Spec) AllPatterns() map[string]string {
621621
return cloneStringMap(s.patterns.allPatterns)
622622
}
623623

624624
// ParameterEnums returns all the enums found in parameters
625-
// the map is cloned to avoid accidental changes
625+
// the map is cloned to avoid accidental changes.
626626
func (s *Spec) ParameterEnums() map[string][]any {
627627
return cloneEnumMap(s.enums.parameters)
628628
}
629629

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

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

642642
// SchemaEnums returns all the enums found in schemas
643-
// the map is cloned to avoid accidental changes
643+
// the map is cloned to avoid accidental changes.
644644
func (s *Spec) SchemaEnums() map[string][]any {
645645
return cloneEnumMap(s.enums.schemas)
646646
}
647647

648648
// AllEnums returns all the enums found in the spec
649-
// the map is cloned to avoid accidental changes
649+
// the map is cloned to avoid accidental changes.
650650
func (s *Spec) AllEnums() map[string][]any {
651651
return cloneEnumMap(s.enums.allEnums)
652652
}

debug.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ import (
99
"github.com/go-openapi/analysis/internal/debug"
1010
)
1111

12-
var debugLog = debug.GetLogger("analysis", os.Getenv("SWAGGER_DEBUG") != "")
12+
var debugLog = debug.GetLogger("analysis", os.Getenv("SWAGGER_DEBUG") != "") //nolint:gochecknoglobals // it's okay to use a private global for logging

flatten.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
const definitionsPath = "#/definitions"
2323

24-
// newRef stores information about refs created during the flattening process
24+
// newRef stores information about refs created during the flattening process.
2525
type newRef struct {
2626
key string
2727
newName string
@@ -32,7 +32,7 @@ type newRef struct {
3232
parents []string
3333
}
3434

35-
// context stores intermediary results from flatten
35+
// context stores intermediary results from flatten.
3636
type context struct {
3737
newRefs map[string]*newRef
3838
warnings []string
@@ -169,7 +169,7 @@ func expand(opts *FlattenOpts) error {
169169
}
170170

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

@@ -521,7 +521,7 @@ func stripOAIGen(opts *FlattenOpts) (bool, error) {
521521
return replacedWithComplex, nil
522522
}
523523

524-
// updateRefParents updates all parents of an updated $ref
524+
// updateRefParents updates all parents of an updated $ref.
525525
func updateRefParents(allRefs map[string]spec.Ref, r *newRef) {
526526
if !r.isOAIGen || r.resolved { // bail on already resolved entries (avoid looping)
527527
return

flatten_name.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ import (
1717
"github.com/go-openapi/swag/mangling"
1818
)
1919

20-
// InlineSchemaNamer finds a new name for an inlined type
20+
// InlineSchemaNamer finds a new name for an inlined type.
2121
type InlineSchemaNamer struct {
2222
Spec *spec.Swagger
2323
Operations map[string]operations.OpRef
2424
flattenContext *context
2525
opts *FlattenOpts
2626
}
2727

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

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

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

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

0 commit comments

Comments
 (0)