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
Client wont compile with a route tagged "test" #1683
Comments
Looks like removing the snakize here
is enough to fix things. On the other hand, snakize is missing here: go-swagger/generator/shared.go Line 442 in b10bd7b
This problem seems limited to client generation: no issue when testing with server codegen. Also please note that some name conflicts are possible, and probably unavoidable like: choosing a tag like: "strfmt", "httptransport", "runtime", "models", "api" ... will almost certainly generate name conflicts. |
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Makes generation functional and consistent regarding: * dashes in names * reserved suffixes, which are meaningful for go, like 'test' * sub-directories specified as target names (e.g. 'api/subdir') * packages for client, model and server * fixes go-swagger#1683 * fixes go-swagger#1157 * fixes go-swagger#1624 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Makes generation functional and consistent regarding: * dashes in names * reserved suffixes, which are meaningful for go, like 'test' * sub-directories specified as target names (e.g. 'api/subdir') * packages for client, model and server * fixes go-swagger#1683 * fixes go-swagger#1157 * fixes go-swagger#1624 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Makes generation functional and consistent regarding: * dashes in names * reserved suffixes, which are meaningful for go, like 'test' * sub-directories specified as target names (e.g. 'api/subdir') * packages for client, model and server * fixes go-swagger#1683 * fixes go-swagger#1157 * fixes go-swagger#1624 * replaces go-swagger#1790 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Makes generation functional and consistent regarding: * dashes in names * reserved suffixes, which are meaningful for go, like 'test' * sub-directories specified as target names (e.g. 'api/subdir') * packages for client, model and server * fixes go-swagger#1683 * fixes go-swagger#1157 * fixes go-swagger#1624 * replaces go-swagger#1790 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Problem statement
Have a swagger with a route tagged "test", it can generate the client but it wont compile. The basic client file generated contains a struct referencing a package test_swagger which does not exist.
After a little digging it seems the template generation uses formatting function called snakize which changes the name (protection against reserved words) but not all formatting functions do this or use is inconsistent.
See here, this is the line that fails to compile for "test":
https://github.com/go-swagger/go-swagger/blob/master/generator/templates/client/facade.gotmpl#L120
This seems to boil down to a MangleFileName func which goes to a LanguageOpts fileNameFunc and there is a comment /code that does some special reserved word protection where it will append "_swagger" on to it
So it seems this struct is having that package manipulated / matched the reserved word but other usages are not, neither is the import which is why the struct package is not found / failing to compile.
An example of a place using .Name directly.
https://github.com/go-swagger/go-swagger/blob/master/generator/templates/client/facade.gotmpl#L73
The other thing I noticed for the client operations it generates a folder in its name, which is "client/test" -- i.e. it doesn't attempt to do the _swagger. So either snakize and some of the formatting functions are being a little over zealous or the _swagger notion is missing from a few places including the folder creations. Thats when I entered a rabbit hole.
I also found this ticket:
#1157
Which also seems to have some inconsistency related to use of formatting functions.
The simple workaround is to tag the route as something a little more specific / not use a reserved word.
Swagger specification
Steps to reproduce
Generate a client with a swagger file that contains a route tagged with "test", will generate but shouldnt compile.
Environment
swagger version: 0.16.0
go version: 1.10.3
OS: Linux Mint 18
The text was updated successfully, but these errors were encountered: