Skip to content

Commit 0b247d8

Browse files
authored
Merge pull request #102 from Bellangelo/add-examples-from-main-specification-repository
Move examples from OpenAPI-Specification repository
2 parents 3279d75 + d605231 commit 0b247d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+7117
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: convert-examples-to-json
2+
3+
# author: @MikeRalphson / @cebe
4+
# issue: https://github.com/OAI/OpenAPI-Specification/issues/1385
5+
6+
#
7+
# This workflow updates the *.json files in the examples/v3.x directories,
8+
# when the corresponding *.yaml files change.
9+
# JSON example files are automatically generated from the YAML example files.
10+
# Only the YAML files should be adjusted manually.
11+
#
12+
13+
# run this on push to main
14+
on:
15+
push:
16+
branches:
17+
- main
18+
paths:
19+
- 'examples/**'
20+
21+
jobs:
22+
yaml2json:
23+
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- uses: actions/checkout@v2 # checkout repo content
28+
29+
- uses: actions/setup-node@v4 # setup Node.js
30+
with:
31+
node-version: '20.x'
32+
33+
- name: Install dependencies
34+
run: npm ci
35+
36+
- name: convert YAML examples to JSON
37+
run: find examples/v3* -type f -name "*.yaml" | xargs node scripts/yaml2json/yaml2json.js
38+
39+
- name: git diff
40+
run: |
41+
git add examples/**/*.json
42+
git --no-pager -c color.diff=always diff --staged
43+
44+
- name: Create Pull Request
45+
uses: peter-evans/create-pull-request@v5
46+
with:
47+
token: ${{ secrets.GITHUB_TOKEN }}
48+
branch: update-json-examples
49+
title: Update JSON example files
50+
commit-message: Update JSON example files
51+
body: |
52+
This pull request is automatically triggered by GitHub action `convert-examples-to-json`.
53+
54+
The examples/v3.* YAML files have changed, so the JSON files are automatically being recreated.
55+

