Skip to content

fields named like "+1" cause swagger to fail gnerating a cli #2764

@hxw

Description

@hxw

Problem statement

attempting to use a struct from: github.com/google/go-github/v43/github

// GithubWebhook GoDoc
// @security     githubHMACAuth
// @summary      GithubWebhook
// @description  Github webhook entrypoint
// @tags         Webhook
// @param        event  body  github.IssueCommentEvent  true  "options"
// @accept       json
// @produce      json
// @success      200  {object}  

This references the reactions.go file which contains the following Reactions struct
:

// Reactions represents a summary of GitHub reactions.                                                                                                         
type Reactions struct {                                                                                                                                        
        TotalCount *int    `json:"total_count,omitempty"`                                                                                                      
        PlusOne    *int    `json:"+1,omitempty"`                                                                                                               
        MinusOne   *int    `json:"-1,omitempty"`                   

which shows in swagger.yaml as:

  github.Reactions:
    properties:
      "+1":
        type: integer
      "-1":
        type: integer
      confused:
        type: integer

which produces the following:

func registerGithubReactionsPlus1(depth int, cmdPrefix string, cmd *cobra.Command) error{
    if depth > maxDepth {
        return nil
    }
    1Description := ``   
    var 1FlagName string
    if cmdPrefix == "" {
        1FlagName = "+1"
    }else{
        1FlagName = fmt.Sprintf("%v.+1", cmdPrefix)
    }
    var 1FlagDefault int64  
        _ = cmd.PersistentFlags().Int64(1FlagName, 1FlagDefault, 1Description)
    return nil
}

func registerGithubReactionsMinus1(depth int, cmdPrefix string, cmd *cobra.Command) error{
    if depth > maxDepth {
        return nil
    }
    1Description := ``
    var 1FlagName string

It looks like the Function names get the +1/-1 converted to Plus1/Minus1 but the Description/FlagName do not get the Plus/Minus and so are invalid variable names

Please remove the sections that don't apply

Swagger specification

// GithubWebhook GoDoc
// @security     githubHMACAuth
// @summary      GithubWebhook
// @description  Github webhook entrypoint
// @tags         Webhook
// @param        event  body  github.IssueCommentEvent  true  "options"
// @accept       json
// @produce      json
// @success      200  {object}  

Steps to reproduce

Have a struct field with a tag starting with a non-alphabetic character:

Environment

swagger version: "dev" built from:

42c184c0 Merge pull request #2751 from Huckletoon/issue-1957-vendor-extension.. 2022-03-30 14:17:16 E Ivan Porto Carrero HEAD -> master, origin/master, origin/HEAD

go version: go1.18 freebsd/amd64
OS: FreeBSD 13.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions