Skip to content

Commit

Permalink
create overlays docs (#990)
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdallah Abedraba authored Nov 29, 2022
1 parent bab5657 commit 7eb2f70
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
107 changes: 107 additions & 0 deletions docs/docs/guides/overlays.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# OpenAPI Overlays

Kusk supports code-first approaches, i.e. OpenAPI generated from code annotations, by use of OpenAPI Overlays.

[OpenAPI Overlays](https://github.com/OAI/Overlay-Specification) is a new specification that allows you to have an OpenAPI file without any Kusk extensions, and an overlay file containing the extenions you would want to add to your OpenAPI definition.

After merging the overlay with the OpenAPI file, the resulting file is an OpenAPI definition with all the metadata added to it, ready to be deployed by Kusk.

This way, teams can generate their OpenAPI from code, and then add the gateway deployment metadata later.

## Example

Let's start with an OpenAPI definition that does not have any Kusk extensions added to it.

```yaml file="openapi.yaml"
openapi: 3.0.0
servers:
- url: http://api.mydomain.com
info:
title: simple-api
version: 0.1.0
paths:
/hello:
get:
summary: Returns a Hello world to the user
responses:
'200':
description: A simple hello world!
content:
application/json; charset=utf-8:
schema:
type: object
properties:
message:
type: string
required:
- message
```
Now let's create an overlay that adds Kusk mocking policy to our OpenAPI definition.
```yaml file="overlay.yaml"
overlays: 1.0.0
extends: ./openapi.yaml
actions:
- target: "$"
update:
mocking:
enabled: true
```
To apply the overlay to the OpenAPI definition, run:
```sh
kusk deploy --overlay overlay.yaml
```

```sh title="Expected output"
🎉 successfully parsed
✅ initiallizing deployment to fleet kusk-gateway-envoy-fleet
api.gateway.kusk.io/simple-api created
```

If you want to look at the generated OpenAPI file before deploying it to Kusk, you can run:

```sh
kusk generate --overlay overlay.yaml
```

```yaml title="Expected output"
apiVersion: gateway.kusk.io/v1alpha1
kind: API
metadata:
name: simple-api
namespace: default
spec:
fleet:
name: kusk-gateway-envoy-fleet
namespace: kusk-system
spec: |
openapi: 3.0.0
servers:
- url: http://api.mydomain.com
components: {}
info:
title: simple-api
version: 0.1.0
x-kusk:
mocking:
enabled: true
paths:
/hello:
get:
responses:
"200":
content:
application/json; charset=utf-8:
schema:
properties:
message:
type: string
required:
- message
type: object
description: A simple hello world!
summary: Returns a Hello world to the user
```
1 change: 1 addition & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const sidebars = {
"guides/timeouts",
"guides/routing",
"guides/rate-limit",
"guides/overlays",
"guides/cert-manager",
"guides/troubleshooting",
"guides/observability",
Expand Down

0 comments on commit 7eb2f70

Please sign in to comment.