Skip to content

Code generation fails when swagger is built with go1.13 #2058

@mikkeloscar

Description

@mikkeloscar

Problem statement

Code generation panics when swagger is built from go1.13 but works fine if built from go1.12.9

Swagger specification

https://github.com/zalando-incubator/cluster-lifecycle-manager/blob/master/docs/cluster-registry.yaml

Steps to reproduce

go1.13 install github.com/go-swagger/go-swagger/cmd/swagger
swagger generate client --name cluster-registry --principal oauth.User --spec docs/cluster-registry.yaml --target ./pkg/cluster-registry
2019/09/06 15:34:40 validating spec docs/cluster-registry.yaml
panic: Invalid schema provided to SchemaValidator: object has no key "default"

goroutine 1 [running]:
github.com/go-openapi/validate.NewSchemaValidator(0xc0001d8240, 0xd0b0e0, 0xc0001d8240, 0x0, 0x0, 0xeac980, 0xc0003b7740, 0x0, 0x0, 0x0, ...)
	/home/moscar/projects/go/pkg/mod/github.com/go-openapi/[email protected]/schema.go:72 +0x1039
github.com/go-openapi/validate.(*SpecValidator).Validate(0xc000a17cc0, 0xcbe3a0, 0xc0000f0000, 0xc0008c18c0, 0xc0008c1970)
	/home/moscar/projects/go/pkg/mod/github.com/go-openapi/[email protected]/spec.go:92 +0x216
github.com/go-openapi/validate.Spec(0xc0000f0000, 0xeac980, 0xc0003b7740, 0x14, 0xbf54b5fc10269115)
	/home/moscar/projects/go/pkg/mod/github.com/go-openapi/[email protected]/spec.go:47 +0xad
github.com/go-swagger/go-swagger/generator.validateSpec(0x7fff3addf7d7, 0x1a, 0xc0000f0000, 0x1, 0x1)
	/home/moscar/projects/go/pkg/mod/github.com/go-swagger/[email protected]/generator/shared.go:939 +0x89
github.com/go-swagger/go-swagger/generator.validateAndFlattenSpec(0xc000110200, 0xc0000f0000, 0x7fff3addf7d7, 0x1a, 0xc0000f0000)
	/home/moscar/projects/go/pkg/mod/github.com/go-swagger/[email protected]/generator/shared.go:1135 +0x42e
github.com/go-swagger/go-swagger/generator.GenerateClient(0x7fff3addf7a8, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000110200, 0xcc8760, ...)
	/home/moscar/projects/go/pkg/mod/github.com/go-swagger/[email protected]/generator/client.go:61 +0xe9
github.com/go-swagger/go-swagger/cmd/swagger/commands/generate.(*Client).generate(0xc00008b980, 0xc000110200, 0x0, 0x0)
	/home/moscar/projects/go/pkg/mod/github.com/go-swagger/[email protected]/cmd/swagger/commands/generate/client.go:72 +0x94
github.com/go-swagger/go-swagger/cmd/swagger/commands/generate.createSwagger(0xeaadc0, 0xc00008b980, 0x8b3e01, 0x7f2581c88900)
	/home/moscar/projects/go/pkg/mod/github.com/go-swagger/[email protected]/cmd/swagger/commands/generate/shared.go:157 +0x1b2
github.com/go-swagger/go-swagger/cmd/swagger/commands/generate.(*Client).Execute(0xc00008b980, 0xc0001e1680, 0x0, 0xa, 0xc00008b980, 0x1)
	/home/moscar/projects/go/pkg/mod/github.com/go-swagger/[email protected]/cmd/swagger/commands/generate/client.go:91 +0x37
github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc00006f260, 0xc0000b6010, 0xa, 0xa, 0x0, 0xd5a73b, 0x2a, 0xbd7ca0, 0xc0002d4150)
	/home/moscar/projects/go/pkg/mod/github.com/jessevdk/[email protected]/parser.go:316 +0x8dc
github.com/jessevdk/go-flags.(*Parser).Parse(...)
	/home/moscar/projects/go/pkg/mod/github.com/jessevdk/[email protected]/parser.go:186
main.main()
	/home/moscar/projects/go/pkg/mod/github.com/go-swagger/[email protected]/cmd/swagger/swagger.go:145 +0xc2c
make: *** [Makefile:55: pkg/cluster-registry] Error 2

If I do the same with go-swagger built from go1.12.9 then the code generation doesn't fail:

