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

API Swagger Json files should be added to the .gitignore #256

Closed
acourt opened this issue Aug 15, 2018 · 1 comment
Closed

API Swagger Json files should be added to the .gitignore #256

acourt opened this issue Aug 15, 2018 · 1 comment

Comments

@acourt
Copy link

acourt commented Aug 15, 2018

Is this a bug or a feature request?

Bug

What did you expect?

I expect that when I perform a make command that generates a bunch of generated files, it shouldn't show up in the change list.

If these files are generated, shouldn't they be added to the .gitignore? This way when you perform modifications and commits, you don't have a polluted changelist.

What happened?

When performing a build from scratch, following the instructions given for the build using the makefile, building the API files performs a bunch of modifications *.swagger.json files that are in the api directory.

What version are your using?

Master branch (commit 12076fa189a8e59ae9941945eb233fced8726dd4)

How can your issue be reproduced?

git pull origin master
make requirements
make ui-requirements
make api
git status

Could you share your log output?

On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   Gopkg.lock
        modified:   ui/package-lock.json

no changes added to commit (use "git add" and/or "git commit -a")
ubuntu@dev-loraserverio:~/work/src/github.com/brocaar/lora-app-server$ make api
Generating API code from .proto files
ubuntu@dev-loraserverio:~/work/src/github.com/brocaar/lora-app-server$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   Gopkg.lock
        modified:   api/common.pb.go
        modified:   api/device.pb.go
        modified:   api/gateway.pb.go
        modified:   api/swagger/application.swagger.json
        modified:   api/swagger/device.swagger.json
        modified:   api/swagger/deviceProfile.swagger.json
        modified:   api/swagger/deviceQueue.swagger.json
        modified:   api/swagger/gateway.swagger.json
        modified:   api/swagger/gatewayProfile.swagger.json
        modified:   api/swagger/internal.swagger.json
        modified:   api/swagger/networkServer.swagger.json
        modified:   api/swagger/organization.swagger.json
        modified:   api/swagger/serviceProfile.swagger.json
        modified:   api/swagger/user.swagger.json
        modified:   ui/package-lock.json

no changes added to commit (use "git add" and/or "git commit -a")
@brocaar
Copy link
Owner

brocaar commented Aug 18, 2018

The swagger api files are included on purpose, the same for the generated *.pb.go files. Please note that there is currently an issue in the swagger generator, it does not respect the json_name option in the .proto files. See: grpc-ecosystem/grpc-gateway#681.

Unless you are making API modifications, there is no need to run make api. If you do, consider applying this patch to $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway

diff --git a/protoc-gen-swagger/genswagger/template.go b/protoc-gen-swagger/genswagger/template.go
index f12ea38..cc98e77 100644
--- a/protoc-gen-swagger/genswagger/template.go
+++ b/protoc-gen-swagger/genswagger/template.go
@@ -107,7 +107,7 @@ func queryParams(message *descriptor.Message, field *descriptor.Field, prefix st
                        desc = strings.TrimSpace(schema.Title + ". " + schema.Description)
                }
                param := swaggerParameterObject{
-                       Name:        prefix + field.GetName(),
+                       Name:        prefix + field.GetJsonName(),
                        Description: desc,
                        In:          "query",
                        Type:        schema.Type,
@@ -143,7 +143,7 @@ func queryParams(message *descriptor.Message, field *descriptor.Field, prefix st
                return nil, fmt.Errorf("unknown message type %s", fieldType)
        }
        for _, nestedField := range msg.Fields {
-               p, err := queryParams(msg, nestedField, prefix+field.GetName()+".", reg, pathParams)
+               p, err := queryParams(msg, nestedField, prefix+field.GetJsonName()+".", reg, pathParams)
                if err != nil {
                        return nil, err
                }
@@ -251,7 +251,7 @@ func renderMessagesAsDefinition(messages messageMap, d swaggerDefinitionsObject,
                                panic(err)
                        }

-                       schema.Properties = append(schema.Properties, keyVal{f.GetName(), fieldValue})
+                       schema.Properties = append(schema.Properties, keyVal{f.GetJsonName(), fieldValue})
                }
                d[fullyQualifiedNameToSwaggerName(msg.FQMN(), reg)] = schema
        }

@brocaar brocaar closed this as completed Aug 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants