mikkeloscar/gin-swagger

Add documentation on how to extend the templates

Closed this issue · 5 comments

Raffo commented

I have extended the template in https://github.com/Raffo/gin-swagger/blob/master/templates/api.gotmpl#L93 but I don't really understand how I can make it possible to update the templates used for generation on my machine.

I tried:

make generate
make

The gin-swagger binary generates the same templates even if they were updated. Can you provide some more info on what to check and maybe we can add it to the readme as well?

NOTE: this was done at 5 AM at the airport, so it might be subject to "I didn't know what I was doing".

It should be enough to run make.
Make sure you are not running the gin-swagger binary from your $GOPATH/bin but the local one (./gin-swagger).

Raffo commented

Ok, PBCAC is always possible, but this is not the case and I made sure about that (by overwriting it in my $GOPATH/bin ) already. So yeah, I don't know. Anything else I should try?

I usually check changes to the templates against the example folder like this:

cd example
make -C ../ && ../gin-swagger -A my-api -f swagger.yaml

If this doesn't work, then maybe post the log of running gin-swagger maybe something is broken?

Raffo commented

It didn't work.
Here the output:

make -C ../ && ../gin-swagger -A my-api -f swagger.yaml
CGO_ENABLED=0 go build -o gin-swagger -v -ldflags "-X main.version= -w -s"
net
gopkg.in/alecthomas/kingpin.v2
github.com/mikkeloscar/gin-swagger
I'm the new one.
2017/09/16 20:32:39 trying to read config from /var/folders/gx/6z_my5097_x19771qgv6hr3w0000gn/T/gin-swagger-1505586759553096401/config.yaml
2017/09/16 20:32:42 building a plan for generation
2017/09/16 20:32:42 planning definitions
2017/09/16 20:32:42 planning operations
2017/09/16 20:32:42 grouping operations into packages
2017/09/16 20:32:42 planning meta data and facades
2017/09/16 20:32:42 rendering 8 models
2017/09/16 20:32:42 rendering 1 templates for model InfrastructureAccount
2017/09/16 20:32:42 name field InfrastructureAccount
2017/09/16 20:32:42 package field models
2017/09/16 20:32:42 creating "infrastructure_account.go" in "models" as definition
2017/09/16 20:32:42 rendering 1 templates for model InfrastructureAccountUpdate
2017/09/16 20:32:42 name field InfrastructureAccountUpdate
2017/09/16 20:32:42 package field models
2017/09/16 20:32:42 creating "infrastructure_account_update.go" in "models" as definition
2017/09/16 20:32:42 rendering 1 templates for model Cluster
2017/09/16 20:32:42 name field Cluster
2017/09/16 20:32:42 package field models
2017/09/16 20:32:42 creating "cluster.go" in "models" as definition
2017/09/16 20:32:42 rendering 1 templates for model ClusterUpdate
2017/09/16 20:32:42 name field ClusterUpdate
2017/09/16 20:32:42 package field models
2017/09/16 20:32:42 creating "cluster_update.go" in "models" as definition
2017/09/16 20:32:42 rendering 1 templates for model ConfigValue
2017/09/16 20:32:42 name field ConfigValue
2017/09/16 20:32:42 package field models
2017/09/16 20:32:42 creating "config_value.go" in "models" as definition
2017/09/16 20:32:42 rendering 1 templates for model ClusterStatus
2017/09/16 20:32:42 name field ClusterStatus
2017/09/16 20:32:42 package field models
2017/09/16 20:32:42 creating "cluster_status.go" in "models" as definition
2017/09/16 20:32:42 rendering 1 templates for model NodePool
2017/09/16 20:32:42 name field NodePool
2017/09/16 20:32:42 package field models
2017/09/16 20:32:42 creating "node_pool.go" in "models" as definition
2017/09/16 20:32:42 rendering 1 templates for model Error
2017/09/16 20:32:42 name field Error
2017/09/16 20:32:42 package field models
2017/09/16 20:32:42 creating "error.go" in "models" as definition
2017/09/16 20:32:42 rendering 4 operation groups (tags)
2017/09/16 20:32:42 rendering 5 operations for clusters
2017/09/16 20:32:42 rendering 1 templates for operation my-api
2017/09/16 20:32:42 name field createCluster
2017/09/16 20:32:42 package field clusters
2017/09/16 20:32:42 creating "create_cluster_parameters.go" in "restapi/operations/clusters" as parameters
2017/09/16 20:32:42 rendering 1 templates for operation my-api
2017/09/16 20:32:42 name field deleteCluster
2017/09/16 20:32:42 package field clusters
2017/09/16 20:32:42 creating "delete_cluster_parameters.go" in "restapi/operations/clusters" as parameters
2017/09/16 20:32:42 rendering 1 templates for operation my-api
2017/09/16 20:32:42 name field getCluster
2017/09/16 20:32:42 package field clusters
2017/09/16 20:32:42 creating "get_cluster_parameters.go" in "restapi/operations/clusters" as parameters
2017/09/16 20:32:42 rendering 1 templates for operation my-api
2017/09/16 20:32:42 name field listClusters
2017/09/16 20:32:42 package field clusters
2017/09/16 20:32:42 creating "list_clusters_parameters.go" in "restapi/operations/clusters" as parameters
2017/09/16 20:32:42 rendering 1 templates for operation my-api
2017/09/16 20:32:42 name field updateCluster
2017/09/16 20:32:42 package field clusters
2017/09/16 20:32:42 creating "update_cluster_parameters.go" in "restapi/operations/clusters" as parameters
2017/09/16 20:32:42 rendering 2 operations for config_items
2017/09/16 20:32:42 rendering 1 templates for operation my-api
2017/09/16 20:32:42 name field addOrUpdateConfigItem
2017/09/16 20:32:42 package field config_items
2017/09/16 20:32:42 creating "add_or_update_config_item_parameters.go" in "restapi/operations/config_items" as parameters
2017/09/16 20:32:42 rendering 1 templates for operation my-api
2017/09/16 20:32:42 name field deleteConfigItem
2017/09/16 20:32:42 package field config_items
2017/09/16 20:32:42 creating "delete_config_item_parameters.go" in "restapi/operations/config_items" as parameters
2017/09/16 20:32:42 rendering 4 operations for infrastructure_accounts
2017/09/16 20:32:42 rendering 1 templates for operation my-api
2017/09/16 20:32:42 name field createInfrastructureAccount
2017/09/16 20:32:42 package field infrastructure_accounts
2017/09/16 20:32:42 creating "create_infrastructure_account_parameters.go" in "restapi/operations/infrastructure_accounts" as parameters
2017/09/16 20:32:42 rendering 1 templates for operation my-api
2017/09/16 20:32:42 name field getInfrastructureAccount
2017/09/16 20:32:42 package field infrastructure_accounts
2017/09/16 20:32:42 creating "get_infrastructure_account_parameters.go" in "restapi/operations/infrastructure_accounts" as parameters
2017/09/16 20:32:42 rendering 1 templates for operation my-api
2017/09/16 20:32:42 name field listInfrastructureAccounts
2017/09/16 20:32:42 package field infrastructure_accounts
2017/09/16 20:32:42 creating "list_infrastructure_accounts_parameters.go" in "restapi/operations/infrastructure_accounts" as parameters
2017/09/16 20:32:42 rendering 1 templates for operation my-api
2017/09/16 20:32:42 name field updateInfrastructureAccount
2017/09/16 20:32:42 package field infrastructure_accounts
2017/09/16 20:32:42 creating "update_infrastructure_account_parameters.go" in "restapi/operations/infrastructure_accounts" as parameters
2017/09/16 20:32:43 rendering 3 operations for node_pools
2017/09/16 20:32:43 rendering 1 templates for operation my-api
2017/09/16 20:32:43 name field createOrUpdateNodePool
2017/09/16 20:32:43 package field node_pools
2017/09/16 20:32:43 creating "create_or_update_node_pool_parameters.go" in "restapi/operations/node_pools" as parameters
2017/09/16 20:32:43 rendering 1 templates for operation my-api
2017/09/16 20:32:43 name field deleteNodePool
2017/09/16 20:32:43 package field node_pools
2017/09/16 20:32:43 creating "delete_node_pool_parameters.go" in "restapi/operations/node_pools" as parameters
2017/09/16 20:32:43 rendering 1 templates for operation my-api
2017/09/16 20:32:43 name field listNodePools
2017/09/16 20:32:43 package field node_pools
2017/09/16 20:32:43 creating "list_node_pools_parameters.go" in "restapi/operations/node_pools" as parameters
2017/09/16 20:32:43 rendering support
2017/09/16 20:32:43 rendering 3 templates for application My
2017/09/16 20:32:43 name field My
2017/09/16 20:32:43 package field operations
2017/09/16 20:32:43 creating "config.go" in "restapi" as configure
2017/09/16 20:32:43 name field My
2017/09/16 20:32:43 package field operations
2017/09/16 20:32:43 creating "embedded_spec.go" in "restapi" as embedded_spec
2017/09/16 20:32:43 name field My
2017/09/16 20:32:43 package field operations
2017/09/16 20:32:43 creating "api.go" in "restapi" as server
Generation completed!

For this generation to compile you need to have some packages in your GOPATH:

  * github.com/go-openapi/runtime
  * github.com/tylerb/graceful
  * github.com/jessevdk/go-flags

You can get these now with: go get -u -f ./...

It's even printing "I'm the new one" to prove that is the new one. The content is not right. Let's not worry too much now, we can have a look later. Enjoy the weekend!

Raffo commented

It worked after updating go-swagger with go get -u github.com/go-swagger/go-swagger/cmd/swagger and rebuilding gin-swagger. I'm still not sure gin-swagger is to trust, but now it works, closing.