1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package testing
16
17 import (
18 "encoding/json"
19 )
20
21
22 const PetStore20YAML = `swagger: '2.0'
23 info:
24 version: '1.0.0'
25 title: Swagger Petstore
26 description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification
27 termsOfService: http://helloreverb.com/terms/
28 contact:
29 name: Swagger API team
30 email: foo@example.com
31 url: http://swagger.io
32 license:
33 name: MIT
34 url: http://opensource.org/licenses/MIT
35 host: petstore.swagger.wordnik.com
36 basePath: /api
37 schemes:
38 - http
39 consumes:
40 - application/json
41 produces:
42 - application/json
43 paths:
44 /pets:
45 get:
46 description: Returns all pets from the system that the user has access to
47 operationId: findPets
48 produces:
49 - application/json
50 - application/xml
51 - text/xml
52 - text/html
53 parameters:
54 - name: tags
55 in: query
56 description: tags to filter by
57 required: false
58 type: array
59 items:
60 type: string
61 collectionFormat: csv
62 - name: limit
63 in: query
64 description: maximum number of results to return
65 required: false
66 type: integer
67 format: int32
68 responses:
69 '200':
70 description: pet response
71 schema:
72 type: array
73 items:
74 $ref: '#/definitions/pet'
75 default:
76 description: unexpected error
77 schema:
78 $ref: '#/definitions/errorModel'
79 post:
80 description: Creates a new pet in the store. Duplicates are allowed
81 operationId: addPet
82 produces:
83 - application/json
84 parameters:
85 - name: pet
86 in: body
87 description: Pet to add to the store
88 required: true
89 schema:
90 $ref: '#/definitions/newPet'
91 responses:
92 '200':
93 description: pet response
94 schema:
95 $ref: '#/definitions/pet'
96 default:
97 description: unexpected error
98 schema:
99 $ref: '#/definitions/errorModel'
100 /pets/{id}:
101 get:
102 description: Returns a user based on a single ID, if the user does not have access to the pet
103 operationId: findPetById
104 produces:
105 - application/json
106 - application/xml
107 - text/xml
108 - text/html
109 parameters:
110 - name: id
111 in: path
112 description: ID of pet to fetch
113 required: true
114 type: integer
115 format: int64
116 responses:
117 '200':
118 description: pet response
119 schema:
120 $ref: '#/definitions/pet'
121 default:
122 description: unexpected error
123 schema:
124 $ref: '#/definitions/errorModel'
125 delete:
126 description: deletes a single pet based on the ID supplied
127 operationId: deletePet
128 parameters:
129 - name: id
130 in: path
131 description: ID of pet to delete
132 required: true
133 type: integer
134 format: int64
135 responses:
136 '204':
137 description: pet deleted
138 default:
139 description: unexpected error
140 schema:
141 $ref: '#/definitions/errorModel'
142 definitions:
143 pet:
144 required:
145 - id
146 - name
147 properties:
148 id:
149 type: integer
150 format: int64
151 name:
152 type: string
153 tag:
154 type: string
155 newPet:
156 allOf:
157 - $ref: '#/definitions/pet'
158 - required:
159 - name
160 properties:
161 id:
162 type: integer
163 format: int64
164 name:
165 type: string
166 errorModel:
167 required:
168 - code
169 - message
170 properties:
171 code:
172 type: integer
173 format: int32
174 message:
175 type: string
176 `
177
178
179 const PetStore20 = `{
180 "swagger": "2.0",
181 "info": {
182 "version": "1.0.0",
183 "title": "Swagger Petstore",
184 "contact": {
185 "name": "Wordnik API Team",
186 "url": "http://developer.wordnik.com"
187 },
188 "license": {
189 "name": "Creative Commons 4.0 International",
190 "url": "http://creativecommons.org/licenses/by/4.0/"
191 }
192 },
193 "host": "petstore.swagger.wordnik.com",
194 "basePath": "/api",
195 "schemes": [
196 "http"
197 ],
198 "paths": {
199 "/pets": {
200 "get": {
201 "security": [
202 {
203 "basic": []
204 }
205 ],
206 "tags": [ "Pet Operations" ],
207 "operationId": "getAllPets",
208 "parameters": [
209 {
210 "name": "status",
211 "in": "query",
212 "description": "The status to filter by",
213 "type": "string"
214 },
215 {
216 "name": "limit",
217 "in": "query",
218 "description": "The maximum number of results to return",
219 "type": "integer",
220 "format": "int64"
221 }
222 ],
223 "summary": "Finds all pets in the system",
224 "responses": {
225 "200": {
226 "description": "Pet response",
227 "schema": {
228 "type": "array",
229 "items": {
230 "$ref": "#/definitions/Pet"
231 }
232 }
233 },
234 "default": {
235 "description": "Unexpected error",
236 "schema": {
237 "$ref": "#/definitions/Error"
238 }
239 }
240 }
241 },
242 "post": {
243 "security": [
244 {
245 "basic": []
246 }
247 ],
248 "tags": [ "Pet Operations" ],
249 "operationId": "createPet",
250 "summary": "Creates a new pet",
251 "consumes": ["application/x-yaml"],
252 "produces": ["application/x-yaml"],
253 "parameters": [
254 {
255 "name": "pet",
256 "in": "body",
257 "description": "The Pet to create",
258 "required": true,
259 "schema": {
260 "$ref": "#/definitions/newPet"
261 }
262 }
263 ],
264 "responses": {
265 "200": {
266 "description": "Created Pet response",
267 "schema": {
268 "$ref": "#/definitions/Pet"
269 }
270 },
271 "default": {
272 "description": "Unexpected error",
273 "schema": {
274 "$ref": "#/definitions/Error"
275 }
276 }
277 }
278 }
279 },
280 "/pets/{id}": {
281 "delete": {
282 "security": [
283 {
284 "apiKey": []
285 }
286 ],
287 "description": "Deletes the Pet by id",
288 "operationId": "deletePet",
289 "parameters": [
290 {
291 "name": "id",
292 "in": "path",
293 "description": "ID of pet to delete",
294 "required": true,
295 "type": "integer",
296 "format": "int64"
297 }
298 ],
299 "responses": {
300 "204": {
301 "description": "pet deleted"
302 },
303 "default": {
304 "description": "unexpected error",
305 "schema": {
306 "$ref": "#/definitions/Error"
307 }
308 }
309 }
310 },
311 "get": {
312 "tags": [ "Pet Operations" ],
313 "operationId": "getPetById",
314 "summary": "Finds the pet by id",
315 "responses": {
316 "200": {
317 "description": "Pet response",
318 "schema": {
319 "$ref": "#/definitions/Pet"
320 }
321 },
322 "default": {
323 "description": "Unexpected error",
324 "schema": {
325 "$ref": "#/definitions/Error"
326 }
327 }
328 }
329 },
330 "parameters": [
331 {
332 "name": "id",
333 "in": "path",
334 "description": "ID of pet",
335 "required": true,
336 "type": "integer",
337 "format": "int64"
338 }
339 ]
340 }
341 },
342 "definitions": {
343 "Category": {
344 "properties": {
345 "id": {
346 "format": "int64",
347 "type": "integer"
348 },
349 "name": {
350 "type": "string"
351 }
352 }
353 },
354 "Pet": {
355 "properties": {
356 "category": {
357 "$ref": "#/definitions/Category"
358 },
359 "id": {
360 "description": "unique identifier for the pet",
361 "format": "int64",
362 "maximum": 100.0,
363 "minimum": 0.0,
364 "type": "integer"
365 },
366 "name": {
367 "type": "string"
368 },
369 "photoUrls": {
370 "items": {
371 "type": "string"
372 },
373 "type": "array"
374 },
375 "status": {
376 "description": "pet status in the store",
377 "enum": [
378 "available",
379 "pending",
380 "sold"
381 ],
382 "type": "string"
383 },
384 "tags": {
385 "items": {
386 "$ref": "#/definitions/Tag"
387 },
388 "type": "array"
389 }
390 },
391 "required": [
392 "id",
393 "name"
394 ]
395 },
396 "newPet": {
397 "anyOf": [
398 {
399 "$ref": "#/definitions/Pet"
400 },
401 {
402 "required": [
403 "name"
404 ]
405 }
406 ]
407 },
408 "Tag": {
409 "properties": {
410 "id": {
411 "format": "int64",
412 "type": "integer"
413 },
414 "name": {
415 "type": "string"
416 }
417 }
418 },
419 "Error": {
420 "required": [
421 "code",
422 "message"
423 ],
424 "properties": {
425 "code": {
426 "type": "integer",
427 "format": "int32"
428 },
429 "message": {
430 "type": "string"
431 }
432 }
433 }
434 },
435 "consumes": [
436 "application/json",
437 "application/xml"
438 ],
439 "produces": [
440 "application/json",
441 "application/xml",
442 "text/plain",
443 "text/html"
444 ],
445 "securityDefinitions": {
446 "basic": {
447 "type": "basic"
448 },
449 "apiKey": {
450 "type": "apiKey",
451 "in": "header",
452 "name": "X-API-KEY"
453 }
454 }
455 }
456 `
457
458
459 const RootPetStore20 = `{
460 "swagger": "2.0",
461 "info": {
462 "version": "1.0.0",
463 "title": "Swagger Petstore",
464 "contact": {
465 "name": "Wordnik API Team",
466 "url": "http://developer.wordnik.com"
467 },
468 "license": {
469 "name": "Creative Commons 4.0 International",
470 "url": "http://creativecommons.org/licenses/by/4.0/"
471 }
472 },
473 "host": "petstore.swagger.wordnik.com",
474 "basePath": "/",
475 "schemes": [
476 "http"
477 ],
478 "paths": {
479 "/pets": {
480 "get": {
481 "security": [
482 {
483 "basic": []
484 }
485 ],
486 "tags": [ "Pet Operations" ],
487 "operationId": "getAllPets",
488 "parameters": [
489 {
490 "name": "status",
491 "in": "query",
492 "description": "The status to filter by",
493 "type": "string"
494 }
495 ],
496 "summary": "Finds all pets in the system",
497 "responses": {
498 "200": {
499 "description": "Pet response",
500 "schema": {
501 "type": "array",
502 "items": {
503 "$ref": "#/definitions/Pet"
504 }
505 }
506 },
507 "default": {
508 "description": "Unexpected error",
509 "schema": {
510 "$ref": "#/definitions/Error"
511 }
512 }
513 }
514 },
515 "post": {
516 "security": [
517 {
518 "basic": []
519 }
520 ],
521 "tags": [ "Pet Operations" ],
522 "operationId": "createPet",
523 "summary": "Creates a new pet",
524 "consumes": ["application/x-yaml"],
525 "produces": ["application/x-yaml"],
526 "parameters": [
527 {
528 "name": "pet",
529 "in": "body",
530 "description": "The Pet to create",
531 "required": true,
532 "schema": {
533 "$ref": "#/definitions/newPet"
534 }
535 }
536 ],
537 "responses": {
538 "200": {
539 "description": "Created Pet response",
540 "schema": {
541 "$ref": "#/definitions/Pet"
542 }
543 },
544 "default": {
545 "description": "Unexpected error",
546 "schema": {
547 "$ref": "#/definitions/Error"
548 }
549 }
550 }
551 }
552 },
553 "/pets/{id}": {
554 "delete": {
555 "security": [
556 {
557 "apiKey": []
558 }
559 ],
560 "description": "Deletes the Pet by id",
561 "operationId": "deletePet",
562 "parameters": [
563 {
564 "name": "id",
565 "in": "path",
566 "description": "ID of pet to delete",
567 "required": true,
568 "type": "integer",
569 "format": "int64"
570 }
571 ],
572 "responses": {
573 "204": {
574 "description": "pet deleted"
575 },
576 "default": {
577 "description": "unexpected error",
578 "schema": {
579 "$ref": "#/definitions/Error"
580 }
581 }
582 }
583 },
584 "get": {
585 "tags": [ "Pet Operations" ],
586 "operationId": "getPetById",
587 "summary": "Finds the pet by id",
588 "responses": {
589 "200": {
590 "description": "Pet response",
591 "schema": {
592 "$ref": "#/definitions/Pet"
593 }
594 },
595 "default": {
596 "description": "Unexpected error",
597 "schema": {
598 "$ref": "#/definitions/Error"
599 }
600 }
601 }
602 },
603 "parameters": [
604 {
605 "name": "id",
606 "in": "path",
607 "description": "ID of pet",
608 "required": true,
609 "type": "integer",
610 "format": "int64"
611 }
612 ]
613 }
614 },
615 "definitions": {
616 "Category": {
617 "properties": {
618 "id": {
619 "format": "int64",
620 "type": "integer"
621 },
622 "name": {
623 "type": "string"
624 }
625 }
626 },
627 "Pet": {
628 "properties": {
629 "category": {
630 "$ref": "#/definitions/Category"
631 },
632 "id": {
633 "description": "unique identifier for the pet",
634 "format": "int64",
635 "maximum": 100.0,
636 "minimum": 0.0,
637 "type": "integer"
638 },
639 "name": {
640 "type": "string"
641 },
642 "photoUrls": {
643 "items": {
644 "type": "string"
645 },
646 "type": "array"
647 },
648 "status": {
649 "description": "pet status in the store",
650 "enum": [
651 "available",
652 "pending",
653 "sold"
654 ],
655 "type": "string"
656 },
657 "tags": {
658 "items": {
659 "$ref": "#/definitions/Tag"
660 },
661 "type": "array"
662 }
663 },
664 "required": [
665 "id",
666 "name"
667 ]
668 },
669 "newPet": {
670 "anyOf": [
671 {
672 "$ref": "#/definitions/Pet"
673 },
674 {
675 "required": [
676 "name"
677 ]
678 }
679 ]
680 },
681 "Tag": {
682 "properties": {
683 "id": {
684 "format": "int64",
685 "type": "integer"
686 },
687 "name": {
688 "type": "string"
689 }
690 }
691 },
692 "Error": {
693 "required": [
694 "code",
695 "message"
696 ],
697 "properties": {
698 "code": {
699 "type": "integer",
700 "format": "int32"
701 },
702 "message": {
703 "type": "string"
704 }
705 }
706 }
707 },
708 "consumes": [
709 "application/json",
710 "application/xml"
711 ],
712 "produces": [
713 "application/json",
714 "application/xml",
715 "text/plain",
716 "text/html"
717 ],
718 "securityDefinitions": {
719 "basic": {
720 "type": "basic"
721 },
722 "apiKey": {
723 "type": "apiKey",
724 "in": "header",
725 "name": "X-API-KEY"
726 }
727 }
728 }
729 `
730
731
732 var PetStoreJSONMessage = json.RawMessage([]byte(PetStore20))
733
734
735 var RootPetStoreJSONMessage = json.RawMessage([]byte(RootPetStore20))
736
737
738 const InvalidJSON = `{
739 "apiVersion": "1.0.0",
740 "apis": [
741 {
742 "description": "Operations about pets",
743 "path": "/pet"
744 },
745 {
746 "description": "Operations about user",
747 "path": "/user"
748 },
749 {
750 "description": "Operations about store",
751 "path": "/store"
752 }
753 ],
754 "authorizations": {
755 "oauth2": {
756 "grantTypes": {
757 "authorization_code": {
758 "tokenEndpoint": {
759 "tokenName": "auth_code",
760 "url": "http://petstore.swagger.wordnik.com/oauth/token"
761 },
762 "tokenRequestEndpoint": {
763 "clientIdName": "client_id",
764 "clientSecretName": "client_secret",
765 "url": "http://petstore.swagger.wordnik.com/oauth/requestToken"
766 }
767 },
768 "implicit": {
769 "loginEndpoint": {
770 "url": "http://petstore.swagger.wordnik.com/oauth/dialog"
771 },
772 "tokenName": "access_token"
773 }
774 },
775 "scopes": [
776 {
777 "description": "Modify pets in your account",
778 "scope": "write:pets"
779 },
780 {
781 "description": "Read your pets",
782 "scope": "read:pets"
783 },
784 {
785 "description": "Anything (testing)",
786 "scope": "test:anything"
787 }
788 ],
789 "type": "oauth2"
790 }
791 },
792 "info": {
793 "contact": "apiteam@wordnik.com",
794 "description": "This is a sample server Petstore server. You can find out more about Swagger \n at <a href=\"http://swagger.wordnik.com\">http://swagger.wordnik.com</a> or on irc.freenode.net, #swagger. For this sample,\n you can use the api key \"special-key\" to test the authorization filters",
795 "license": "Apache 2.0",
796 "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.html",
797 "termsOfServiceUrl": "http://helloreverb.com/terms/",
798 "title": "Swagger Sample App"
799 },
800 "swaggerVersion": "1.2"
801 }
802 `
803
804
805 var InvalidJSONMessage = json.RawMessage([]byte(InvalidJSON))
806
View as plain text