-
Notifications
You must be signed in to change notification settings - Fork 1.2k
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Validate with external files #2044
Comments
As for swagger 2.0 you can't put references arbitrarily like this. Finally, your parameter definition is invalid: it requires: - name: id
in: path
required: true
type: string Here is the corrected example: consumes:
- application/json
produces:
- application/json
schemes:
- http
swagger: '2.0'
info:
version: 1.0.0
title: test
basePath: /test
parameters:
id:
name: id
in: path
required: true
type: string
paths:
'/endpoint/{id}':
parameters:
- $ref: '#/parameters/id'
get:
responses:
'200':
description: Fetched
|
I don't understand the answer...it's true the parameters definition is missing sub-keys, but I'm not clear why the external reference doesn't work under a path item, but does work under an operation. According to the spec, both the Path Item object and the Operation object support a 'parameters' attribute, which can be either a Parameters Object or a Reference Object. And Reference Object is supposed to support external references. To illustrate, I slightly modified the examples. common.yml parameters:
id:
name: id
type: string
in: path
required: true swagger.yml consumes:
- application/json
produces:
- application/json
schemes:
- http
swagger: '2.0'
info:
version: 1.0.0
title: test
basePath: /test
paths:
'/endpoint/{id}':
# if you uncomment this, you get an invalid reference error
# parameters:
# - $ref: 'common.yml#/parameters/id'
get:
# if you uncomment this instead, it works
# parameters:
# - $ref: 'common.yml#/parameters/id'
responses:
'200':
description: Fetched If you uncomment the first block, then run |
According to the openapi specification 2.0 you can't have refs in parameters, only in the schema of a body parameter If you go to look here: https://swagger.io/specification/v2/ You'll find there is no ref in those properties. |
I must be misreading that document...I'm looking at the v2 docs. I look at the top level Swagger Object. That has a "paths" field of type Paths Object. Paths Object as a field "/{path}" of type Path Item Object. Path Item Object has a field "parameters", which is an array of either Parameter Object, or Reference Object. The definition of Reference Object indicates that it can accept local or external references. The definition of the "parameters" field on the Path Item object is identical to the definition on the Operation object. But they don't seem to work the same.
Also, if I copy the contents of common.yml into swagger.yml, and change the path parameters ref to an internal ref, it works. So it doesn't seem like the problem is related to using refs in path parameters, it seems to be about using an external ref. consumes:
- application/json
produces:
- application/json
schemes:
- http
swagger: '2.0'
info:
version: 1.0.0
title: test
basePath: /test
paths:
'/endpoint/{id}':
parameters:
# an internal ref will work
- $ref: '#/parameters/id'
# but not an external one
# - $ref: 'common.yml#/parameters/id'
get:
responses:
'200':
description: Fetched
parameters:
id:
name: id
type: string
in: path
required: true |
Problem statement
Swagger specification is splitted to some files, and files have refs to external files. When i try to validate it, I get errors about invalid reference
Swagger specification
2.0
Steps to reproduce
have files
swagger.yml
and common.yml
run command
go-swagger validate swagger.yml
got
Environment
swagger version: dev (on moment 2019-08-15)
go version go1.12.7 linux/amd64
OS: ubuntu 16.10
The text was updated successfully, but these errors were encountered: