You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guidelines/REUSE.md
+27-88Lines changed: 27 additions & 88 deletions
Original file line number
Diff line number
Diff line change
@@ -9,33 +9,40 @@ The following types are reusable, as defined by the spec:
9
9
* Parameters
10
10
* Models (or Schema Objects in general)
11
11
* Responses
12
-
* Operations (_Operations can only be referenced externally_)
12
+
* Operations (_Operations can only be remote references_)
13
13
14
14
## Reuse strategy
15
15
16
-
When reusing components in an API design, a pointer is created from the definition to target design. The references are maintained in the structure, and can be updated by modifying the source definitions. This is different from a "copy on design" approach where references are injected into the design itself.
16
+
When reusing components in an API design, a reference is created from the definition to target entity. The references are maintained in the structure, and can be updated by modifying the source definitions. This is different from a "copy on design" approach where references are injected into the design itself.
17
17
18
18
The reuse technique is transparent between JSON or YAML and is lossless when converting between the two.
19
19
20
20
YAML anchors are technically allowed but break the general reuse strategy in OpenAPI Specification, since anchors are "injected" into a single document. They are not recommended.
21
21
22
-
Referenes can be made either internal to the OpenApi Specification file or to external files.
23
-
24
22
## Techniques
25
23
26
24
### Guidelines for Referencing
27
25
28
-
Whether you reference definitions internally or externally, you can never override or change their definitions from the referring ___location. The definitions can only be used as-is.
26
+
All references should follow the [JSON Reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03) specification.
27
+
28
+
JSON Reference provides guidance on the resolution of references, notably:
29
+
30
+
> If the URI contained in the JSON Reference value is a relative URI,
31
+
then the base URI resolution MUST be calculated according to
32
+
[RFC3986], section 5.2. Resolution is performed relative to the
33
+
referring document.
34
+
35
+
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.
29
36
30
-
#### Internal references
37
+
#### Local references
31
38
32
-
When referencing internally, the target references have designated locations:
39
+
When referencing locally (within the current document), the target references should follow the conventions, as defined by the spec:
33
40
34
41
* Parameters -> `#/parameters`
35
42
* Responses -> `#/responses`
36
-
*Models (and general Schema Objects) -> `#/definitions`
43
+
*Definitions (Models/Schema) -> `#/definitions`
37
44
38
-
All references are canonical and must be a qualified [JSON Pointer, per RFC6901](http://tools.ietf.org/html/rfc6901). For example, simply referencing a model `Pet` is not allowed, even if there are no other definitions of it in the file.
45
+
An example of a local definition reference:
39
46
40
47
_Example from https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json_
41
48
```json
@@ -49,77 +56,11 @@ _Example from https://github.com/OAI/OpenAPI-Specification/blob/master/examples/
49
56
}
50
57
```
51
58
52
-
#### External references
59
+
#### Remote references
53
60
54
-
If your referenced file contains only one root-level definition, you can refer to the file directly.
All external relative references should follow the [JSON Reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03) specification.
116
-
117
-
Per the JSON Reference spec:
118
-
119
-
> If the URI contained in the JSON Reference value is a relative URI,
120
-
then the base URI resolution MUST be calculated according to
121
-
[RFC3986], section 5.2. Resolution is performed relative to the
122
-
referring document.
63
+
Files can be referred to in relative paths to the current document.
123
64
124
65
_Example from https://github.com/OAI/OpenAPI-Specification/tree/master/examples/v2.0/json/petstore-separate/spec/swagger.json_
125
66
@@ -134,7 +75,7 @@ _Example from https://github.com/OAI/OpenAPI-Specification/tree/master/examples/
134
75
}
135
76
```
136
77
137
-
External references may also utilize [JSON Pointer](http://tools.ietf.org/html/rfc6901) to reference properties within the relative external file.
78
+
Remote references may also reference properties within the relative remote file.
138
79
139
80
_Example from https://github.com/OAI/OpenAPI-Specification/tree/master/examples/v2.0/json/petstore-separate/spec/swagger.json_
140
81
``` json
@@ -149,14 +90,12 @@ _Example from https://github.com/OAI/OpenAPI-Specification/tree/master/examples/
149
90
```
150
91
151
92
152
-
#### External by URL
93
+
##### URL
153
94
154
-
External files can be hosted on an HTTP server (rather than the local file system).
95
+
Remote files can be hosted on an HTTP server (rather than the local file system).
155
96
156
97
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).
157
98
158
-
Resolution of URLs should follow [RFC3986](https://tools.ietf.org/html/rfc3986).
Reuse schema definitions by creating a repository of definitions. This is done by simply hosting a file or set of files for commonly used definitions across a company or organization.
215
154
216
-
Refer to [External references](#external-references) for referencing strategies.
155
+
Refer to [Guidelines for Referencing](#guidelines-for-referencing) for referencing strategies.
217
156
218
157
219
158
### Parameters
220
159
221
160
Similar to model schemas, you can create a repository of `parameters` to describe the common entities that appear throughout a set of systems.
222
161
223
-
Refer to [External references](#external-references) for referencing strategies.
162
+
Refer to [Guidelines for Referencing](#guidelines-for-referencing) for referencing strategies.
224
163
225
164
Using the same technique as above, you can host on either a single or multiple files. For simplicity, the example below assumes a single file.
226
165
@@ -296,7 +235,7 @@ To include these parameters, you would need to add them individually as such:
296
235
297
236
Again, Operations can be shared across files. Although the reusability of operations will be less than with Parameters and models. For this example, we will share a common `health` resource so that all APIs can reference it:
298
237
299
-
Refer to [External references](#external-references) for additional referencing strategies.
238
+
Refer to [Guidelines for Referencing](#guidelines-for-referencing) for referencing strategies.
300
239
301
240
```json
302
241
{
@@ -338,7 +277,7 @@ Remember, you cannot override the definitions, but in this case, you can add add
338
277
339
278
### Responses
340
279
341
-
Refer to [External references](#external-references) for additional referencing strategies.
280
+
Refer to [Guidelines for Referencing](#guidelines-for-referencing) for referencing strategies.
0 commit comments