.github/workflows/examples-tests.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: schema-test
2+
3+
# Author: @MikeRalphson / runs @jdesrosiers tests
4+
# Issue: https://github.com/OAI/OpenAPI-Specification/pull/2489
5+
6+
#
7+
# This workflow runs the npm test script to validate passing and failing
8+
# testcases for the metaschema.
9+
#
10+
11+
# run this on push to any branch and creation of pull-requests
12+
on:
13+
push:
14+
paths:
15+
- 'examples/**'
16+
pull_request:
17+
paths:
18+
- 'examples/**'
19+
workflow_dispatch: {}
20+
21+
jobs:
22+
test:
23+
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- uses: actions/checkout@v4 # checkout repo content
28+
with:
29+
fetch-depth: 0
30+
- uses: actions/setup-node@v4 # setup Node.js
31+
with:
32+
node-version: '20.x'
33+
- name: Install dependencies from main
34+
run: npm ci
35+
- name: Run tests
36+
run: npm run test
37+

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ _site/
33
*.swp
44
.jekyll-metadata
55
.ruby-version
6+
node_modules
7+
tests/**/schema.json
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "Simple API overview",
5+
"version": "v2"
6+
},
7+
"paths": {
8+
"/": {
9+
"get": {
10+
"operationId": "listVersionsv2",
11+
"summary": "List API versions",
12+
"produces": [
13+
"application/json"
14+
],
15+
"responses": {
16+
"200": {
17+
"description": "200 300 response",
18+
"examples": {
19+
"application/json": "{\n \"versions\": [\n {\n \"status\": \"CURRENT\",\n \"updated\": \"2011-01-21T11:33:21Z\",\n \"id\": \"v2.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v2/\",\n \"rel\": \"self\"\n }\n ]\n },\n {\n \"status\": \"EXPERIMENTAL\",\n \"updated\": \"2013-07-23T11:33:21Z\",\n \"id\": \"v3.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v3/\",\n \"rel\": \"self\"\n }\n ]\n }\n ]\n}"
20+
}
21+
},
22+
"300": {
23+
"description": "200 300 response",
24+
"examples": {
25+
"application/json": "{\n \"versions\": [\n {\n \"status\": \"CURRENT\",\n \"updated\": \"2011-01-21T11:33:21Z\",\n \"id\": \"v2.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v2/\",\n \"rel\": \"self\"\n }\n ]\n },\n {\n \"status\": \"EXPERIMENTAL\",\n \"updated\": \"2013-07-23T11:33:21Z\",\n \"id\": \"v3.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v3/\",\n \"rel\": \"self\"\n }\n ]\n }\n ]\n}"
26+
}
27+
}
28+
}
29+
}
30+
},
31+
"/v2": {
32+
"get": {
33+
"operationId": "getVersionDetailsv2",
34+
"summary": "Show API version details",
35+
"produces": [
36+
"application/json"
37+
],
38+
"responses": {
39+
"200": {
40+
"description": "200 203 response",
41+
"examples": {
42+
"application/json": "{\n \"version\": {\n \"status\": \"CURRENT\",\n \"updated\": \"2011-01-21T11:33:21Z\",\n \"media-types\": [\n {\n \"base\": \"application/xml\",\n \"type\": \"application/vnd.openstack.compute+xml;version=2\"\n },\n {\n \"base\": \"application/json\",\n \"type\": \"application/vnd.openstack.compute+json;version=2\"\n }\n ],\n \"id\": \"v2.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v2/\",\n \"rel\": \"self\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf\",\n \"type\": \"application/pdf\",\n \"rel\": \"describedby\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl\",\n \"type\": \"application/vnd.sun.wadl+xml\",\n \"rel\": \"describedby\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl\",\n \"type\": \"application/vnd.sun.wadl+xml\",\n \"rel\": \"describedby\"\n }\n ]\n }\n}"
43+
}
44+
},
45+
"203": {
46+
"description": "200 203 response",
47+
"examples": {
48+
"application/json": "{\n \"version\": {\n \"status\": \"CURRENT\",\n \"updated\": \"2011-01-21T11:33:21Z\",\n \"media-types\": [\n {\n \"base\": \"application/xml\",\n \"type\": \"application/vnd.openstack.compute+xml;version=2\"\n },\n {\n \"base\": \"application/json\",\n \"type\": \"application/vnd.openstack.compute+json;version=2\"\n }\n ],\n \"id\": \"v2.0\",\n \"links\": [\n {\n \"href\": \"http://23.253.228.211:8774/v2/\",\n \"rel\": \"self\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf\",\n \"type\": \"application/pdf\",\n \"rel\": \"describedby\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl\",\n \"type\": \"application/vnd.sun.wadl+xml\",\n \"rel\": \"describedby\"\n }\n ]\n }\n}"
49+
}
50+
}
51+
}
52+
}
53+
}
54+
},
55+
"consumes": [
56+
"application/json"
57+
]
58+
}
+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"version": "1.0.0",
5+
"title": "Swagger Petstore",
6+
"description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
7+
"termsOfService": "http://swagger.io/terms/",
8+
"contact": {
9+
"name": "Swagger API Team",
10+
"email": "[email protected]",
11+
"url": "http://swagger.io"
12+
},
13+
"license": {
14+
"name": "Apache 2.0",
15+
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
16+
}
17+
},
18+
"host": "petstore.swagger.io",
19+
"basePath": "/api",
20+
"schemes": [
21+
"http"
22+
],
23+
"consumes": [
24+
"application/json"
25+
],
26+
"produces": [
27+
"application/json"
28+
],
29+
"paths": {
30+
"/pets": {
31+
"get": {
32+
"description": "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n",
33+
"operationId": "findPets",
34+
"parameters": [
35+
{
36+
"name": "tags",
37+
"in": "query",
38+
"description": "tags to filter by",
39+
"required": false,
40+
"type": "array",
41+
"collectionFormat": "csv",
42+
"items": {
43+
"type": "string"
44+
}
45+
},
46+
{
47+
"name": "limit",
48+
"in": "query",
49+
"description": "maximum number of results to return",
50+
"required": false,
51+
"type": "integer",
52+
"format": "int32"
53+
}
54+
],
55+
"responses": {
56+
"200": {
57+
"description": "pet response",
58+
"schema": {
59+
"type": "array",
60+
"items": {
61+
"$ref": "#/definitions/Pet"
62+
}
63+
}
64+
},
65+
"default": {
66+
"description": "unexpected error",
67+
"schema": {
68+
"$ref": "#/definitions/Error"
69+
}
70+
}
71+
}
72+
},
73+
"post": {
74+
"description": "Creates a new pet in the store. Duplicates are allowed",
75+
"operationId": "addPet",
76+
"parameters": [
77+
{
78+
"name": "pet",
79+
"in": "body",
80+
"description": "Pet to add to the store",
81+
"required": true,
82+
"schema": {
83+
"$ref": "#/definitions/NewPet"
84+
}
85+
}
86+
],
87+
"responses": {
88+
"200": {
89+
"description": "pet response",
90+
"schema": {
91+
"$ref": "#/definitions/Pet"
92+
}
93+
},
94+
"default": {
95+
"description": "unexpected error",
96+
"schema": {
97+
"$ref": "#/definitions/Error"
98+
}
99+
}
100+
}
101+
}
102+
},
103+
"/pets/{id}": {
104+
"get": {
105+
"description": "Returns a user based on a single ID, if the user does not have access to the pet",
106+
"operationId": "find pet by id",
107+
"parameters": [
108+
{
109+
"name": "id",
110+
"in": "path",
111+
"description": "ID of pet to fetch",
112+
"required": true,
113+
"type": "integer",
114+
"format": "int64"
115+
}
116+
],
117+
"responses": {
118+
"200": {
119+
"description": "pet response",
120+
"schema": {
121+
"$ref": "#/definitions/Pet"
122+
}
123+
},
124+
"default": {
125+
"description": "unexpected error",
126+
"schema": {
127+
"$ref": "#/definitions/Error"
128+
}
129+
}
130+
}
131+
},
132+
"delete": {
133+
"description": "deletes a single pet based on the ID supplied",
134+
"operationId": "deletePet",
135+
"parameters": [
136+
{
137+
"name": "id",
138+
"in": "path",
139+
"description": "ID of pet to delete",
140+
"required": true,
141+
"type": "integer",
142+
"format": "int64"
143+
}
144+
],
145+
"responses": {
146+
"204": {
147+
"description": "pet deleted"
148+
},
149+
"default": {
150+
"description": "unexpected error",
151+
"schema": {
152+
"$ref": "#/definitions/Error"
153+
}
154+
}
155+
}
156+
}
157+
}
158+
},
159+
"definitions": {
160+
"Pet": {
161+
"type": "object",
162+
"allOf": [
163+
{
164+
"$ref": "#/definitions/NewPet"
165+
},
166+
{
167+
"required": [
168+
"id"
169+
],
170+
"properties": {
171+
"id": {
172+
"type": "integer",
173+
"format": "int64"
174+
}
175+
}
176+
}
177+
]
178+
},
179+
"NewPet": {
180+
"type": "object",
181+
"required": [
182+
"name"
183+
],
184+
"properties": {
185+
"name": {
186+
"type": "string"
187+
},
188+
"tag": {
189+
"type": "string"
190+
}
191+
}
192+
},
193+
"Error": {
194+
"type": "object",
195+
"required": [
196+
"code",
197+
"message"
198+
],
199+
"properties": {
200+
"code": {
201+
"type": "integer",
202+
"format": "int32"
203+
},
204+
"message": {
205+
"type": "string"
206+
}
207+
}
208+
}
209+
}
210+
}

0 commit comments

Comments
 (0)