Skip to content

Commit

Permalink
chore: linting code (#1533)
Browse files Browse the repository at this point in the history
* chore: make fmt

* chore: make lint
  • Loading branch information
ubogdan authored Apr 5, 2023
1 parent b060856 commit 4d56898
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
1 change: 1 addition & 0 deletions field_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
swaggerTypeTag = "swaggertype"
swaggerIgnoreTag = "swaggerignore"
)

var _ FieldParser = &tagBaseFieldParser{}

type tagBaseFieldParser struct {
Expand Down
12 changes: 6 additions & 6 deletions field_parserv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,21 +457,21 @@ func (sf *structFieldV3) parseValidTags(validTag string) {
}
}

func (field *structFieldV3) parseEnumTags(enumTag string) error {
enumType := field.schemaType
if field.schemaType == ARRAY {
enumType = field.arrayType
func (sf *structFieldV3) parseEnumTags(enumTag string) error {
enumType := sf.schemaType
if sf.schemaType == ARRAY {
enumType = sf.arrayType
}

field.enums = nil
sf.enums = nil

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

field.enums = append(field.enums, value)
sf.enums = append(sf.enums, value)
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1202,9 +1202,9 @@ func getCodeExampleForSummary(summaryName string, dirPath string) ([]byte, bool,

fileName := entry.Name()

isJson := strings.Contains(fileName, ".json")
isJSON := strings.Contains(fileName, ".json")
isYaml := strings.Contains(fileName, ".yaml")
if !isJson && !isYaml {
if !isJSON && !isYaml {
continue
}

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

return commentInfo, isJson, nil
return commentInfo, isJSON, nil
}
}

Expand Down
4 changes: 2 additions & 2 deletions operationv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"gopkg.in/yaml.v2"
)

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

// SetCodeExampleFilesDirectory sets the directory to search for codeExamples.
// SetCodeExampleFilesDirectoryV3 sets the directory to search for codeExamples.
func SetCodeExampleFilesDirectoryV3(directoryPath string) func(*OperationV3) {
return func(o *OperationV3) {
o.codeExampleFilesDir = directoryPath
Expand Down
32 changes: 16 additions & 16 deletions parserv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"github.com/sv-tools/openapi/spec"
)

// FieldParserFactory create FieldParser.
// FieldParserFactoryV3 func(ps *Parser, field *ast.Field) FieldParserV3 create FieldParser.
type FieldParserFactoryV3 func(ps *Parser, field *ast.Field) FieldParserV3

// FieldParser parse struct field.
// FieldParserV3 parse struct field.
type FieldParserV3 interface {
ShouldSkip() bool
FieldName() (string, error)
Expand All @@ -28,8 +28,8 @@ type FieldParserV3 interface {
}

// GetOpenAPI returns *spec.OpenAPI which is the root document object for the API specification.
func (parser *Parser) GetOpenAPI() *spec.OpenAPI {
return parser.openAPI
func (p *Parser) GetOpenAPI() *spec.OpenAPI {
return p.openAPI
}

func (p *Parser) parseGeneralAPIInfoV3(comments []string) error {
Expand Down Expand Up @@ -419,8 +419,8 @@ func getSecurityDefinitionKey(lines []string) string {
return ""
}

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

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

for _, comment := range astDeclaration.Doc.List {
err := operation.ParseComment(comment.Text, fileInfo.File)
if err != nil {
return fmt.Errorf("ParseComment error in file %s :%+v", fileInfo.Path, err)
}
}
err := processRouterOperationV3(parser, operation)
err := processRouterOperationV3(p, operation)
if err != nil {
return err
}
Expand Down Expand Up @@ -941,8 +941,8 @@ func (p *Parser) getRefTypeSchemaV3(typeSpecDef *TypeSpecDef, schema *SchemaV3)
return refSchema
}

// GetSchemaTypePath get path of schema type.
func (parser *Parser) GetSchemaTypePathV3(schema *spec.RefOrSpec[spec.Schema], depth int) []string {
// GetSchemaTypePathV3 get path of schema type.
func (p *Parser) GetSchemaTypePathV3(schema *spec.RefOrSpec[spec.Schema], depth int) []string {
if schema == nil || depth == 0 {
return nil
}
Expand All @@ -955,8 +955,8 @@ func (parser *Parser) GetSchemaTypePathV3(schema *spec.RefOrSpec[spec.Schema], d
if name != "" {
if pos := strings.LastIndexByte(name, '/'); pos >= 0 {
name = name[pos+1:]
if schema, ok := parser.openAPI.Components.Spec.Schemas[name]; ok {
return parser.GetSchemaTypePathV3(schema, depth)
if schema, ok := p.openAPI.Components.Spec.Schemas[name]; ok {
return p.GetSchemaTypePathV3(schema, depth)
}
}

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

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

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

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

return append(s, parser.GetSchemaTypePathV3(schema.Spec.AdditionalProperties.Schema, depth)...)
return append(s, p.GetSchemaTypePathV3(schema.Spec.AdditionalProperties.Schema, depth)...)
}
}

Expand Down
1 change: 0 additions & 1 deletion testdata/parseExtension/parseExtension.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ func Fun2() {}
func Fun3() {}

// @Router /with-empty-comment-line [get]
//
func FunEmptyCommentLine() {}

0 comments on commit 4d56898

Please sign in to comment.