Skip to content

Commit 72d07cd

Browse files
committed
chore: linting code (#1533)
* chore: make fmt * chore: make lint
1 parent 601fee1 commit 72d07cd

File tree

5 files changed

+28
-27
lines changed

5 files changed

+28
-27
lines changed

field_parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
swaggerTypeTag = "swaggertype"
2222
swaggerIgnoreTag = "swaggerignore"
2323
)
24+
2425
var _ FieldParser = &tagBaseFieldParser{}
2526

2627
type tagBaseFieldParser struct {

field_parserv3.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -457,21 +457,21 @@ func (sf *structFieldV3) parseValidTags(validTag string) {
457457
}
458458
}
459459

460-
func (field *structFieldV3) parseEnumTags(enumTag string) error {
461-
enumType := field.schemaType
462-
if field.schemaType == ARRAY {
463-
enumType = field.arrayType
460+
func (sf *structFieldV3) parseEnumTags(enumTag string) error {
461+
enumType := sf.schemaType
462+
if sf.schemaType == ARRAY {
463+
enumType = sf.arrayType
464464
}
465465

466-
field.enums = nil
466+
sf.enums = nil
467467

468468
for _, e := range strings.Split(enumTag, ",") {
469469
value, err := defineType(enumType, e)
470470
if err != nil {
471471
return err
472472
}
473473

474-
field.enums = append(field.enums, value)
474+
sf.enums = append(sf.enums, value)
475475
}
476476

477477
return nil

operation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,9 +1215,9 @@ func getCodeExampleForSummary(summaryName string, dirPath string) ([]byte, bool,
12151215

12161216
fileName := entry.Name()
12171217

1218-
isJson := strings.Contains(fileName, ".json")
1218+
isJSON := strings.Contains(fileName, ".json")
12191219
isYaml := strings.Contains(fileName, ".yaml")
1220-
if !isJson && !isYaml {
1220+
if !isJSON && !isYaml {
12211221
continue
12221222
}
12231223

@@ -1229,7 +1229,7 @@ func getCodeExampleForSummary(summaryName string, dirPath string) ([]byte, bool,
12291229
return nil, false, fmt.Errorf("Failed to read code example file %s error: %s ", fullPath, err)
12301230
}
12311231

1232-
return commentInfo, isJson, nil
1232+
return commentInfo, isJSON, nil
12331233
}
12341234
}
12351235

operationv3.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"gopkg.in/yaml.v2"
1414
)
1515

16-
// Operation describes a single API operation on a path.
16+
// OperationV3 describes a single API operation on a path.
1717
// For more information: https://github.com/swaggo/swag#api-operation
1818
type OperationV3 struct {
1919
parser *Parser
@@ -39,7 +39,7 @@ func NewOperationV3(parser *Parser, options ...func(*OperationV3)) *OperationV3
3939
return operation
4040
}
4141

42-
// SetCodeExampleFilesDirectory sets the directory to search for codeExamples.
42+
// SetCodeExampleFilesDirectoryV3 sets the directory to search for codeExamples.
4343
func SetCodeExampleFilesDirectoryV3(directoryPath string) func(*OperationV3) {
4444
return func(o *OperationV3) {
4545
o.codeExampleFilesDir = directoryPath

parserv3.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import (
1414
"github.com/sv-tools/openapi/spec"
1515
)
1616

17-
// FieldParserFactory create FieldParser.
17+
// FieldParserFactoryV3 func(ps *Parser, field *ast.Field) FieldParserV3 create FieldParser.
1818
type FieldParserFactoryV3 func(ps *Parser, field *ast.Field) FieldParserV3
1919

20-
// FieldParser parse struct field.
20+
// FieldParserV3 parse struct field.
2121
type FieldParserV3 interface {
2222
ShouldSkip() bool
2323
FieldName() (string, error)
@@ -28,8 +28,8 @@ type FieldParserV3 interface {
2828
}
2929

3030
// GetOpenAPI returns *spec.OpenAPI which is the root document object for the API specification.
31-
func (parser *Parser) GetOpenAPI() *spec.OpenAPI {
32-
return parser.openAPI
31+
func (p *Parser) GetOpenAPI() *spec.OpenAPI {
32+
return p.openAPI
3333
}
3434

3535
func (p *Parser) parseGeneralAPIInfoV3(comments []string) error {
@@ -419,8 +419,8 @@ func getSecurityDefinitionKey(lines []string) string {
419419
return ""
420420
}
421421

422-
// ParseRouterAPIInfo parses router api info for given astFile.
423-
func (parser *Parser) ParseRouterAPIInfoV3(fileInfo *AstFileInfo) error {
422+
// ParseRouterAPIInfoV3 parses router api info for given astFile.
423+
func (p *Parser) ParseRouterAPIInfoV3(fileInfo *AstFileInfo) error {
424424
for _, astDescription := range fileInfo.File.Decls {
425425
if (fileInfo.ParseFlag & ParseOperations) == ParseNone {
426426
continue
@@ -431,18 +431,18 @@ func (parser *Parser) ParseRouterAPIInfoV3(fileInfo *AstFileInfo) error {
431431
continue
432432
}
433433

434-
if parser.matchTags(astDeclaration.Doc.List) &&
435-
matchExtension(parser.parseExtension, astDeclaration.Doc.List) {
434+
if p.matchTags(astDeclaration.Doc.List) &&
435+
matchExtension(p.parseExtension, astDeclaration.Doc.List) {
436436
// for per 'function' comment, create a new 'Operation' object
437-
operation := NewOperationV3(parser, SetCodeExampleFilesDirectoryV3(parser.codeExampleFilesDir))
437+
operation := NewOperationV3(p, SetCodeExampleFilesDirectoryV3(p.codeExampleFilesDir))
438438

439439
for _, comment := range astDeclaration.Doc.List {
440440
err := operation.ParseComment(comment.Text, fileInfo.File)
441441
if err != nil {
442442
return fmt.Errorf("ParseComment error in file %s :%+v", fileInfo.Path, err)
443443
}
444444
}
445-
err := processRouterOperationV3(parser, operation)
445+
err := processRouterOperationV3(p, operation)
446446
if err != nil {
447447
return err
448448
}
@@ -941,8 +941,8 @@ func (p *Parser) getRefTypeSchemaV3(typeSpecDef *TypeSpecDef, schema *SchemaV3)
941941
return refSchema
942942
}
943943

944-
// GetSchemaTypePath get path of schema type.
945-
func (parser *Parser) GetSchemaTypePathV3(schema *spec.RefOrSpec[spec.Schema], depth int) []string {
944+
// GetSchemaTypePathV3 get path of schema type.
945+
func (p *Parser) GetSchemaTypePathV3(schema *spec.RefOrSpec[spec.Schema], depth int) []string {
946946
if schema == nil || depth == 0 {
947947
return nil
948948
}
@@ -955,8 +955,8 @@ func (parser *Parser) GetSchemaTypePathV3(schema *spec.RefOrSpec[spec.Schema], d
955955
if name != "" {
956956
if pos := strings.LastIndexByte(name, '/'); pos >= 0 {
957957
name = name[pos+1:]
958-
if schema, ok := parser.openAPI.Components.Spec.Schemas[name]; ok {
959-
return parser.GetSchemaTypePathV3(schema, depth)
958+
if schema, ok := p.openAPI.Components.Spec.Schemas[name]; ok {
959+
return p.GetSchemaTypePathV3(schema, depth)
960960
}
961961
}
962962

@@ -970,15 +970,15 @@ func (parser *Parser) GetSchemaTypePathV3(schema *spec.RefOrSpec[spec.Schema], d
970970

971971
s := []string{schema.Spec.Type[0]}
972972

973-
return append(s, parser.GetSchemaTypePathV3(schema.Spec.Items.Schema, depth)...)
973+
return append(s, p.GetSchemaTypePathV3(schema.Spec.Items.Schema, depth)...)
974974
case OBJECT:
975975
if schema.Spec.AdditionalProperties != nil && schema.Spec.AdditionalProperties.Schema != nil {
976976
// for map
977977
depth--
978978

979979
s := []string{schema.Spec.Type[0]}
980980

981-
return append(s, parser.GetSchemaTypePathV3(schema.Spec.AdditionalProperties.Schema, depth)...)
981+
return append(s, p.GetSchemaTypePathV3(schema.Spec.AdditionalProperties.Schema, depth)...)
982982
}
983983
}
984984

0 commit comments

Comments
 (0)