Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 401642c

Browse files
authored
Openapi proxy example (#112)
1 parent ad08bf6 commit 401642c

File tree

6 files changed

+217
-0
lines changed

6 files changed

+217
-0
lines changed

openapi.proxy/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# openapi.proxy
2+
## Running locally
3+
4+
This example runs using Docker compose. You will find the setup scripts in the [compose](./docker/compose) folder.
5+
6+
### Setup
7+
8+
The `setup.sh` script will:
9+
10+
- Configured Zilla instance
11+
- Start openapi-mock
12+
13+
```bash
14+
./compose/setup.sh
15+
```
16+
17+
### Test
18+
19+
```bash
20+
curl --location 'http://localhost:7114/pets' --header 'Accept: application/json'
21+
```
22+
23+
### Teardown
24+
25+
The `teardown.sh` script will remove any resources created.
26+
27+
```bash
28+
./compose/teardown.sh
29+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: '3'
2+
services:
3+
zilla:
4+
image: ghcr.io/aklivity/zilla:latest
5+
container_name: zilla
6+
pull_policy: always
7+
restart: unless-stopped
8+
ports:
9+
- 7114:7114
10+
environment:
11+
ZILLA_INCUBATOR_ENABLED: true
12+
volumes:
13+
- ../../specs/schema.json:/etc/zilla/schema.json
14+
- ../../zilla.yaml:/etc/zilla/zilla.yaml
15+
command: start -v -e
16+
17+
openapi-mock:
18+
image: jormaechea/open-api-mocker
19+
platform: linux/amd64
20+
volumes:
21+
- ../../specs:/app
22+
ports:
23+
- "8000:5000"
24+
25+
networks:
26+
default:
27+
driver: bridge

openapi.proxy/docker/compose/setup.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -e
3+
4+
NAMESPACE=zilla-openapi-proxy
5+
# Start or restart Zilla
6+
if [[ -z $(docker-compose -p $NAMESPACE ps -q zilla) ]]; then
7+
docker-compose -p $NAMESPACE up -d
8+
else
9+
docker-compose -p $NAMESPACE restart --no-deps zilla
10+
fi
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
set -e
3+
4+
NAMESPACE=zilla-openapi-proxy
5+
docker-compose -p $NAMESPACE down --remove-orphans

openapi.proxy/specs/schema.json

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"version": "1.0.0",
5+
"title": "Swagger Petstore",
6+
"license": {
7+
"name": "MIT"
8+
}
9+
},
10+
"servers": [
11+
{
12+
"url": "http://localhost:7114"
13+
}
14+
],
15+
"paths": {
16+
"/pets": {
17+
"get": {
18+
"summary": "List all pets",
19+
"operationId": "listPets",
20+
"tags": [
21+
"pets"
22+
],
23+
"responses": {
24+
"200": {
25+
"description": "A paged array of pets",
26+
"content": {
27+
"application/json": {
28+
"schema": {
29+
"$ref": "#/components/schemas/Pets"
30+
}
31+
}
32+
}
33+
},
34+
"default": {
35+
"description": "unexpected error",
36+
"content": {
37+
"application/json": {
38+
"schema": {
39+
"$ref": "#/components/schemas/Error"
40+
}
41+
}
42+
}
43+
}
44+
}
45+
},
46+
"post": {
47+
"summary": "Create a pet",
48+
"operationId": "createPets",
49+
"tags": [
50+
"pets"
51+
],
52+
"requestBody": {
53+
"content": {
54+
"application/json": {
55+
"schema": {
56+
"$ref": "#/components/schemas/Pet"
57+
}
58+
}
59+
},
60+
"required": true
61+
},
62+
"responses": {
63+
"201": {
64+
"description": "Null response"
65+
},
66+
"default": {
67+
"description": "unexpected error",
68+
"content": {
69+
"application/json": {
70+
"schema": {
71+
"$ref": "#/components/schemas/Error"
72+
}
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}
79+
},
80+
"components": {
81+
"schemas": {
82+
"Pet": {
83+
"type": "object",
84+
"required": [
85+
"id",
86+
"name"
87+
],
88+
"properties": {
89+
"id": {
90+
"type": "integer",
91+
"format": "int64"
92+
},
93+
"name": {
94+
"type": "string"
95+
},
96+
"tag": {
97+
"type": "string"
98+
}
99+
}
100+
},
101+
"Pets": {
102+
"type": "array",
103+
"maxItems": 100,
104+
"items": {
105+
"$ref": "#/components/schemas/Pet"
106+
}
107+
},
108+
"Error": {
109+
"type": "object",
110+
"required": [
111+
"code",
112+
"message"
113+
],
114+
"properties": {
115+
"code": {
116+
"type": "integer",
117+
"format": "int32"
118+
},
119+
"message": {
120+
"type": "string"
121+
}
122+
}
123+
}
124+
}
125+
}
126+
}

openapi.proxy/zilla.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: zilla-openapi-proxy
3+
bindings:
4+
north_openapi_server:
5+
type: openapi
6+
kind: server
7+
options:
8+
specs:
9+
my-openapi-spec: schema.json
10+
exit: south_openapi_lcient
11+
south_openapi_lcient:
12+
type: openapi
13+
kind: client
14+
options:
15+
specs:
16+
my-openapi-spec: schema.json
17+
tcp:
18+
host: openapi-mock
19+
port:
20+
- 5000

0 commit comments

Comments
 (0)