Я столкнулся с ошибкой "импортный цикл не разрешен" в go -swagger автоматически сгенерированном файле, ниже приведен код. Я также прочитал другие ответы, связанные с этой проблемой, но безуспешно. Если требуется какая-либо другая информация, пожалуйста, оставьте комментарий.
Заранее спасибо
items_swagger.yaml
---
swagger: "2.0"
info:
description: Item list swagger for performing various op like create , delete , update.
title: ItemList
version: 1.0.0
consumes:
- application/json
produces:
- application/json
schemes:
- http
paths:
/createItem:
post:
tags:
- createItem
operationId: createOne
parameters:
- name: body
in: body
schema:
$ref: '#/definitions/item'
responses:
200:
description: Created
schema:
$ref: '#/definitions/item'
default:
description:
error
schema:
$ref: "#/definitions/error"
/updateItem:
put:
tags:
- updateItem
operationId: updateone
parameters:
- name: body
in: body
schema:
$ref: "#/definitions/item"
responses:
200:
description: OK
schema:
$ref: "#/definitions/item"
default:
description: error
schema:
$ref: "#/definitions/error"
/deleteItems:
delete:
tags:
- deleteItem
operationId: purgeItems
responses:
204:
description: Deleted
default:
description: error
schema:
$ref: "#/definitions/error"
definitions:
item:
type: object
required:
- id
- itemName
properties:
id:
type: integer
format: int64
readOnly: false
itemName:
type: string
format: string
readOnly: false
error:
type: object
required:
- message
- code
properties:
code:
type: integer
format: int
message:
type: string
Когда я генерирую его модель, она генерируется успешно.
beast@beast-VirtualBox:~/Documents/WorkSpace_Go/ItemsSwagger/src$ swagger generate server -A ItemsSwagger -f ../swagger/items-swagger.yml -t generate
2020/04/14 20:25:19 validating spec /home/beast/Documents/WorkSpace_Go/ItemsSwagger/swagger/items-swagger.yml
2020/04/14 20:25:21 preprocessing spec with option: minimal flattening
2020/04/14 20:25:21 building a plan for generation
2020/04/14 20:25:21 generation target generate
2020/04/14 20:25:21 planning definitions
2020/04/14 20:25:21 planning operations
2020/04/14 20:25:21 grouping operations into packages
2020/04/14 20:25:21 planning meta data and facades
2020/04/14 20:25:21 rendering 2 models
2020/04/14 20:25:21 rendering 1 templates for model error
2020/04/14 20:25:21 name field error
2020/04/14 20:25:21 package field models
2020/04/14 20:25:21 creating generated file "error.go" in "generate/models" as definition
2020/04/14 20:25:21 executed template asset:model
2020/04/14 20:25:21 rendering 1 templates for model item
2020/04/14 20:25:21 name field item
2020/04/14 20:25:21 package field models
2020/04/14 20:25:21 creating generated file "item.go" in "generate/models" as definition
2020/04/14 20:25:21 executed template asset:model
2020/04/14 20:25:21 rendering 3 operation groups (tags)
2020/04/14 20:25:21 rendering 1 operations for create_item
2020/04/14 20:25:21 rendering 4 templates for operation ItemsSwagger
2020/04/14 20:25:21 name field createOne
2020/04/14 20:25:21 package field create_item
2020/04/14 20:25:21 creating generated file "create_one_parameters.go" in "generate/restapi/operations/create_item" as parameters
2020/04/14 20:25:21 executed template asset:serverParameter
2020/04/14 20:25:21 name field createOne
2020/04/14 20:25:21 package field create_item
2020/04/14 20:25:21 creating generated file "create_one_urlbuilder.go" in "generate/restapi/operations/create_item" as urlbuilder
2020/04/14 20:25:21 executed template asset:serverUrlbuilder
2020/04/14 20:25:21 name field createOne
2020/04/14 20:25:21 package field create_item
2020/04/14 20:25:21 creating generated file "create_one_responses.go" in "generate/restapi/operations/create_item" as responses
2020/04/14 20:25:21 executed template asset:serverResponses
2020/04/14 20:25:21 name field createOne
2020/04/14 20:25:21 package field create_item
2020/04/14 20:25:21 creating generated file "create_one.go" in "generate/restapi/operations/create_item" as handler
2020/04/14 20:25:21 executed template asset:serverOperation
2020/04/14 20:25:21 rendering 0 templates for operation group ItemsSwagger
2020/04/14 20:25:21 rendering 1 operations for delete_item
2020/04/14 20:25:21 rendering 4 templates for operation ItemsSwagger
2020/04/14 20:25:21 name field purgeItems
2020/04/14 20:25:21 package field delete_item
2020/04/14 20:25:21 creating generated file "purge_items_parameters.go" in "generate/restapi/operations/delete_item" as parameters
2020/04/14 20:25:21 executed template asset:serverParameter
2020/04/14 20:25:21 name field purgeItems
2020/04/14 20:25:21 package field delete_item
2020/04/14 20:25:21 creating generated file "purge_items_urlbuilder.go" in "generate/restapi/operations/delete_item" as urlbuilder
2020/04/14 20:25:21 executed template asset:serverUrlbuilder
2020/04/14 20:25:21 name field purgeItems
2020/04/14 20:25:21 package field delete_item
2020/04/14 20:25:21 creating generated file "purge_items_responses.go" in "generate/restapi/operations/delete_item" as responses
2020/04/14 20:25:21 executed template asset:serverResponses
2020/04/14 20:25:21 name field purgeItems
2020/04/14 20:25:21 package field delete_item
2020/04/14 20:25:21 creating generated file "purge_items.go" in "generate/restapi/operations/delete_item" as handler
2020/04/14 20:25:21 executed template asset:serverOperation
2020/04/14 20:25:21 rendering 0 templates for operation group ItemsSwagger
2020/04/14 20:25:21 rendering 1 operations for update_item
2020/04/14 20:25:21 rendering 4 templates for operation ItemsSwagger
2020/04/14 20:25:21 name field updateone
2020/04/14 20:25:21 package field update_item
2020/04/14 20:25:21 creating generated file "updateone_parameters.go" in "generate/restapi/operations/update_item" as parameters
2020/04/14 20:25:21 executed template asset:serverParameter
2020/04/14 20:25:21 name field updateone
2020/04/14 20:25:21 package field update_item
2020/04/14 20:25:21 creating generated file "updateone_urlbuilder.go" in "generate/restapi/operations/update_item" as urlbuilder
2020/04/14 20:25:21 executed template asset:serverUrlbuilder
2020/04/14 20:25:21 name field updateone
2020/04/14 20:25:21 package field update_item
2020/04/14 20:25:21 creating generated file "updateone_responses.go" in "generate/restapi/operations/update_item" as responses
2020/04/14 20:25:21 executed template asset:serverResponses
2020/04/14 20:25:21 name field updateone
2020/04/14 20:25:21 package field update_item
2020/04/14 20:25:21 creating generated file "updateone.go" in "generate/restapi/operations/update_item" as handler
2020/04/14 20:25:21 executed template asset:serverOperation
2020/04/14 20:25:21 rendering 0 templates for operation group ItemsSwagger
2020/04/14 20:25:21 rendering support
2020/04/14 20:25:21 rendering 6 templates for application ItemsSwagger
2020/04/14 20:25:21 name field ItemsSwagger
2020/04/14 20:25:21 package field operations
2020/04/14 20:25:21 name field ItemsSwagger
2020/04/14 20:25:21 package field operations
2020/04/14 20:25:21 creating generated file "main.go" in "generate/cmd/items-swagger-server" as main
2020/04/14 20:25:21 executed template asset:serverMain
2020/04/14 20:25:21 name field ItemsSwagger
2020/04/14 20:25:21 package field operations
2020/04/14 20:25:21 creating generated file "embedded_spec.go" in "generate/restapi" as embedded_spec
2020/04/14 20:25:21 executed template asset:swaggerJsonEmbed
2020/04/14 20:25:21 name field ItemsSwagger
2020/04/14 20:25:21 package field operations
2020/04/14 20:25:21 creating generated file "server.go" in "generate/restapi" as server
2020/04/14 20:25:21 executed template asset:serverServer
2020/04/14 20:25:21 name field ItemsSwagger
2020/04/14 20:25:21 package field operations
2020/04/14 20:25:21 creating generated file "items_swagger_api.go" in "generate/restapi/operations" as builder
2020/04/14 20:25:21 executed template asset:serverBuilder
2020/04/14 20:25:21 name field ItemsSwagger
2020/04/14 20:25:21 package field operations
2020/04/14 20:25:21 creating generated file "doc.go" in "generate/restapi" as doc
2020/04/14 20:25:21 executed template asset:serverDoc
2020/04/14 20:25:21 Generation completed!
For this generation to compile you need to have some packages in your GOPATH:
* github.com/go-openapi/runtime
* github.com/jessevdk/go-flags
You can get these now with: go get -u -f generate/...
Здесь происходит ошибка, когда я пытаюсь запустить сервер.
beast@beast-VirtualBox:~/Documents/WorkSpace_Go/ItemsSwagger/src$ go run generate/cmd/items-swagger-server/main.go
import cycle not allowed
package main
imports generate/restapi
imports context
imports errors
imports internal/reflectlite
imports runtime
imports internal/cpu
imports runtime
beast@beast-VirtualBox:~/Documents/WorkSpace_Go/ItemsSwagger/src$
go env output
beast@beast-VirtualBox:~/Documents/WorkSpace_Go/ItemsSwagger/src$ go env
GOARCH="amd64"
GOBIN="/home/beast/Documents/WorkSpace_Go/ItemsSwagger/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/beast/Documents/WorkSpace_Go/ItemsSwagger/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
Редактировать 1: Спасибо, Volker. Мне удалось устранить ошибку "import cycli c", переустановив go, возник конфликт, вызванный go_1. 6 и версия go_1.9.
Я снова выполнил команду "go run", но безуспешно.
beast@beast-VirtualBox:~/Documents/WorkSpace_Go/ItemsSwagger/src$ go run generate/cmd/items-swagger-server/main.go
# github.com/go-openapi/validate
github.com/go-openapi/validate/spec.go:46:16: undefined: loads.Document
github.com/go-openapi/validate/spec.go:57:16: undefined: loads.Document
github.com/go-openapi/validate/spec.go:59:16: undefined: loads.Document
github.com/go-openapi/validate/spec.go:75:10: undefined: loads.Document
github.com/go-openapi/validate/spec.go:78:21: undefined: loads.Document
# github.com/go-openapi/runtime/middleware/untyped
github.com/go-openapi/runtime/middleware/untyped/api.go:33:19: undefined: loads.Document
github.com/go-openapi/runtime/middleware/untyped/api.go:54:19: undefined: loads.Document
beast@beast-VirtualBox:~/Documents/WorkSpace_Go/ItemsSwagger/src$
Я искал в отношении ошибки только полезную ссылку, которую я нашел здесь . Я также попытался создать файлы swagger fre sh, удалив старые.
Любые предложения будут полезны.