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
couldn't find a swagger spec #2580
Comments
Same problem |
Is |
@youyuanwu yes, correct. |
Cannot reproduce bash:~/temp$ ls
swagger.yml
bash:~/temp$ cat swagger.yml
swagger: "2.0"
info:
description: From the todo list tutorial on goswagger.io
title: A Todo list application
version: 1.0.0
consumes:
- application/io.goswagger.examples.todo-list.v1+json
produces:
- application/io.goswagger.examples.todo-list.v1+json
schemes:
- http
paths:
/:
get:
tags:
- todos
parameters:
- name: since
in: query
type: integer
format: int64
- name: limit
in: query
type: integer
format: int32
default: 20
responses:
200:
description: list the todo operations
schema:
type: array
items:
$ref: "#/definitions/item"
default:
description: generic error response
schema:
$ref: "#/definitions/error"
definitions:
item:
type: object
required:
- description
properties:
id:
type: integer
format: int64
readOnly: true
description:
type: string
minLength: 1
completed:
type: boolean
error:
type: object
required:
- message
properties:
code:
type: integer
format: int64
message:
type: string
bash:~/temp$ swagger generate server -f swagger.yml
2021/06/02 00:13:02 validating spec /home/user1/temp/swagger.yml
2021/06/02 00:13:02 preprocessing spec with option: minimal flattening
2021/06/02 00:13:02 building a plan for generation
2021/06/02 00:13:02 generation target ./
2021/06/02 00:13:02 target must reside inside a location in the $GOPATH/src or be a module |
Following these steps:
|
Seems like the error is from here: Line 144 in 43c2774
Not sure how the spec file name is not picked up. Can you try run |
I get the same result. |
is this in or out of the go path, does the project have a go.mod file if it isn't? |
$ cd $(mktemp -d)
/tmp/tmp.4HoE96p3Rl $ swagger generate server -f ./swagger.yaml
2021/06/05 12:54:48 validating spec /tmp/tmp.4HoE96p3Rl/swagger.yaml
2021/06/05 12:54:49 preprocessing spec with option: minimal flattening
2021/06/05 12:54:49 building a plan for generation
2021/06/05 12:54:49 generation target ./
2021/06/05 12:54:49 target must reside inside a location in the $GOPATH/src or be a module
/tmp/tmp.4HoE96p3Rl $ swagger generate server -f swagger.yaml
2021/06/05 12:54:55 validating spec /tmp/tmp.4HoE96p3Rl/swagger.yaml
2021/06/05 12:54:56 preprocessing spec with option: minimal flattening
2021/06/05 12:54:56 building a plan for generation
2021/06/05 12:54:56 generation target ./
2021/06/05 12:54:56 target must reside inside a location in the $GOPATH/src or be a module
/tmp/tmp.4HoE96p3Rl $ go mod init goswagger.io/example/todo-list
go: creating new go.mod: module goswagger.io/example/todo-list
/tmp/tmp.4HoE96p3Rl $ swagger generate server -f swagger.yaml
2021/06/05 12:55:16 validating spec /tmp/tmp.4HoE96p3Rl/swagger.yaml
2021/06/05 12:55:16 preprocessing spec with option: minimal flattening
2021/06/05 12:55:16 building a plan for generation
2021/06/05 12:55:16 generation target ./
2021/06/05 12:55:16 planning definitions (found: 2)
2021/06/05 12:55:16 planning operations (found: 1)
2021/06/05 12:55:16 grouping operations into packages (packages: 1)
2021/06/05 12:55:16 operations for package packages "todos" (found: 1)
2021/06/05 12:55:16 planning meta data and facades
2021/06/05 12:55:16 rendering 2 models
2021/06/05 12:55:16 rendering 1 templates for model error
2021/06/05 12:55:16 name field error
2021/06/05 12:55:16 package field models
2021/06/05 12:55:16 creating generated file "error.go" in "models" as definition
2021/06/05 12:55:16 executed template asset:model
2021/06/05 12:55:16 rendering 1 templates for model item
2021/06/05 12:55:16 name field item
2021/06/05 12:55:16 package field models
2021/06/05 12:55:16 creating generated file "item.go" in "models" as definition
2021/06/05 12:55:16 executed template asset:model
2021/06/05 12:55:16 rendering 1 operation groups (tags)
2021/06/05 12:55:16 rendering 1 operations for todos
2021/06/05 12:55:16 rendering 4 templates for operation ATodoListApplication
2021/06/05 12:55:16 name field Get
2021/06/05 12:55:16 package field todos
2021/06/05 12:55:16 creating generated file "get_parameters.go" in "restapi/operations/todos" as parameters
2021/06/05 12:55:16 executed template asset:serverParameter
2021/06/05 12:55:16 name field Get
2021/06/05 12:55:16 package field todos
2021/06/05 12:55:16 creating generated file "get_urlbuilder.go" in "restapi/operations/todos" as urlbuilder
2021/06/05 12:55:16 executed template asset:serverUrlbuilder
2021/06/05 12:55:16 name field Get
2021/06/05 12:55:16 package field todos
2021/06/05 12:55:16 creating generated file "get_responses.go" in "restapi/operations/todos" as responses
2021/06/05 12:55:16 executed template asset:serverResponses
2021/06/05 12:55:16 name field Get
2021/06/05 12:55:16 package field todos
2021/06/05 12:55:16 creating generated file "get.go" in "restapi/operations/todos" as handler
2021/06/05 12:55:16 executed template asset:serverOperation
2021/06/05 12:55:16 rendering 0 templates for operation group ATodoListApplication
2021/06/05 12:55:16 rendering support
2021/06/05 12:55:16 rendering 6 templates for application ATodoListApplication
2021/06/05 12:55:16 name field ATodoListApplication
2021/06/05 12:55:16 package field operations
2021/06/05 12:55:16 creating generated file "main.go" in "cmd/a-todo-list-application-server" as main
2021/06/05 12:55:16 executed template asset:serverMain
2021/06/05 12:55:16 name field ATodoListApplication
2021/06/05 12:55:16 package field operations
2021/06/05 12:55:16 creating generated file "embedded_spec.go" in "restapi" as embedded_spec
2021/06/05 12:55:16 executed template asset:swaggerJsonEmbed
2021/06/05 12:55:16 name field ATodoListApplication
2021/06/05 12:55:16 package field operations
2021/06/05 12:55:16 creating generated file "server.go" in "restapi" as server
2021/06/05 12:55:16 executed template asset:serverServer
2021/06/05 12:55:16 name field ATodoListApplication
2021/06/05 12:55:16 package field operations
2021/06/05 12:55:16 creating generated file "a_todo_list_application_api.go" in "restapi/operations" as builder
2021/06/05 12:55:16 executed template asset:serverBuilder
2021/06/05 12:55:16 name field ATodoListApplication
2021/06/05 12:55:16 package field operations
2021/06/05 12:55:16 creating generated file "doc.go" in "restapi" as doc
2021/06/05 12:55:16 executed template asset:serverDoc
2021/06/05 12:55:16 name field ATodoListApplication
2021/06/05 12:55:16 package field operations
2021/06/05 12:55:16 creating generated file "configure_a_todo_list_application.go" in "restapi" as configure
2021/06/05 12:55:16 executed template asset:serverConfigureapi
2021/06/05 12:55:16 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 ./... |
I did setup go modules, but didn't work out:
|
Is ther filename "swagger.yml" or "swagger.yaml"? |
Sorry that I was using the wrong file name, but even after the correct extension, I don't see a difference:
|
I suggest you try generate under home directory, or try on another machine. It is unclear why swagger cannot read the file. |
Unfortunately the same outcome is there in the home directory:
|
I have the same error
|
Hi @santosh, I feel like this might have something to do with running You could try using the static binary https://goswagger.io/install.html#static-binary and see if it resolves the issue. |
i think the init path is not right swagger validate ./swagger/swagger.yml open ./swagger/swagger.yml: no such file or directory |
try with:
|
looks like |
I'm closing this issue as I'm able to run the same command without any issue in an environment different than Amazon Linux 2. I was able to run this on below environment:
|
Problem statement
Getting
couldn't find a swagger spec
when doingswagger generate server -A todo-list -f ./swagger.yml
.I am following https://goswagger.io/tutorial/todo-list.html.
Steps to reproduce
swagger.yml
.swagger generate server -A todo-list -f ./swagger.yml
from the directory of the file.Environment
swagger version: version: v0.27.0
go version: go1.15.8
OS: Amazon Linux 2
The text was updated successfully, but these errors were encountered: