-
Notifications
You must be signed in to change notification settings - Fork 536
Using external file with all definitions doesn't work #147
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
Comments
I believe the relative file references shouldn't have the Unfortunately this is a hazy portion of the json-pointer spec, and it may not be consistent across all implementations. |
I have the same problem, and it doesn't work better without Moreover, the same problem arises for the whole |
I missed something on the first commit. This:
is not legal. You cannot have any additional attribute as a sibling to a What you should do instead is change the references from here:
To here:
|
you're right about sibling legality, anyway you shouldn't have to use this trick to use an external definition file :) |
yes, we're not violating json schema at this point, even if it's painful sometimes. |
I think the point of this issue is that we should allow:
or even:
and the same for any other section (parameters, responses, paths, etc), but this isn't supported at the moment, right? |
@fehguy oh, I see your point. I'm in favor of this feature mainly because it's useful, the Swagger's JSON schema allows it, and so do validating tools like sway. |
If the question is on whether: definitions:
$ref: './defs.yaml' is allowed in 2.0 then the answer is 'definitely not'. Whether the JSON Schema allows it or not is irrelevant as the source of truth is the spec itself. |
Oh, I understand, thanks @webron. I thought that since the Swagger syntax is just a subset of JSON Schema, the reference mechanism has to be preserved (and so a {$ref: x} object should be dereferenced no matter where it is). Note that lots of Swagger tools out there do JSON Schema-based parsing, so they dereference all $refs as I said. I like that you are planning to support references in more places in 3.0 (e.g. OAI/OpenAPI-Specification#677 OAI/OpenAPI-Specification#680 OAI/OpenAPI-Specification#544), but I'd vote for references everywhere :) |
@diegode That's a common mistake, but Swagger syntax is not a subset of JSON Schema. The Schema Object, under the Swagger spec is a subset of JSON Schema. The rest of the structure is just a JSON format we chose, and we chose to support JSON References in some places. I won't go into it here, but there are pros and cons to allowing JSON References everywhere. I agree we should extend the locations, I disagree we should allow them everywhere. In any case, just because other tools dereference all the references automatically, doesn't make them right ;) |
Am I doing something wrong? I get bad behavior with this. In my main file I have: paths:
/cogs:
get:
summary: List cogs
tags:
- Cogs
responses:
200:
description: An array of cogs
schema:
type: array
items:
$ref: 'definitions.yaml#/definitions/Cog'
default:
description: Unexpected error
schema:
$ref: 'definitions.yaml#/definitions/Error' And in definitions.yaml: definitions:
CogSummary:
type: object
properties:
id:
type: string
description: Unique identifier
readOnly: true
name:
type: string
description: Name of the cog.
Cog:
type: object
properties:
id:
type: string
description: Unique identifier.
readOnly: true
name:
type: string
description: Name of the cog.
components:
type: array
items:
$ref: '#/definitions/Component'
description: List of components.
status:
type: string
description: Status of the cog
Component:
type: object
properties:
id:
type: string
description: Unique identifier.
readOnly: true
name:
type: string
description: Name of the component.
appId:
type: string
description: ID of the app this component belongs to.
... Note how I only reference definitions/Cog in paths//cogs/get. It validates, but "swagger bundle" produces this under responses: responses:
'200':
description: An array of cogs
schema:
type: array
items:
definitions:
CogSummary:
type: object
properties:
id:
type: string
description: Unique identifier
readOnly: true
name:
type: string
description: Name of the cog.
Cog:
type: object
properties:
id:
type: string
description: Unique identifier.
readOnly: true
name:
type: string
description: Name of the cog.
components:
type: array
items:
$ref: >-
#/paths/~1cogs/get/responses/200/schema/items/definitions/Component
description: List of components.
status:
type: string
description: Status of the cog.
Component:
type: object
properties:
id:
type: string
description: Unique identifier.
readOnly: true
name:
type: string
description: Name of the component.
appId:
type: string
description: ID of the app this component belongs to.
... Note:
Perhaps these are bugs I should file against swagger bundle in particular? |
What is swagger bundle? Perhaps it's a project using this library. If so, you do need to open an issue there, or turn your case into something reproducable by this library directly. The ref that you describe is a legal json pointer. |
Oops, my bad. It's part of a CLI I'm using that I thought was official. It's clearly not. |
OK got it. There are two modes for the parser, which includes "resolving" and simply parsing. If resolving, it will pull remote definitions into the local file. |
We have a file with all the definitions for a given service in a separated file and we need to reuse it in multiple api definitions but we cannnot import it. The definition original definition file use model with nested models etc and we need to import a lot of these, we cannot repeat all the names with all the $refs in every api definition.
In this example we need import all the definitions from _testdrivemulti.yaml and use it in the main api definition but it doesn't work.
The text was updated successfully, but these errors were encountered: