go-swagger: responses with external $ref thrown nil pointer dereference

Problem statement

Using an external $ref definition for responses thrown nil pointer dereference:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x8bf5f0]

goroutine 1 [running]:
github.com/go-swagger/go-swagger/vendor/github.com/go-openapi/validate.(*SpecValidator).validateResponseExample(0xc421d27c80, 0xc4202b34c8, 0x1, 0xc421d27818, 0xc42008c780)
	/home/hello/workspace/project/go/src/github.com/go-swagger/go-swagger/vendor/github.com/go-openapi/validate/spec.go:837 +0x3d0
github.com/go-swagger/go-swagger/vendor/github.com/go-openapi/validate.(*SpecValidator).validateExamplesValidAgainstSchema(0xc421d27c80, 0xc421d27a90)
	/home/hello/workspace/project/go/src/github.com/go-swagger/go-swagger/vendor/github.com/go-openapi/validate/spec.go:876 +0x281
github.com/go-swagger/go-swagger/vendor/github.com/go-openapi/validate.(*SpecValidator).Validate(0xc421d27c80, 0xb610e0, 0xc4202a4690, 0x0, 0x0)
	/home/hello/workspace/project/go/src/github.com/go-swagger/go-swagger/vendor/github.com/go-openapi/validate/spec.go:161 +0x4bb
github.com/go-swagger/go-swagger/cmd/swagger/commands.(*ValidateSpec).Execute(0xc4202b2608, 0xc4200e7d00, 0x1, 0x2, 0xc4202b2608, 0x1)
	/home/hello/workspace/project/go/src/github.com/go-swagger/go-swagger/cmd/swagger/commands/validate.go:60 +0x168
github.com/go-swagger/go-swagger/vendor/github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc420159320, 0xc420010190, 0x2, 0x2, 0x412608, 0xc420490630, 0xc42018fe00, 0xc4200e7201, 0xc420257d40)
	/home/hello/workspace/project/go/src/github.com/go-swagger/go-swagger/vendor/github.com/jessevdk/go-flags/parser.go:316 +0x841
github.com/go-swagger/go-swagger/vendor/github.com/jessevdk/go-flags.(*Parser).Parse(0xc420159320, 0x6, 0xbb0ebe, 0x6, 0x0, 0xbf88d9)
	/home/hello/workspace/project/go/src/github.com/go-swagger/go-swagger/vendor/github.com/jessevdk/go-flags/parser.go:186 +0x71
main.main()
	/home/hello/workspace/project/go/src/github.com/go-swagger/go-swagger/cmd/swagger/swagger.go:140 +0xd89

Swagger specification

responses.yaml:

swagger: '2.0'
info:
  title: Responses
  version: 0.1.0
responses:
  NotFound:
    description: Not found

paths:
  /:
    get:
      summary: GET
      operationId: getAll
      responses:
        '200':
          description: Ok

swagger.yaml:

swagger: '2.0'
info:
  title: Object
  version: 0.1.0

paths:
  /:
    get:
      summary: GET
      operationId: getAll
      responses:
        '200':
          description: Ok
        '404':
          $ref: './responses.yaml#/responses/NotFound'

Steps to reproduce

swagger validate swagger.yaml

Environment

swagger version: tested with 0.13.0 and dev go version: 1.9.2 OS: Ubuntu 16.04

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 30 (28 by maintainers)

Most upvoted comments

OK I tested it more seriously. Here is my takeaway: there are some good and bad news.

  • I could fix the panic issue. It was actually a test case I was missing.

  • The #/responses does not resolve to external references (same for #/parameters)

    It looks like $ref to external files are only resolved for schema objects.

    That should be confirmed by our $ref-resolver experts around (@kreamyx, @casualjim)

ok. let us export these, then. I’ll take care of the upgrade in validate.

This construct is not legal in Swagger 2.0. $ref should be under the schema section. The panic issue has been fixed by go-openapi/validate#72 and should be soon vendored with go-swagger