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

Are external references supported? #1774

Closed
ok11 opened this issue Oct 25, 2018 · 4 comments · Fixed by #1799
Closed

Are external references supported? #1774

ok11 opened this issue Oct 25, 2018 · 4 comments · Fixed by #1799

Comments

@ok11
Copy link

ok11 commented Oct 25, 2018

It may have some relation to #1767, but since the diagnostic is a bit different, I opened a new issue.

Problem statement

When one tries to use $ref, pointing to another file (residing locally) as shown in the gist (everything is in a def directory, api.yaml, Data.yaml, ...), go-openapi calls a panic at runtime:

ok11@home:~/workspace/bb-go/userservice/cmd/service$ go run main.go
panic: Invalid schema provided to SchemaValidator: open /home/ok11/workspace/bb-go/userservice/cmd/service/Data.yaml: no such file or directory

goroutine 1 [running]:
github.com/go-openapi/validate.NewSchemaValidator(0xc0001a6d80, 0x8cbe40, 0xc0001d0100, 0xc000311b68, 0x7, 0x9d6b00, 0xc0001f8db0, 0xc000313e00)
        /home/ok11/workspace/go/pkg/mod/github.com/go-openapi/validate@v0.17.0/schema.go:71 +0xf42
github.com/go-openapi/runtime/middleware.newUntypedParamBinder(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/ok11/workspace/go/pkg/mod/github.com/go-openapi/runtime@v0.17.0/middleware/parameter.go:46 +0x18c
github.com/go-openapi/runtime/middleware.newUntypedRequestBinder(0xc000313e00, 0xc0001d0100, 0x9d6b00, 0xc0001f8db0, 0xc0001cc060)
        /home/ok11/workspace/go/pkg/mod/github.com/go-openapi/runtime@v0.17.0/middleware/request.go:39 +0x196
github.com/go-openapi/runtime/middleware.(*defaultRouteBuilder).AddRoute(0xc000313da0, 0x935b9a, 0x3, 0xc000556bc0, 0x20, 0xc0001a4380)
        /home/ok11/workspace/go/pkg/mod/github.com/go-openapi/runtime@v0.17.0/middleware/router.go:432 +0x4cc
github.com/go-openapi/runtime/middleware.DefaultRouter(0xc0000ca140, 0x9d7880, 0xc00009e580, 0x8c8360, 0xc000168970)
        /home/ok11/workspace/go/pkg/mod/github.com/go-openapi/runtime@v0.17.0/middleware/router.go:139 +0x14c
github.com/go-openapi/runtime/middleware.NewRouter(0xc000313830, 0x9d1a20, 0xc000168970, 0xc000168970, 0xc000518340)
        /home/ok11/workspace/go/pkg/mod/github.com/go-openapi/runtime@v0.17.0/middleware/router.go:71 +0xe2
github.com/go-openapi/runtime/middleware.(*Context).RoutesHandler(0xc000313830, 0x964488, 0xc000518320, 0xc0000ca320)
        /home/ok11/workspace/go/pkg/mod/github.com/go-openapi/runtime@v0.17.0/middleware/context.go:581 +0x7c
github.com/go-openapi/runtime/middleware.(*Context).APIHandler(0xc000313830, 0x0, 0xc000313201, 0xc0000ca410)
        /home/ok11/workspace/go/pkg/mod/github.com/go-openapi/runtime@v0.17.0/middleware/context.go:572 +0xfa
github.wdf.sap.corp/bb-go/userservice/pkg/api/rest/gen/restapi/operations.(*UserServiceAPI).Serve(0xc00009e580, 0x0, 0x27e5, 0x0)
        /home/ok11/workspace/bb-go/userservice/pkg/api/rest/gen/restapi/operations/user_service_api.go:389 +0x80
github.wdf.sap.corp/bb-go/userservice/pkg/api/rest/gen/restapi.Handler(0x9d0820, 0xc000416f80, 0x9d66e0, 0xc000416f80, 0x964808, 0x0, 0x0, 0xc000416fc0, 0x964558, 0xc830d44fc000b480, ...)
        /home/ok11/workspace/bb-go/userservice/pkg/api/rest/gen/restapi/configure_user_service.go:134 +0x71a
main.main()
        /home/ok11/workspace/bb-go/userservice/cmd/service/main.go:15 +0x1a6
exit status 2

The panic message prints out a wrong path (it must be not at the path where main.go resides and which basically represents the pwd, but rather pkg/api/rest/def). But even if it were the right path, it is still weird. What I usually distribute, is an executable, not the entire design-time stuff. And YAML API definitions are rather design time, aren't they? How a compiled executable should find them after the distribution?

So, my question is, do you (go-swagger and/or go-openapi) support this scenario at all? I have not found any tests that verify that.

After having put all references inside the file (#/definitions etc) everything works just fine.

Swagger specification

See gist. It is a collection of files, all residing in a def directory

Steps to reproduce

swagger generate server --spec=pkg/api/rest/def/api.yaml --model-package=dto --template=stratoscale --template-dir=pkg/api/rest/templates --name=UserService --target=pkg/api/rest/gen --exclude-main --with-flatten=full
Yes, it is custom templates. If you want me to redo it with default templates, please let me know.

Environment

swagger version: 0.17.0
go version: 1.11
OS: Windows 10 (Linux Subsystem/Ubuntu 18.04)

@fredbi
Copy link
Contributor

fredbi commented Oct 25, 2018

Looks related to go-openapi/validate#102, although I don't know how the templates you are using are calling this (standard templates don't use dynamic schema validation).

@seblegall
Copy link
Contributor

Hi,

I get a similar issue. Here is my folders :

swagger.json
|
- Authent
       |
       - authent.json
- Common
      |
      - errors.json

In swagger.json i have a ref to Authent/authent.json.
In Authent/authent.json i have a ref to Common/errors.json

When I run swagger validate everything is ok.

But when I run swagger serve here is what I have :

capture d ecran 2018-11-13 a 13 22 28

Am I doing something wrong? Or is it related to this issue?

@fredbi
Copy link
Contributor

fredbi commented Nov 13, 2018

This is a different kind of issue. Specs served with swagger serve should be self-contained. Preprocess them with the flatten command if needed.

@seblegall
Copy link
Contributor

Oh ! thx for the tips !

fredbi added a commit to fredbi/analysis that referenced this issue Nov 16, 2018
* Acknowleges go-swagger/go-swagger#1774

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/analysis that referenced this issue Nov 16, 2018
* Acknowleges go-swagger/go-swagger#1774

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@fredbi fredbi added the bug label Nov 16, 2018
@fredbi fredbi self-assigned this Nov 16, 2018
fredbi added a commit to fredbi/go-swagger that referenced this issue Nov 16, 2018
* fixes go-swagger#1796
* fixes go-swagger#1774
* fixes go-swagger#1767

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Nov 16, 2018
* fixes go-swagger#1796
* fixes go-swagger#1774
* fixes go-swagger#1767

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Nov 17, 2018
* fixes go-swagger#1796
* fixes go-swagger#1774
* fixes go-swagger#1767

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Nov 17, 2018
* fixes go-swagger#1796
* fixes go-swagger#1774
* fixes go-swagger#1767

Updates vendor from go-openapi/analysis

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Nov 18, 2018
* fixes go-swagger#1796
* fixes go-swagger#1774
* fixes go-swagger#1767

Updates vendor from go-openapi/analysis

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Nov 19, 2018
* fixes go-swagger#1796
* fixes go-swagger#1774
* fixes go-swagger#1767

Updates vendor from go-openapi/analysis

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Nov 22, 2018
* fixes go-swagger#1796
* fixes go-swagger#1774
* fixes go-swagger#1767

Updates vendor from go-openapi/analysis

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Nov 28, 2018
* fixes go-swagger#1796
* fixes go-swagger#1774
* fixes go-swagger#1767

Updates vendor from go-openapi/analysis

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit that referenced this issue Nov 28, 2018
* Fix flattening spec with remote circular $ref

* fixes #1796
* fixes #1774
* fixes #1767

Updates vendor from go-openapi/analysis

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>

* * Updates vendor (20181118)

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants