Skip to content

Commit 4edff51

Browse files
committed
fixes #1 Add Petstore OpenAPI 3.0 spec and test case
1 parent 76ab5be commit 4edff51

File tree

2 files changed

+306
-0
lines changed

2 files changed

+306
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.networknt.oas;
2+
3+
import com.networknt.oas.model.OpenApi3;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class PetstoreTest {
8+
@Test
9+
public void testLoadPetstore() {
10+
OpenApi3 openApi3 = (OpenApi3) new OpenApiParser().parse(PetstoreTest.class.getClassLoader().getResource("models/openapi.json"), true);
11+
Assert.assertNotNull(openApi3);
12+
}
13+
}
Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
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://petstore.swagger.io/v1"
13+
}
14+
],
15+
"paths": {
16+
"/pets": {
17+
"get": {
18+
"summary": "List all pets",
19+
"operationId": "listPets",
20+
"tags": [
21+
"pets"
22+
],
23+
"parameters": [
24+
{
25+
"name": "limit",
26+
"in": "query",
27+
"description": "How many items to return at one time (max 100)",
28+
"required": false,
29+
"schema": {
30+
"type": "integer",
31+
"format": "int32"
32+
}
33+
}
34+
],
35+
"security": [
36+
{
37+
"petstore_auth": [
38+
"read:pets"
39+
]
40+
}
41+
],
42+
"responses": {
43+
"200": {
44+
"description": "An paged array of pets",
45+
"headers": {
46+
"x-next": {
47+
"description": "A link to the next page of responses",
48+
"schema": {
49+
"type": "string"
50+
}
51+
}
52+
},
53+
"content": {
54+
"application/json": {
55+
"schema": {
56+
"type": "array",
57+
"items": {
58+
"$ref": "#/components/schemas/Pet"
59+
}
60+
},
61+
"example": [
62+
{
63+
"id": 1,
64+
"name": "catten",
65+
"tag": "cat"
66+
},
67+
{
68+
"id": 2,
69+
"name": "doggy",
70+
"tag": "dog"
71+
}
72+
]
73+
}
74+
}
75+
},
76+
"default": {
77+
"description": "unexpected error",
78+
"content": {
79+
"application/json": {
80+
"schema": {
81+
"$ref": "#/components/schemas/Error"
82+
}
83+
}
84+
}
85+
}
86+
}
87+
},
88+
"post": {
89+
"summary": "Create a pet",
90+
"operationId": "createPets",
91+
"requestBody": {
92+
"description": "Pet to add to the store",
93+
"required": true,
94+
"content": {
95+
"application/json": {
96+
"schema": {
97+
"$ref": "#/components/schemas/Pet"
98+
}
99+
}
100+
}
101+
},
102+
"tags": [
103+
"pets"
104+
],
105+
"security": [
106+
{
107+
"petstore_auth": [
108+
"read:pets",
109+
"write:pets"
110+
]
111+
}
112+
],
113+
"responses": {
114+
"201": {
115+
"description": "Null response"
116+
},
117+
"default": {
118+
"description": "unexpected error",
119+
"content": {
120+
"application/json": {
121+
"schema": {
122+
"$ref": "#/components/schemas/Error"
123+
}
124+
}
125+
}
126+
}
127+
}
128+
}
129+
},
130+
"/pets/{petId}": {
131+
"get": {
132+
"summary": "Info for a specific pet",
133+
"operationId": "showPetById",
134+
"tags": [
135+
"pets"
136+
],
137+
"parameters": [
138+
{
139+
"name": "petId",
140+
"in": "path",
141+
"required": true,
142+
"description": "The id of the pet to retrieve",
143+
"schema": {
144+
"type": "string"
145+
}
146+
}
147+
],
148+
"security": [
149+
{
150+
"petstore_auth": [
151+
"read:pets"
152+
]
153+
}
154+
],
155+
"responses": {
156+
"200": {
157+
"description": "Expected response to a valid request",
158+
"content": {
159+
"application/json": {
160+
"schema": {
161+
"$ref": "#/components/schemas/Pet"
162+
},
163+
"example": {
164+
"id": 1,
165+
"name": "Jessica Right",
166+
"tag": "pet"
167+
}
168+
}
169+
}
170+
},
171+
"default": {
172+
"description": "unexpected error",
173+
"content": {
174+
"application/json": {
175+
"schema": {
176+
"$ref": "#/components/schemas/Error"
177+
}
178+
}
179+
}
180+
}
181+
}
182+
},
183+
"delete": {
184+
"summary": "Delete a specific pet",
185+
"operationId": "deletePetById",
186+
"tags": [
187+
"pets"
188+
],
189+
"parameters": [
190+
{
191+
"name": "petId",
192+
"in": "path",
193+
"required": true,
194+
"description": "The id of the pet to delete",
195+
"schema": {
196+
"type": "string"
197+
}
198+
},
199+
{
200+
"name": "key",
201+
"in": "header",
202+
"required": true,
203+
"description": "The key header",
204+
"schema": {
205+
"type": "string"
206+
}
207+
}
208+
],
209+
"security": [
210+
{
211+
"petstore_auth": [
212+
"write:pets"
213+
]
214+
}
215+
],
216+
"responses": {
217+
"200": {
218+
"description": "Expected response to a valid request",
219+
"content": {
220+
"application/json": {
221+
"schema": {
222+
"$ref": "#/components/schemas/Pet"
223+
}
224+
}
225+
}
226+
},
227+
"default": {
228+
"description": "unexpected error",
229+
"content": {
230+
"application/json": {
231+
"schema": {
232+
"$ref": "#/components/schemas/Error"
233+
}
234+
}
235+
}
236+
}
237+
}
238+
}
239+
}
240+
},
241+
"components": {
242+
"securitySchemes": {
243+
"petstore_auth": {
244+
"type": "oauth2",
245+
"description": "This API uses OAuth 2 with the client credential grant flow.",
246+
"flows": {
247+
"clientCredentials": {
248+
"tokenUrl": "https://localhost:6882/token",
249+
"scopes": {
250+
"write:pets": "modify pets in your account",
251+
"read:pets": "read your pets"
252+
}
253+
}
254+
}
255+
}
256+
},
257+
"schemas": {
258+
"Pet": {
259+
"required": [
260+
"id",
261+
"name"
262+
],
263+
"properties": {
264+
"id": {
265+
"type": "integer",
266+
"format": "int64"
267+
},
268+
"name": {
269+
"type": "string"
270+
},
271+
"tag": {
272+
"type": "string"
273+
}
274+
}
275+
},
276+
"Error": {
277+
"required": [
278+
"code",
279+
"message"
280+
],
281+
"properties": {
282+
"code": {
283+
"type": "integer",
284+
"format": "int32"
285+
},
286+
"message": {
287+
"type": "string"
288+
}
289+
}
290+
}
291+
}
292+
}
293+
}

0 commit comments

Comments
 (0)