-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Splitting guidelines #547
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
Closed
Closed
Splitting guidelines #547
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# Guidelines for Referencing | ||
|
||
The OpenAPI Specification relies on JSON Refereneces as the machinsm for reusability (DRY). This guide gives you a brief introduction to JSON References and its capability. It does not provide the full details which are covered in its own specification, but aims to provide you with information about the reference types. | ||
|
||
All references should follow the [JSON Reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03) specification. | ||
|
||
JSON Reference provides guidance on the resolution of references, notably: | ||
|
||
> If the URI contained in the JSON Reference value is a relative URI, | ||
then the base URI resolution MUST be calculated according to | ||
[RFC3986], section 5.2. Resolution is performed relative to the | ||
referring document. | ||
|
||
Whether you reference definitions locally or remote, you can never override or change their definitions from the referring location. The definitions can only be used as-is. | ||
|
||
### Local references | ||
|
||
When referencing locally (within the current document), the target references should follow the conventions, as defined by the spec: | ||
|
||
* Parameters -> `#/parameters` | ||
* Responses -> `#/responses` | ||
* Definitions (Models/Schema) -> `#/definitions` | ||
|
||
An example of a local definition reference: | ||
|
||
_Example from https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json_ | ||
``` json | ||
// ... | ||
"200": { | ||
"description": "pet response", | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/Pet" | ||
} | ||
} | ||
``` | ||
|
||
### Remote references | ||
|
||
#### Relative path | ||
|
||
Files can be referred to in relative paths to the current document. | ||
|
||
_Example from https://github.com/OAI/OpenAPI-Specification/tree/master/examples/v2.0/json/petstore-separate/spec/swagger.json_ | ||
|
||
``` json | ||
// ... | ||
"responses": { | ||
"default": { | ||
"description": "unexpected error", | ||
"schema": { | ||
"$ref": "../common/Error.json" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Remote references may also reference properties within the relative remote file. | ||
|
||
_Example from https://github.com/OAI/OpenAPI-Specification/tree/master/examples/v2.0/json/petstore-separate/spec/swagger.json_ | ||
``` json | ||
// ... | ||
"parameters": [ | ||
{ | ||
"$ref": "parameters.json#/tagsParam" | ||
}, | ||
{ | ||
"$ref": "parameters.json#/limitsParam" | ||
} | ||
] | ||
``` | ||
|
||
|
||
#### URL | ||
|
||
Remote files can be hosted on an HTTP server (rather than the local file system). | ||
|
||
One risk of this approach is that environment specific issues could arise if DNS is not taken into account (as the reference can only contain one hostname). | ||
|
||
_Assuming file https://my.company.com/definitions/Model.json_ | ||
```json | ||
{ | ||
"description": "A simple model", | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "integer", | ||
"format": "int64" | ||
}, | ||
"tag": { | ||
"description": "A complex, shared property. Note the absolute reference", | ||
"$ref": "https://my.company.com/definitions/Tag.json" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Remote references may also reference properties within the remote file. | ||
|
||
_Assuming file https://my.company.com/definitions/models.json_ | ||
```json | ||
{ | ||
"models": { | ||
"Model": { | ||
"description": "A simple model", | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "integer", | ||
"format": "int64" | ||
}, | ||
"tag": { | ||
"description": "a complex, shared property. Note the absolute reference", | ||
"$ref": "https://my.company.com/definitions/models.json#/models/Tag" | ||
} | ||
} | ||
}, | ||
"Tag": { | ||
"description": "A tag entity in the system", | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mechanism