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

Swagger tags starting with integer make formatting errors in operations #2111

Closed
tomas-chudjak opened this issue Nov 17, 2019 · 0 comments · Fixed by #2181
Closed

Swagger tags starting with integer make formatting errors in operations #2111

tomas-chudjak opened this issue Nov 17, 2019 · 0 comments · Fixed by #2181

Comments

@tomas-chudjak
Copy link

Hi guys,

go-swagger has an issue to create operations from the swagger configuration if the path contains the first tag starting with an integer.

Sample swagger:

paths:
  /test:
    get:
      tags:
      - 123abc
      operationId: testId
      responses:
        200:
          description: Expected response to a valid request
          schema:
            type: object

Sample error:

$ package field 123abc
$ creating generated file "test_id_parameters.go" in "restapi\\operations\\123abc" as parameters
$ executed template asset:serverParameter
$ source formatting failed on template-generated source ("restapi\\operations\\123abc\\test_id_parameters.go" for parameters). Check that your template produces valid code 
$ unformatted generated source "test_id_parameters.go" has been dumped for template debugging purposes. DO NOT build on this source!
source formatting on generated source "parameters" failed: test_id_parameters.go:14:9: expected 'IDENT', found 123

I would like to keep this error here, as the output is not clear about the root cause.

Temporary solution:

  • rename tag to start with alphabet letter
  • if multiple tags, use the first tag with alphabet letter

Environment

swagger version: 0.21.0
go version: 1.13.4
OS: Windows

@fredbi fredbi self-assigned this Dec 31, 2019
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 16, 2020
* removed redundant code generation code regarding imports (and  let goimport sort it out)
* refactored imports in templates: imports are maps, codegen uses a language-specific funcmap
* mangle tag-based package names to safe names and use package aliasing
* introduced CLI option to disable tag-based package generation for operations
* introduced CLI option to override main server package location
* introduced x-go-operation-tag to alter tag-based package generation
* made global tag definition honor the x-go-name tag to alter tag-based package generation

Issues fixes:
* fixes go-swagger#1049 (tag override)
* fixes go-swagger#2111 (tag mangling)
* fixes go-swagger#2057 (tag mangling)
* fixes go-swagger#1291 (tag mangling)
* fixes go-swagger#1971 (main package mangling & override)

TODO: name aliasing for imported models

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>

sets our target for generator refactoring

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 26, 2020
* removed redundant code generation code regarding imports (and  let goimport sort it out)
* refactored imports in templates: imports are maps, codegen uses a language-specific funcmap

* mangle tag-based package names to safe names and use package aliasing

* introduced CLI option to disable tag-based package generation for operations
* introduced CLI option to override main server package location

* introduced x-go-operation-tag to alter tag-based package generation
* made global tag definition honor the x-go-name tag to alter tag-based package generation

* propagated changes to stratoscale contrib templates

Issues fixes:
* fixes go-swagger#1049 (tag override)
* fixes go-swagger#2111 (tag mangling)
* fixes go-swagger#2057 (tag mangling)
* fixes go-swagger#1291 (tag mangling)
* fixes go-swagger#1971 (main package mangling & main target override)

TODO: name aliasing and mangling for imported models remains to be done

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 26, 2020
* removed redundant code generation code regarding imports (and  let goimport sort it out)
* refactored imports in templates: imports are maps, codegen uses a language-specific funcmap

* mangle tag-based package names to safe names and use package aliasing

* introduced CLI option to disable tag-based package generation for operations
* introduced CLI option to override main server package location

* introduced x-go-operation-tag to alter tag-based package generation
* made global tag definition honor the x-go-name tag to alter tag-based package generation

* propagated changes to stratoscale contrib templates

Issues fixes:
* fixes go-swagger#1049 (tag override)
* fixes go-swagger#2111 (tag mangling)
* fixes go-swagger#2057 (tag mangling)
* fixes go-swagger#1291 (tag mangling)
* fixes go-swagger#1971 (main package mangling & main target override)

TODO: name aliasing and mangling for imported models remains to be done

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 26, 2020
* removed redundant code generation code regarding imports (and  let goimport sort it out)
* refactored imports in templates: imports are maps, codegen uses a language-specific funcmap

* mangle tag-based package names to safe names and use package aliasing

* introduced CLI option to disable tag-based package generation for operations
* introduced CLI option to override main server package location

* introduced x-go-operation-tag to alter tag-based package generation
* made global tag definition honor the x-go-name tag to alter tag-based package generation

* propagated changes to stratoscale contrib templates

Issues fixes:
* fixes go-swagger#1049 (tag override)
* fixes go-swagger#2111 (tag mangling)
* fixes go-swagger#2057 (tag mangling)
* fixes go-swagger#1291 (tag mangling)
* fixes go-swagger#1971 (main package mangling & main target override)

TODO: name aliasing and mangling for imported models remains to be done

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit that referenced this issue Jan 26, 2020
* Review of codegen imports and package name mangling

* removed redundant code generation code regarding imports (and  let goimport sort it out)
* refactored imports in templates: imports are maps, codegen uses a language-specific funcmap

* mangle tag-based package names to safe names and use package aliasing

* introduced CLI option to disable tag-based package generation for operations
* introduced CLI option to override main server package location

* introduced x-go-operation-tag to alter tag-based package generation
* made global tag definition honor the x-go-name tag to alter tag-based package generation

* propagated changes to stratoscale contrib templates

Issues fixes:
* fixes #1049 (tag override)
* fixes #2111 (tag mangling)
* fixes #2057 (tag mangling)
* fixes #1291 (tag mangling)
* fixes #1971 (main package mangling & main target override)

TODO: name aliasing and mangling for imported models remains to be done

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>

* fixup some linting after refactoring

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>

* fixup server doc

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants