Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upper cases in x-tentions dont work in general API info #916

Open
Janwillemtv opened this issue Apr 14, 2021 · 2 comments
Open

Upper cases in x-tentions dont work in general API info #916

Janwillemtv opened this issue Apr 14, 2021 · 2 comments
Labels

Comments

@Janwillemtv
Copy link

Describe the bug
I have run into an issue when declaring tagGroups in the general API information.
When using // @x-tagGroups [{"name":"General","tags":["lanes","video-recommendations"]}]
it gives the error annotation @x-taggroups need a value

When looking into it it seems you already fixed this issue for the operation side of it, but not for the general API parser.
What happens is that the attribute gets extracted and lowercased from the commentline

attribute := strings.ToLower(strings.Split(commentLine, " ")[0])

so in this example it becomes @x-taggroups.

In the switch case for ParseGeneralAPIInfo in parser.go the default action tries to split the comment using this lowercased attribute:

default:
prefixExtension := "@x-"
if len(attribute) > 5 { // Prefix extension + 1 char + 1 space  + 1 char
	if attribute[:len(prefixExtension)] == prefixExtension {
		var valueJSON interface{}
                // HERE IS THE ISSUE
		split := strings.SplitAfter(commentLine, attribute+" ")
		if len(split) < 2 {
			return fmt.Errorf("annotation %s need a value", attribute)
		}

For camelcased @x-tentions (or any x-tentions using Upper case) it always returns an error because it tries to split the commentLine using the lowercased version of the attribute, which does not match because it still contains upper cases.

It works when using // @x-taggroups (so all lower case) but this does not give a working swagger doc with camelcased x-tentions.

To Reproduce
Steps to reproduce the behavior:

  1. Use // @x-tagGroups [{"name":"General","tags":["lanes","video-recommendations"]}] as a general API doc
  2. run swag init
  3. See error annotation @x-taggroups need a value

Expected behavior

  1. Use // @x-tagGroups [{"name":"General","tags":["lanes","video-recommendations"]}] as a general API doc
  2. run swag init
  3. swagger.yaml doc should contain:
x-tagGroups:
  - name: General
    tags:
      - lanes
      - video-recommendations

Your swag version
e.g. 1.7

Your go version
e.g. 1.13.8

Desktop:

  • OS: linux/ubuntu
  • Browser: chrome
  • Version: 89
@ubogdan ubogdan added the bug label Sep 8, 2021
@ubogdan
Copy link
Contributor

ubogdan commented Sep 8, 2021

I will take a look into it any time soon.

@ubogdan
Copy link
Contributor

ubogdan commented Sep 29, 2021

The fix will be released with v1.7.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants