Skip to content

Commit c5e3673

Browse files
authored
Merge pull request #115 from lornajane/overlay-docs
Overlay documentation
2 parents 1d8e4b9 + ccfd62e commit c5e3673

File tree

5 files changed

+145
-1
lines changed

5 files changed

+145
-1
lines changed

glossary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ These acronyms are commonly used in OpenAPI discussions, and are defined in the
3131
- **OpenAPI Initiative** (OAI): The organization responsible for the development of the OpenAPI Specification _(not to be confused with the unrelated and more recent "OpenAI")_, [website](https://openapis.org/)
3232
- **OpenAPI Specification** (OAS): The formal requirements for the OpenAPI format, which exists in several versions (e.g., 3.0.3, 3.1.0) ([repository](https://github.com/OAI/OpenAPI-Specification))
3333
- **Outreach Committee**: The group of volunteers dedicated to furthering the reach and impact of the OAS ([repository](https://github.com/OAI/Outreach))
34-
- **Overlay Specification**: A proposed specification from the overlays SIG ([repository](https://github.com/OAI/Overlay-Specification))
34+
- **Overlay Specification**: A specification to describe repeatable edits to apply to an OpenAPI description ([repository](https://github.com/OAI/Overlay-Specification))
3535
- **Special Interest Group** (SIG): OpenAPI working groups focused on [specific topics](https://github.com/OAI/OpenAPI-Specification/blob/main/SPECIAL_INTEREST_GROUPS.md) related to the OAS or possible additional companion specifications
3636
- **Technical Developer Community** (TDC): The community of developers and specification-writers who work on and provide feedback to OpenAPI projects ([weekly Zoom calls](https://github.com/OAI/OpenAPI-Specification/issues?q=is%3Aissue+is%3Aopen+%22Open+Community+%28TDC%29+Meeting%22) are on Thursdays from 9-10 AM US-Pacific)
3737
- **Technical Steering Committee** (TSC): The [group of people](https://github.com/OAI/OpenAPI-Specification/blob/main/MAINTAINERS.md) charged with stewarding the OAI's specification work, as described in the [OAI Charter](https://www.openapis.org/participate/how-to-contribute/governance)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
layout: default
3+
parent: Overlays
4+
nav_order: 5
5+
title: 'Example: add params selectively'
6+
has_toc: false
7+
---
8+
9+
# Example: Add multiple parameters to selected operations
10+
11+
One of the most requested features for OpenAPI is the ability to group parameters and easily apply all of them together, to either some or all operations in an OpenAPI description.
12+
Especially for common parameters that always come as a set (pagination or filter parameters are a great example), it can be more maintainable to use them as a "trait" and apply the set as part of the API lifecycle rather than trying to maintain a source of truth with a lot of repetition.
13+
This approach leads to good API governance, since if the collection of fields changes then the update is consistently applied through automation.
14+
15+
In the following example, any operations with the extension `x-supports-filters` set to `true` will have two inline parameters added to their parameter collection, and an `x-filters-added` tag for decoration/debugging.
16+
17+
```yaml
18+
overlay: 1.0.0
19+
info:
20+
title: Add filter parameters everywhere
21+
version: 1.0.0
22+
actions:
23+
- target: $.paths.*.*[?(@.x-supports-filters == true)]
24+
update:
25+
parameters:
26+
- name: month
27+
in: query
28+
description: Month number of event (1-12)
29+
required: false
30+
type: integer
31+
32+
- name: time_start
33+
in: query
34+
description: Start time of event
35+
required: false
36+
type: string
37+
tags:
38+
- x-filters-added
39+
```
40+
41+
You can adjust the target expression to apply only to certain paths or methods, or use another approach to identify which operations should be updated.
42+
43+
It might be more elegant to first update the `components.parameters` section of an OpenAPI description to add the parameters there, and then refer to those new entries when updating the existing operations.
44+
The Overlay Specification requires that each action is processed in the order it is seen in the Overlay document.
45+
46+
The 1.0 specification has a [traits example](https://spec.openapis.org/overlay/v1.0.0.html#traits-example) that uses the `x-oas-traits` [Specification Extension](https://spec.openapis.org/oas/v3.1.1.html#specification-extensions).
47+
This extension is a useful convention to consider when you use a pattern like the one described here.

overlay/example-add-license.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
layout: default
3+
parent: Overlays
4+
nav_order: 2
5+
title: 'Example: add a license'
6+
has_toc: false
7+
---
8+
9+
# Example: add a license
10+
11+
Every API needs a license so people know they can use it, but what if your OpenAPI descriptions don't have a license?
12+
This example shows an Overlay that adds a license to an OpenAPI description.
13+
14+
Here's the Overlay file, with just one action to add or change the `info.license` fields:
15+
16+
```yaml
17+
overlay: 1.0.0
18+
info:
19+
title: Add MIT license
20+
version: 1.0.0
21+
actions:
22+
- target: '$.info'
23+
update:
24+
license:
25+
name: MIT
26+
url: https://opensource.org/licenses/MIT
27+
```
28+
29+
You can use this Overlay with different OpenAPI files to make the same change to a batch of files.
30+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
layout: default
3+
parent: Overlays
4+
nav_order: 3
5+
title: 'Example: tag DELETE operations'
6+
has_toc: false
7+
---
8+
9+
# Example: tag DELETE operations
10+
11+
To add the same tag to all operations in an OpenAPI description that use `DELETE` methods, use an Overlay like the example below.
12+
This example adds an `x-restricted` tag to all delete operations:
13+
14+
```yaml
15+
overlay: 1.0.0
16+
info:
17+
title: Tag delete operations as restricted
18+
version: 1.0.0
19+
actions:
20+
- target: $.paths.*.delete
21+
update:
22+
tags:
23+
- x-restricted
24+
```
25+
26+
This overlay adds `x-restricted` to the tags array for each delete operation.
27+
If the tags array doesn't exist, it'll be created; if it does, the new tag is added to the existing array.
28+
29+
You can use an approach like this to make other changes to all matching operations.

overlay/index.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
layout: default
3+
nav_order: 8
4+
title: Overlays
5+
has_children: true
6+
has_toc: false
7+
---
8+
9+
# Introduction to OpenAPI Overlay Specification
10+
11+
The [Overlay Specification](https://spec.openapis.org/overlay/latest.html) defines a document format for information that transforms an existing OpenAPI description yet remains separate from the OpenAPI description's source document(s).
12+
The Overlay Specification defines a mechanism for providing consistent, deterministic updates to a given OpenAPI description, as an aid to automation throughout the API lifecycle.
13+
14+
An Overlay can be applied to an OpenAPI description, resulting in an updated OpenAPI description.
15+
16+
> **OpenAPI + Overlays = (better) OpenAPI**
17+
18+
One Overlay might be specific to one OpenAPI description, or general enough to be used with multiple OpenAPI descriptions.
19+
Equally, one OpenAPI description pipeline might apply different Overlays during the workflow.
20+
21+
## Use cases for Overlays
22+
23+
Overlays support a range of scenarios, including:
24+
25+
- Translating documentation into another language
26+
- Providing configuration information for different deployment environments
27+
- Allowing separation of concerns for metadata such as gateway configuration or SLA information
28+
- Supporting a traits-like capability for applying a set of configuration data, such as multiple parameters or multiple headers, for targeted objects
29+
- Providing default responses or parameters where they were not explicitly provided
30+
- Applying configuration data globally or based on filter conditions
31+
32+
## Resources for working with Overlays
33+
34+
The [GitHub repository for Overlays](https://github.com/oai/Overlay-Specification) is the main hub of activity on the Overlays project.
35+
Check the issues and pull requests for what is currently in progress, and the discussions for details of future ideas and our regular meetings.
36+
37+
The project maintains a [list of tools for working with Overlays](https://github.com/OAI/Overlay-Specification/?tab=readme-ov-file#tools-that-support-overlays).
38+

0 commit comments

Comments
 (0)