go1.12.9 install github.com/go-swagger/go-swagger/cmd/swagger
swagger generate client --name cluster-registry --principal oauth.User --spec docs/cluster-registry.yaml --target ./pkg/cluster-registry
2019/09/06 15:39:15 validating spec docs/cluster-registry.yaml
2019/09/06 15:39:16 preprocessing spec with option:  minimal flattening
2019/09/06 15:39:16 building a plan for generation
2019/09/06 15:39:16 planning definitions
2019/09/06 15:39:17 planning operations
2019/09/06 15:39:17 grouping operations into packages
2019/09/06 15:39:17 planning meta data and facades
2019/09/06 15:39:17 rendering 1 templates for model Cluster
2019/09/06 15:39:17 name field Cluster
2019/09/06 15:39:17 package field models
2019/09/06 15:39:17 creating generated file "cluster.go" in "pkg/cluster-registry/models" as definition
2019/09/06 15:39:17 executed template asset:model
2019/09/06 15:39:17 rendering 1 templates for model ClusterStatus
2019/09/06 15:39:17 name field ClusterStatus
2019/09/06 15:39:17 package field models
2019/09/06 15:39:17 creating generated file "cluster_status.go" in "pkg/cluster-registry/models" as definition
2019/09/06 15:39:17 executed template asset:model
2019/09/06 15:39:17 rendering 1 templates for model ClusterUpdate
2019/09/06 15:39:17 name field ClusterUpdate
2019/09/06 15:39:17 package field models
2019/09/06 15:39:17 creating generated file "cluster_update.go" in "pkg/cluster-registry/models" as definition
2019/09/06 15:39:17 executed template asset:model
2019/09/06 15:39:17 rendering 1 templates for model ConfigValue
2019/09/06 15:39:17 name field ConfigValue
2019/09/06 15:39:17 package field models
2019/09/06 15:39:17 creating generated file "config_value.go" in "pkg/cluster-registry/models" as definition
2019/09/06 15:39:17 executed template asset:model
2019/09/06 15:39:17 rendering 1 templates for model Error
2019/09/06 15:39:17 name field Error
2019/09/06 15:39:17 package field models
2019/09/06 15:39:17 creating generated file "error.go" in "pkg/cluster-registry/models" as definition
2019/09/06 15:39:17 executed template asset:model
2019/09/06 15:39:17 rendering 1 templates for model InfrastructureAccount
2019/09/06 15:39:17 name field InfrastructureAccount
2019/09/06 15:39:17 package field models
2019/09/06 15:39:17 creating generated file "infrastructure_account.go" in "pkg/cluster-registry/models" as definition
2019/09/06 15:39:17 executed template asset:model
2019/09/06 15:39:17 rendering 1 templates for model InfrastructureAccountUpdate
2019/09/06 15:39:17 name field InfrastructureAccountUpdate
2019/09/06 15:39:17 package field models
2019/09/06 15:39:17 creating generated file "infrastructure_account_update.go" in "pkg/cluster-registry/models" as definition
2019/09/06 15:39:17 executed template asset:model
2019/09/06 15:39:17 rendering 1 templates for model NodePool
2019/09/06 15:39:17 name field NodePool
2019/09/06 15:39:17 package field models
2019/09/06 15:39:17 creating generated file "node_pool.go" in "pkg/cluster-registry/models" as definition
2019/09/06 15:39:17 executed template asset:model
2019/09/06 15:39:17 rendering 1 templates for model NodePoolUpdate
2019/09/06 15:39:17 name field NodePoolUpdate
2019/09/06 15:39:17 package field models
2019/09/06 15:39:17 creating generated file "node_pool_update.go" in "pkg/cluster-registry/models" as definition
2019/09/06 15:39:17 executed template asset:model
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field createCluster
2019/09/06 15:39:17 package field clusters
2019/09/06 15:39:17 creating generated file "create_cluster_parameters.go" in "pkg/cluster-registry/client/clusters" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field createCluster
2019/09/06 15:39:17 package field clusters
2019/09/06 15:39:17 creating generated file "create_cluster_responses.go" in "pkg/cluster-registry/client/clusters" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field deleteCluster
2019/09/06 15:39:17 package field clusters
2019/09/06 15:39:17 creating generated file "delete_cluster_parameters.go" in "pkg/cluster-registry/client/clusters" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field deleteCluster
2019/09/06 15:39:17 package field clusters
2019/09/06 15:39:17 creating generated file "delete_cluster_responses.go" in "pkg/cluster-registry/client/clusters" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field getCluster
2019/09/06 15:39:17 package field clusters
2019/09/06 15:39:17 creating generated file "get_cluster_parameters.go" in "pkg/cluster-registry/client/clusters" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field getCluster
2019/09/06 15:39:17 package field clusters
2019/09/06 15:39:17 creating generated file "get_cluster_responses.go" in "pkg/cluster-registry/client/clusters" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field listClusters
2019/09/06 15:39:17 package field clusters
2019/09/06 15:39:17 creating generated file "list_clusters_parameters.go" in "pkg/cluster-registry/client/clusters" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field listClusters
2019/09/06 15:39:17 package field clusters
2019/09/06 15:39:17 creating generated file "list_clusters_responses.go" in "pkg/cluster-registry/client/clusters" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field updateCluster
2019/09/06 15:39:17 package field clusters
2019/09/06 15:39:17 creating generated file "update_cluster_parameters.go" in "pkg/cluster-registry/client/clusters" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field updateCluster
2019/09/06 15:39:17 package field clusters
2019/09/06 15:39:17 creating generated file "update_cluster_responses.go" in "pkg/cluster-registry/client/clusters" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 1 templates for operation group 
2019/09/06 15:39:17 name field clusters
2019/09/06 15:39:17 creating generated file "clusters_client.go" in "pkg/cluster-registry/client/clusters" as client
2019/09/06 15:39:17 executed template asset:clientClient
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field addOrUpdateConfigItem
2019/09/06 15:39:17 package field config_items
2019/09/06 15:39:17 creating generated file "add_or_update_config_item_parameters.go" in "pkg/cluster-registry/client/config_items" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field addOrUpdateConfigItem
2019/09/06 15:39:17 package field config_items
2019/09/06 15:39:17 creating generated file "add_or_update_config_item_responses.go" in "pkg/cluster-registry/client/config_items" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field deleteConfigItem
2019/09/06 15:39:17 package field config_items
2019/09/06 15:39:17 creating generated file "delete_config_item_parameters.go" in "pkg/cluster-registry/client/config_items" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field deleteConfigItem
2019/09/06 15:39:17 package field config_items
2019/09/06 15:39:17 creating generated file "delete_config_item_responses.go" in "pkg/cluster-registry/client/config_items" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 1 templates for operation group 
2019/09/06 15:39:17 name field config_items
2019/09/06 15:39:17 creating generated file "config_items_client.go" in "pkg/cluster-registry/client/config_items" as client
2019/09/06 15:39:17 executed template asset:clientClient
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field createInfrastructureAccount
2019/09/06 15:39:17 package field infrastructure_accounts
2019/09/06 15:39:17 creating generated file "create_infrastructure_account_parameters.go" in "pkg/cluster-registry/client/infrastructure_accounts" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field createInfrastructureAccount
2019/09/06 15:39:17 package field infrastructure_accounts
2019/09/06 15:39:17 creating generated file "create_infrastructure_account_responses.go" in "pkg/cluster-registry/client/infrastructure_accounts" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field getInfrastructureAccount
2019/09/06 15:39:17 package field infrastructure_accounts
2019/09/06 15:39:17 creating generated file "get_infrastructure_account_parameters.go" in "pkg/cluster-registry/client/infrastructure_accounts" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field getInfrastructureAccount
2019/09/06 15:39:17 package field infrastructure_accounts
2019/09/06 15:39:17 creating generated file "get_infrastructure_account_responses.go" in "pkg/cluster-registry/client/infrastructure_accounts" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field listInfrastructureAccounts
2019/09/06 15:39:17 package field infrastructure_accounts
2019/09/06 15:39:17 creating generated file "list_infrastructure_accounts_parameters.go" in "pkg/cluster-registry/client/infrastructure_accounts" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field listInfrastructureAccounts
2019/09/06 15:39:17 package field infrastructure_accounts
2019/09/06 15:39:17 creating generated file "list_infrastructure_accounts_responses.go" in "pkg/cluster-registry/client/infrastructure_accounts" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field updateInfrastructureAccount
2019/09/06 15:39:17 package field infrastructure_accounts
2019/09/06 15:39:17 creating generated file "update_infrastructure_account_parameters.go" in "pkg/cluster-registry/client/infrastructure_accounts" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field updateInfrastructureAccount
2019/09/06 15:39:17 package field infrastructure_accounts
2019/09/06 15:39:17 creating generated file "update_infrastructure_account_responses.go" in "pkg/cluster-registry/client/infrastructure_accounts" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 1 templates for operation group 
2019/09/06 15:39:17 name field infrastructure_accounts
2019/09/06 15:39:17 creating generated file "infrastructure_accounts_client.go" in "pkg/cluster-registry/client/infrastructure_accounts" as client
2019/09/06 15:39:17 executed template asset:clientClient
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field addOrUpdateNodePoolConfigItem
2019/09/06 15:39:17 package field node_pool_config_items
2019/09/06 15:39:17 creating generated file "add_or_update_node_pool_config_item_parameters.go" in "pkg/cluster-registry/client/node_pool_config_items" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field addOrUpdateNodePoolConfigItem
2019/09/06 15:39:17 package field node_pool_config_items
2019/09/06 15:39:17 creating generated file "add_or_update_node_pool_config_item_responses.go" in "pkg/cluster-registry/client/node_pool_config_items" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field deleteNodePoolConfigItem
2019/09/06 15:39:17 package field node_pool_config_items
2019/09/06 15:39:17 creating generated file "delete_node_pool_config_item_parameters.go" in "pkg/cluster-registry/client/node_pool_config_items" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field deleteNodePoolConfigItem
2019/09/06 15:39:17 package field node_pool_config_items
2019/09/06 15:39:17 creating generated file "delete_node_pool_config_item_responses.go" in "pkg/cluster-registry/client/node_pool_config_items" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 1 templates for operation group 
2019/09/06 15:39:17 name field node_pool_config_items
2019/09/06 15:39:17 creating generated file "node_pool_config_items_client.go" in "pkg/cluster-registry/client/node_pool_config_items" as client
2019/09/06 15:39:17 executed template asset:clientClient
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field createOrUpdateNodePool
2019/09/06 15:39:17 package field node_pools
2019/09/06 15:39:17 creating generated file "create_or_update_node_pool_parameters.go" in "pkg/cluster-registry/client/node_pools" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field createOrUpdateNodePool
2019/09/06 15:39:17 package field node_pools
2019/09/06 15:39:17 creating generated file "create_or_update_node_pool_responses.go" in "pkg/cluster-registry/client/node_pools" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field deleteNodePool
2019/09/06 15:39:17 package field node_pools
2019/09/06 15:39:17 creating generated file "delete_node_pool_parameters.go" in "pkg/cluster-registry/client/node_pools" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field deleteNodePool
2019/09/06 15:39:17 package field node_pools
2019/09/06 15:39:17 creating generated file "delete_node_pool_responses.go" in "pkg/cluster-registry/client/node_pools" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field listNodePools
2019/09/06 15:39:17 package field node_pools
2019/09/06 15:39:17 creating generated file "list_node_pools_parameters.go" in "pkg/cluster-registry/client/node_pools" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field listNodePools
2019/09/06 15:39:17 package field node_pools
2019/09/06 15:39:17 creating generated file "list_node_pools_responses.go" in "pkg/cluster-registry/client/node_pools" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 2 templates for operation 
2019/09/06 15:39:17 name field updateNodePool
2019/09/06 15:39:17 package field node_pools
2019/09/06 15:39:17 creating generated file "update_node_pool_parameters.go" in "pkg/cluster-registry/client/node_pools" as parameters
2019/09/06 15:39:17 executed template asset:clientParameter
2019/09/06 15:39:17 name field updateNodePool
2019/09/06 15:39:17 package field node_pools
2019/09/06 15:39:17 creating generated file "update_node_pool_responses.go" in "pkg/cluster-registry/client/node_pools" as responses
2019/09/06 15:39:17 executed template asset:clientResponse
2019/09/06 15:39:17 rendering 1 templates for operation group 
2019/09/06 15:39:17 name field node_pools
2019/09/06 15:39:17 creating generated file "node_pools_client.go" in "pkg/cluster-registry/client/node_pools" as client
2019/09/06 15:39:17 executed template asset:clientClient
2019/09/06 15:39:17 rendering 1 templates for application ClusterRegistry
2019/09/06 15:39:17 name field ClusterRegistry
2019/09/06 15:39:17 package field client
2019/09/06 15:39:17 creating generated file "cluster_registry_client.go" in "pkg/cluster-registry/client" as facade
2019/09/06 15:39:17 executed template asset:clientFacade
2019/09/06 15:39:17 Generation completed!

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

	* github.com/go-openapi/errors
	* github.com/go-openapi/runtime
	* github.com/go-openapi/runtime/client
	* github.com/go-openapi/strfmt

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

Ref: mikkeloscar/gin-swagger#38

Environment

swagger version: v0.20.1
go version: 1.13
OS: Linux Z 5.2.11-arch1-1-ARCH #1 SMP PREEMPT Thu Aug 29 08:09:36 UTC 2019 x86_64 GNU/Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions