git.iko.soy/typeable/openapi3
on 29f720f help sign in
typeable/openapi3/test/Data/SwaggerSpec.hs
1661 lines 47 kB history raw
1{-# LANGUAGE OverloadedLists #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE QuasiQuotes #-}
5module Data.SwaggerSpec where
7import Prelude ()
8import Prelude.Compat
10import Control.Lens
12import Data.Aeson
13import Data.Aeson.QQ.Simple
14import Data.HashMap.Strict (HashMap)
15import qualified Data.Set as Set
16import Data.Text (Text)
18import Data.Swagger
19import SpecCommon
20import Test.Hspec hiding (example)
22spec :: Spec
23spec = do
24 describe "host" $ do
25 it "can decode the host port" $ do
26 let h = Just $ Host "localhost" (Just (fromInteger 8000))
27 swagger :: Swagger
28 swagger = swaggerExample
29 & host .~ h
30 parsed :: Swagger = either error id $ eitherDecode' $ encode swagger
31 parsed ^. host `shouldBe` h
32 describe "License Object" $ licenseExample <=> licenseExampleJSON
33 describe "Contact Object" $ contactExample <=> contactExampleJSON
34 describe "Info Object" $ infoExample <=> infoExampleJSON
35 describe "Operation Object" $ operationExample <=> operationExampleJSON
36 describe "Schema Object" $ do
37 context "Primitive Sample" $ schemaPrimitiveExample <=> schemaPrimitiveExampleJSON
38 context "Simple Model" $ schemaSimpleModelExample <=> schemaSimpleModelExampleJSON
39 context "Model with Map/Dictionary Properties" $ schemaModelDictExample <=> schemaModelDictExampleJSON
40 context "Model with Arbitrary Properties" $ schemaAdditionalExample <=> schemaAdditionalExampleJSON
41 context "Model with Example" $ schemaWithExampleExample <=> schemaWithExampleExampleJSON
42 describe "Definitions Object" $ definitionsExample <=> definitionsExampleJSON
43 describe "Parameters Definition Object" $ paramsDefinitionExample <=> paramsDefinitionExampleJSON
44 describe "Responses Definition Object" $ responsesDefinitionExample <=> responsesDefinitionExampleJSON
45 describe "Security Definitions Object" $ securityDefinitionsExample <=> securityDefinitionsExampleJSON
46 describe "Composition Schema Example" $ compositionSchemaExample <=> compositionSchemaExampleJSON
47 describe "Swagger Object" $ do
48 context "Todo Example" $ swaggerExample <=> swaggerExampleJSON
49 context "PetStore Example" $
50 it "decodes successfully" $ do
51 fromJSON petstoreExampleJSON `shouldSatisfy` (\x -> case x of Success (_ :: Swagger) -> True; _ -> False)
53main :: IO ()
54main = hspec spec
56-- =======================================================================
57-- Info object
58-- =======================================================================
60infoExample :: Info
61infoExample = mempty
62 & title .~ "Swagger Sample App"
63 & description ?~ "This is a sample server Petstore server."
64 & termsOfService ?~ "http://swagger.io/terms/"
65 & contact ?~ contactExample
66 & license ?~ licenseExample
67 & version .~ "1.0.1"
69infoExampleJSON :: Value
70infoExampleJSON = [aesonQQ|
72 "title": "Swagger Sample App",
73 "description": "This is a sample server Petstore server.",
74 "termsOfService": "http://swagger.io/terms/",
75 "contact": {
76 "name": "API Support",
77 "url": "http://www.swagger.io/support",
78 "email": "support@swagger.io"
79 },
80 "license": {
81 "name": "Apache 2.0",
82 "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
83 },
84 "version": "1.0.1"
86|]
88-- =======================================================================
89-- Contact object
90-- =======================================================================
92contactExample :: Contact
93contactExample = mempty
94 & name ?~ "API Support"
95 & url ?~ URL "http://www.swagger.io/support"
96 & email ?~ "support@swagger.io"
98contactExampleJSON :: Value
99contactExampleJSON = [aesonQQ|
101 "name": "API Support",
102 "url": "http://www.swagger.io/support",
103 "email": "support@swagger.io"
105|]
107-- =======================================================================
108-- License object
109-- =======================================================================
111licenseExample :: License
112licenseExample = "Apache 2.0"
113 & url ?~ URL "http://www.apache.org/licenses/LICENSE-2.0.html"
115licenseExampleJSON :: Value
116licenseExampleJSON = [aesonQQ|
118 "name": "Apache 2.0",
119 "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
121|]
124-- =======================================================================
125-- Operation object
126-- =======================================================================
128operationExample :: Operation
129operationExample = mempty
130 & tags .~ Set.fromList ["pet"]
131 & summary ?~ "Updates a pet in the store with form data"
132 & description ?~ ""
133 & operationId ?~ "updatePetWithForm"
134 & consumes ?~ MimeList ["application/x-www-form-urlencoded"]
135 & produces ?~ MimeList ["application/json", "application/xml"]
136 & parameters .~ map Inline
137 [ mempty
138 & name .~ "petId"
139 & description ?~ "ID of pet that needs to be updated"
140 & required ?~ True
141 & schema .~ ParamOther (stringSchema ParamPath)
142 , mempty
143 & name .~ "name"
144 & description ?~ "Updated name of the pet"
145 & required ?~ False
146 & schema .~ ParamOther (stringSchema ParamFormData)
147 , mempty
148 & name .~ "status"
149 & description ?~ "Updated status of the pet"
150 & required ?~ False
151 & schema .~ ParamOther (stringSchema ParamFormData)
152 ]
154 & at 200 ?~ "Pet updated."
155 & at 405 ?~ "Invalid input"
156 & security .~ [SecurityRequirement [("petstore_auth", ["write:pets", "read:pets"])]]
157 where
158 stringSchema :: ParamLocation -> ParamOtherSchema
159 stringSchema loc = mempty
160 & in_ .~ loc
161 & type_ .~ SwaggerString
163operationExampleJSON :: Value
164operationExampleJSON = [aesonQQ|
166 "tags": [
167 "pet"
168 ],
169 "summary": "Updates a pet in the store with form data",
170 "description": "",
171 "operationId": "updatePetWithForm",
172 "consumes": [
173 "application/x-www-form-urlencoded"
174 ],
175 "produces": [
176 "application/json",
177 "application/xml"
178 ],
179 "parameters": [
180 {
181 "name": "petId",
182 "in": "path",
183 "description": "ID of pet that needs to be updated",
184 "required": true,
185 "type": "string"
186 },
187 {
188 "name": "name",
189 "in": "formData",
190 "description": "Updated name of the pet",
191 "required": false,
192 "type": "string"
193 },
194 {
195 "name": "status",
196 "in": "formData",
197 "description": "Updated status of the pet",
198 "required": false,
199 "type": "string"
200 }
201 ],
202 "responses": {
203 "200": {
204 "description": "Pet updated."
205 },
206 "405": {
207 "description": "Invalid input"
208 }
209 },
210 "security": [
211 {
212 "petstore_auth": [
213 "write:pets",
214 "read:pets"
215 ]
216 }
217 ]
219|]
221-- =======================================================================
222-- Schema object
223-- =======================================================================
225schemaPrimitiveExample :: Schema
226schemaPrimitiveExample = mempty
227 & type_ .~ SwaggerString
228 & format ?~ "email"
230schemaPrimitiveExampleJSON :: Value
231schemaPrimitiveExampleJSON = [aesonQQ|
233 "type": "string",
234 "format": "email"
236|]
238schemaSimpleModelExample :: Schema
239schemaSimpleModelExample = mempty
240 & type_ .~ SwaggerObject
241 & required .~ [ "name" ]
242 & properties .~
243 [ ("name", Inline (mempty & type_ .~ SwaggerString))
244 , ("address", Ref (Reference "Address"))
245 , ("age", Inline $ mempty
246 & minimum_ ?~ 0
247 & type_ .~ SwaggerInteger
248 & format ?~ "int32" ) ]
250schemaSimpleModelExampleJSON :: Value
251schemaSimpleModelExampleJSON = [aesonQQ|
253 "type": "object",
254 "required": [
255 "name"
256 ],
257 "properties": {
258 "name": {
259 "type": "string"
260 },
261 "address": {
262 "$ref": "#/definitions/Address"
263 },
264 "age": {
265 "type": "integer",
266 "format": "int32",
267 "minimum": 0
268 }
269 }
271|]
273schemaModelDictExample :: Schema
274schemaModelDictExample = mempty
275 & type_ .~ SwaggerObject
276 & additionalProperties ?~ AdditionalPropertiesSchema (Inline (mempty & type_ .~ SwaggerString))
278schemaModelDictExampleJSON :: Value
279schemaModelDictExampleJSON = [aesonQQ|
281 "type": "object",
282 "additionalProperties": {
283 "type": "string"
284 }
286|]
288schemaAdditionalExample :: Schema
289schemaAdditionalExample = mempty
290 & type_ .~ SwaggerObject
291 & additionalProperties ?~ AdditionalPropertiesAllowed True
293schemaAdditionalExampleJSON :: Value
294schemaAdditionalExampleJSON = [aesonQQ|
296 "type": "object",
297 "additionalProperties": true
299|]
301schemaWithExampleExample :: Schema
302schemaWithExampleExample = mempty
303 & type_ .~ SwaggerObject
304 & properties .~
305 [ ("id", Inline $ mempty
306 & type_ .~ SwaggerInteger
307 & format ?~ "int64" )
308 , ("name", Inline $ mempty
309 & type_ .~ SwaggerString) ]
310 & required .~ [ "name" ]
311 & example ?~ [aesonQQ|
312 {
313 "name": "Puma",
314 "id": 1
315 }
316 |]
318schemaWithExampleExampleJSON :: Value
319schemaWithExampleExampleJSON = [aesonQQ|
321 "type": "object",
322 "properties": {
323 "id": {
324 "type": "integer",
325 "format": "int64"
326 },
327 "name": {
328 "type": "string"
329 }
330 },
331 "required": [
332 "name"
333 ],
334 "example": {
335 "name": "Puma",
336 "id": 1
337 }
339|]
341-- =======================================================================
342-- Definitions object
343-- =======================================================================
345definitionsExample :: HashMap Text Schema
346definitionsExample =
347 [ ("Category", mempty
348 & type_ .~ SwaggerObject
349 & properties .~
350 [ ("id", Inline $ mempty
351 & type_ .~ SwaggerInteger
352 & format ?~ "int64")
353 , ("name", Inline (mempty & type_ .~ SwaggerString)) ] )
354 , ("Tag", mempty
355 & type_ .~ SwaggerObject
356 & properties .~
357 [ ("id", Inline $ mempty
358 & type_ .~ SwaggerInteger
359 & format ?~ "int64")
360 , ("name", Inline (mempty & type_ .~ SwaggerString)) ] ) ]
362definitionsExampleJSON :: Value
363definitionsExampleJSON = [aesonQQ|
365 "Category": {
366 "type": "object",
367 "properties": {
368 "id": {
369 "type": "integer",
370 "format": "int64"
371 },
372 "name": {
373 "type": "string"
374 }
375 }
376 },
377 "Tag": {
378 "type": "object",
379 "properties": {
380 "id": {
381 "type": "integer",
382 "format": "int64"
383 },
384 "name": {
385 "type": "string"
386 }
387 }
388 }
390|]
392-- =======================================================================
393-- Parameters Definition object
394-- =======================================================================
396paramsDefinitionExample :: HashMap Text Param
397paramsDefinitionExample =
398 [ ("skipParam", mempty
399 & name .~ "skip"
400 & description ?~ "number of items to skip"
401 & required ?~ True
402 & schema .~ ParamOther (mempty
403 & in_ .~ ParamQuery
404 & type_ .~ SwaggerInteger
405 & format ?~ "int32" ))
406 , ("limitParam", mempty
407 & name .~ "limit"
408 & description ?~ "max records to return"
409 & required ?~ True
410 & schema .~ ParamOther (mempty
411 & in_ .~ ParamQuery
412 & type_ .~ SwaggerInteger
413 & format ?~ "int32" )) ]
415paramsDefinitionExampleJSON :: Value
416paramsDefinitionExampleJSON = [aesonQQ|
418 "skipParam": {
419 "name": "skip",
420 "in": "query",
421 "description": "number of items to skip",
422 "required": true,
423 "type": "integer",
424 "format": "int32"
425 },
426 "limitParam": {
427 "name": "limit",
428 "in": "query",
429 "description": "max records to return",
430 "required": true,
431 "type": "integer",
432 "format": "int32"
433 }
435|]
437-- =======================================================================
438-- Responses Definition object
439-- =======================================================================
441responsesDefinitionExample :: HashMap Text Response
442responsesDefinitionExample =
443 [ ("NotFound", mempty & description .~ "Entity not found.")
444 , ("IllegalInput", mempty & description .~ "Illegal input for operation.") ]
446responsesDefinitionExampleJSON :: Value
447responsesDefinitionExampleJSON = [aesonQQ|
449 "NotFound": {
450 "description": "Entity not found."
451 },
452 "IllegalInput": {
453 "description": "Illegal input for operation."
454 }
456|]
458-- =======================================================================
459-- Responses Definition object
460-- =======================================================================
462securityDefinitionsExample :: HashMap Text SecurityScheme
463securityDefinitionsExample =
464 [ ("api_key", SecurityScheme
465 { _securitySchemeType = SecuritySchemeApiKey (ApiKeyParams "api_key" ApiKeyHeader)
466 , _securitySchemeDescription = Nothing })
467 , ("petstore_auth", SecurityScheme
468 { _securitySchemeType = SecuritySchemeOAuth2 (OAuth2Params
469 { _oauth2Flow = OAuth2Implicit "http://swagger.io/api/oauth/dialog"
470 , _oauth2Scopes =
471 [ ("write:pets", "modify pets in your account")
472 , ("read:pets", "read your pets") ] } )
473 , _securitySchemeDescription = Nothing }) ]
475securityDefinitionsExampleJSON :: Value
476securityDefinitionsExampleJSON = [aesonQQ|
478 "api_key": {
479 "type": "apiKey",
480 "name": "api_key",
481 "in": "header"
482 },
483 "petstore_auth": {
484 "type": "oauth2",
485 "authorizationUrl": "http://swagger.io/api/oauth/dialog",
486 "flow": "implicit",
487 "scopes": {
488 "write:pets": "modify pets in your account",
489 "read:pets": "read your pets"
490 }
491 }
493|]
495-- =======================================================================
496-- Swagger object
497-- =======================================================================
499swaggerExample :: Swagger
500swaggerExample = mempty
501 & basePath ?~ "/"
502 & schemes ?~ [Http]
503 & info .~ (mempty
504 & version .~ "1.0"
505 & title .~ "Todo API"
506 & license ?~ "MIT"
507 & license._Just.url ?~ URL "http://mit.com"
508 & description ?~ "This is a an API that tests servant-swagger support for a Todo API")
509 & paths.at "/todo/{id}" ?~ (mempty & get ?~ ((mempty :: Operation)
510 & at 200 ?~ Inline (mempty
511 & description .~ "OK"
512 & schema ?~ Inline (mempty
513 & type_ .~ SwaggerObject
514 & example ?~ [aesonQQ|
515 {
516 "created": 100,
517 "description": "get milk"
518 } |]
519 & description ?~ "This is some real Todo right here"
520 & properties .~
521 [ ("created", Inline $ mempty
522 & type_ .~ SwaggerInteger
523 & format ?~ "int32")
524 , ("description", Inline (mempty & type_ .~ SwaggerString))]))
525 & produces ?~ MimeList [ "application/json" ]
526 & parameters .~
527 [ Inline $ mempty
528 & required ?~ True
529 & name .~ "id"
530 & description ?~ "TodoId param"
531 & schema .~ ParamOther (mempty
532 & in_ .~ ParamPath
533 & type_ .~ SwaggerString ) ]
534 & tags .~ Set.fromList [ "todo" ] ))
536swaggerExampleJSON :: Value
537swaggerExampleJSON = [aesonQQ|
539 "swagger": "2.0",
540 "basePath": "/",
541 "schemes": [
542 "http"
543 ],
544 "info": {
545 "version": "1.0",
546 "title": "Todo API",
547 "license": {
548 "url": "http://mit.com",
549 "name": "MIT"
550 },
551 "description": "This is a an API that tests servant-swagger support for a Todo API"
552 },
553 "paths": {
554 "/todo/{id}": {
555 "get": {
556 "responses": {
557 "200": {
558 "schema": {
559 "example": {
560 "created": 100,
561 "description": "get milk"
562 },
563 "type": "object",
564 "description": "This is some real Todo right here",
565 "properties": {
566 "created": {
567 "format": "int32",
568 "type": "integer"
569 },
570 "description": {
571 "type": "string"
572 }
573 }
574 },
575 "description": "OK"
576 }
577 },
578 "produces": [
579 "application/json"
580 ],
581 "parameters": [
582 {
583 "required": true,
584 "in": "path",
585 "name": "id",
586 "type": "string",
587 "description": "TodoId param"
588 }
589 ],
590 "tags": [
591 "todo"
592 ]
593 }
594 }
595 }
597|]
599petstoreExampleJSON :: Value
600petstoreExampleJSON = [aesonQQ|
602 "swagger":"2.0",
603 "info":{
604 "description":"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",
605 "version":"1.0.0",
606 "title":"Swagger Petstore",
607 "termsOfService":"http://swagger.io/terms/",
608 "contact":{
609 "email":"apiteam@swagger.io"
610 },
611 "license":{
612 "name":"Apache 2.0",
613 "url":"http://www.apache.org/licenses/LICENSE-2.0.html"
614 }
615 },
616 "host":"petstore.swagger.io",
617 "basePath":"/v2",
618 "tags":[
619 {
620 "name":"pet",
621 "description":"Everything about your Pets",
622 "externalDocs":{
623 "description":"Find out more",
624 "url":"http://swagger.io"
625 }
626 },
627 {
628 "name":"store",
629 "description":"Access to Petstore orders"
630 },
631 {
632 "name":"user",
633 "description":"Operations about user",
634 "externalDocs":{
635 "description":"Find out more about our store",
636 "url":"http://swagger.io"
637 }
638 }
639 ],
640 "schemes":[
641 "http"
642 ],
643 "paths":{
644 "/pet":{
645 "post":{
646 "tags":[
647 "pet"
648 ],
649 "summary":"Add a new pet to the store",
650 "description":"",
651 "operationId":"addPet",
652 "consumes":[
653 "application/json",
654 "application/xml"
655 ],
656 "produces":[
657 "application/xml",
658 "application/json"
659 ],
660 "parameters":[
661 {
662 "in":"body",
663 "name":"body",
664 "description":"Pet object that needs to be added to the store",
665 "required":true,
666 "schema":{
667 "$ref":"#/definitions/Pet"
668 }
669 }
670 ],
671 "responses":{
672 "405":{
673 "description":"Invalid input"
674 }
675 },
676 "security":[
677 {
678 "petstore_auth":[
679 "write:pets",
680 "read:pets"
681 ]
682 }
683 ]
684 },
685 "put":{
686 "tags":[
687 "pet"
688 ],
689 "summary":"Update an existing pet",
690 "description":"",
691 "operationId":"updatePet",
692 "consumes":[
693 "application/json",
694 "application/xml"
695 ],
696 "produces":[
697 "application/xml",
698 "application/json"
699 ],
700 "parameters":[
701 {
702 "in":"body",
703 "name":"body",
704 "description":"Pet object that needs to be added to the store",
705 "required":true,
706 "schema":{
707 "$ref":"#/definitions/Pet"
708 }
709 }
710 ],
711 "responses":{
712 "400":{
713 "description":"Invalid ID supplied"
714 },
715 "404":{
716 "description":"Pet not found"
717 },
718 "405":{
719 "description":"Validation exception"
720 }
721 },
722 "security":[
723 {
724 "petstore_auth":[
725 "write:pets",
726 "read:pets"
727 ]
728 }
729 ]
730 }
731 },
732 "/pet/findByStatus":{
733 "get":{
734 "tags":[
735 "pet"
736 ],
737 "summary":"Finds Pets by status",
738 "description":"Multiple status values can be provided with comma seperated strings",
739 "operationId":"findPetsByStatus",
740 "produces":[
741 "application/xml",
742 "application/json"
743 ],
744 "parameters":[
745 {
746 "name":"status",
747 "in":"query",
748 "description":"Status values that need to be considered for filter",
749 "required":true,
750 "type":"array",
751 "items":{
752 "type":"string",
753 "enum":[
754 "available",
755 "pending",
756 "sold"
757 ],
758 "default":"available"
759 },
760 "collectionFormat":"csv"
761 }
762 ],
763 "responses":{
764 "200":{
765 "description":"successful operation",
766 "schema":{
767 "type":"array",
768 "items":{
769 "$ref":"#/definitions/Pet"
770 }
771 }
772 },
773 "400":{
774 "description":"Invalid status value"
775 }
776 },
777 "security":[
778 {
779 "petstore_auth":[
780 "write:pets",
781 "read:pets"
782 ]
783 }
784 ]
785 }
786 },
787 "/pet/findByTags":{
788 "get":{
789 "tags":[
790 "pet"
791 ],
792 "summary":"Finds Pets by tags",
793 "description":"Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
794 "operationId":"findPetsByTags",
795 "produces":[
796 "application/xml",
797 "application/json"
798 ],
799 "parameters":[
800 {
801 "name":"tags",
802 "in":"query",
803 "description":"Tags to filter by",
804 "required":true,
805 "type":"array",
806 "items":{
807 "type":"string"
808 },
809 "collectionFormat":"csv"
810 }
811 ],
812 "responses":{
813 "200":{
814 "description":"successful operation",
815 "schema":{
816 "type":"array",
817 "items":{
818 "$ref":"#/definitions/Pet"
819 }
820 }
821 },
822 "400":{
823 "description":"Invalid tag value"
824 }
825 },
826 "security":[
827 {
828 "petstore_auth":[
829 "write:pets",
830 "read:pets"
831 ]
832 }
833 ]
834 }
835 },
836 "/pet/{petId}":{
837 "get":{
838 "tags":[
839 "pet"
840 ],
841 "summary":"Find pet by ID",
842 "description":"Returns a single pet",
843 "operationId":"getPetById",
844 "produces":[
845 "application/xml",
846 "application/json"
847 ],
848 "parameters":[
849 {
850 "name":"petId",
851 "in":"path",
852 "description":"ID of pet to return",
853 "required":true,
854 "type":"integer",
855 "format":"int64"
856 }
857 ],
858 "responses":{
859 "200":{
860 "description":"successful operation",
861 "schema":{
862 "$ref":"#/definitions/Pet"
863 }
864 },
865 "400":{
866 "description":"Invalid ID supplied"
867 },
868 "404":{
869 "description":"Pet not found"
870 }
871 },
872 "security":[
873 {
874 "api_key": []
875 }
876 ]
877 },
878 "post":{
879 "tags":[
880 "pet"
881 ],
882 "summary":"Updates a pet in the store with form data",
883 "description":"",
884 "operationId":"updatePetWithForm",
885 "consumes":[
886 "application/x-www-form-urlencoded"
887 ],
888 "produces":[
889 "application/xml",
890 "application/json"
891 ],
892 "parameters":[
893 {
894 "name":"petId",
895 "in":"path",
896 "description":"ID of pet that needs to be updated",
897 "required":true,
898 "type":"integer",
899 "format":"int64"
900 },
901 {
902 "name":"name",
903 "in":"formData",
904 "description":"Updated name of the pet",
905 "required":false,
906 "type":"string"
907 },
908 {
909 "name":"status",
910 "in":"formData",
911 "description":"Updated status of the pet",
912 "required":false,
913 "type":"string"
914 }
915 ],
916 "responses":{
917 "405":{
918 "description":"Invalid input"
919 }
920 },
921 "security":[
922 {
923 "petstore_auth":[
924 "write:pets",
925 "read:pets"
926 ]
927 }
928 ]
929 },
930 "delete":{
931 "tags":[
932 "pet"
933 ],
934 "summary":"Deletes a pet",
935 "description":"",
936 "operationId":"deletePet",
937 "produces":[
938 "application/xml",
939 "application/json"
940 ],
941 "parameters":[
942 {
943 "name":"api_key",
944 "in":"header",
945 "required":false,
946 "type":"string"
947 },
948 {
949 "name":"petId",
950 "in":"path",
951 "description":"Pet id to delete",
952 "required":true,
953 "type":"integer",
954 "format":"int64"
955 }
956 ],
957 "responses":{
958 "400":{
959 "description":"Invalid pet value"
960 }
961 },
962 "security":[
963 {
964 "petstore_auth":[
965 "write:pets",
966 "read:pets"
967 ]
968 }
969 ]
970 }
971 },
972 "/pet/{petId}/uploadImage":{
973 "post":{
974 "tags":[
975 "pet"
976 ],
977 "summary":"uploads an image",
978 "description":"",
979 "operationId":"uploadFile",
980 "consumes":[
981 "multipart/form-data"
982 ],
983 "produces":[
984 "application/json"
985 ],
986 "parameters":[
987 {
988 "name":"petId",
989 "in":"path",
990 "description":"ID of pet to update",
991 "required":true,
992 "type":"integer",
993 "format":"int64"
994 },
995 {
996 "name":"additionalMetadata",
997 "in":"formData",
998 "description":"Additional data to pass to server",
999 "required":false,
1000 "type":"string"
1001 },
1003 "name":"file",
1004 "in":"formData",
1005 "description":"file to upload",
1006 "required":false,
1007 "type":"file"
1009 ],
1010 "responses":{
1011 "200":{
1012 "description":"successful operation",
1013 "schema":{
1014 "$ref":"#/definitions/ApiResponse"
1017 },
1018 "security":[
1020 "petstore_auth":[
1021 "write:pets",
1022 "read:pets"
1027 },
1028 "/store/inventory":{
1029 "get":{
1030 "tags":[
1031 "store"
1032 ],
1033 "summary":"Returns pet inventories by status",
1034 "description":"Returns a map of status codes to quantities",
1035 "operationId":"getInventory",
1036 "produces":[
1037 "application/json"
1038 ],
1039 "parameters": [],
1040 "responses":{
1041 "200":{
1042 "description":"successful operation",
1043 "schema":{
1044 "type":"object",
1045 "additionalProperties":{
1046 "type":"integer",
1047 "format":"int32"
1051 },
1052 "security":[
1054 "api_key": []
1058 },
1059 "/store/order":{
1060 "post":{
1061 "tags":[
1062 "store"
1063 ],
1064 "summary":"Place an order for a pet",
1065 "description":"",
1066 "operationId":"placeOrder",
1067 "produces":[
1068 "application/xml",
1069 "application/json"
1070 ],
1071 "parameters":[
1073 "in":"body",
1074 "name":"body",
1075 "description":"order placed for purchasing the pet",
1076 "required":true,
1077 "schema":{
1078 "$ref":"#/definitions/Order"
1081 ],
1082 "responses":{
1083 "200":{
1084 "description":"successful operation",
1085 "schema":{
1086 "$ref":"#/definitions/Order"
1088 },
1089 "400":{
1090 "description":"Invalid Order"
1094 },
1095 "/store/order/{orderId}":{
1096 "get":{
1097 "tags":[
1098 "store"
1099 ],
1100 "summary":"Find purchase order by ID",
1101 "description":"For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
1102 "operationId":"getOrderById",
1103 "produces":[
1104 "application/xml",
1105 "application/json"
1106 ],
1107 "parameters":[
1109 "name":"orderId",
1110 "in":"path",
1111 "description":"ID of pet that needs to be fetched",
1112 "required":true,
1113 "type":"integer",
1114 "maximum":5.0,
1115 "minimum":1.0,
1116 "format":"int64"
1118 ],
1119 "responses":{
1120 "200":{
1121 "description":"successful operation",
1122 "schema":{
1123 "$ref":"#/definitions/Order"
1125 },
1126 "400":{
1127 "description":"Invalid ID supplied"
1128 },
1129 "404":{
1130 "description":"Order not found"
1133 },
1134 "delete":{
1135 "tags":[
1136 "store"
1137 ],
1138 "summary":"Delete purchase order by ID",
1139 "description":"For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
1140 "operationId":"deleteOrder",
1141 "produces":[
1142 "application/xml",
1143 "application/json"
1144 ],
1145 "parameters":[
1147 "name":"orderId",
1148 "in":"path",
1149 "description":"ID of the order that needs to be deleted",
1150 "required":true,
1151 "type":"string",
1152 "minimum":1.0
1154 ],
1155 "responses":{
1156 "400":{
1157 "description":"Invalid ID supplied"
1158 },
1159 "404":{
1160 "description":"Order not found"
1164 },
1165 "/user":{
1166 "post":{
1167 "tags":[
1168 "user"
1169 ],
1170 "summary":"Create user",
1171 "description":"This can only be done by the logged in user.",
1172 "operationId":"createUser",
1173 "produces":[
1174 "application/xml",
1175 "application/json"
1176 ],
1177 "parameters":[
1179 "in":"body",
1180 "name":"body",
1181 "description":"Created user object",
1182 "required":true,
1183 "schema":{
1184 "$ref":"#/definitions/User"
1187 ],
1188 "responses":{
1189 "default":{
1190 "description":"successful operation"
1194 },
1195 "/user/createWithArray":{
1196 "post":{
1197 "tags":[
1198 "user"
1199 ],
1200 "summary":"Creates list of users with given input array",
1201 "description":"",
1202 "operationId":"createUsersWithArrayInput",
1203 "produces":[
1204 "application/xml",
1205 "application/json"
1206 ],
1207 "parameters":[
1209 "in":"body",
1210 "name":"body",
1211 "description":"List of user object",
1212 "required":true,
1213 "schema":{
1214 "type":"array",
1215 "items":{
1216 "$ref":"#/definitions/User"
1220 ],
1221 "responses":{
1222 "default":{
1223 "description":"successful operation"
1227 },
1228 "/user/createWithList":{
1229 "post":{
1230 "tags":[
1231 "user"
1232 ],
1233 "summary":"Creates list of users with given input array",
1234 "description":"",
1235 "operationId":"createUsersWithListInput",
1236 "produces":[
1237 "application/xml",
1238 "application/json"
1239 ],
1240 "parameters":[
1242 "in":"body",
1243 "name":"body",
1244 "description":"List of user object",
1245 "required":true,
1246 "schema":{
1247 "type":"array",
1248 "items":{
1249 "$ref":"#/definitions/User"
1253 ],
1254 "responses":{
1255 "default":{
1256 "description":"successful operation"
1260 },
1261 "/user/login":{
1262 "get":{
1263 "tags":[
1264 "user"
1265 ],
1266 "summary":"Logs user into the system",
1267 "description":"",
1268 "operationId":"loginUser",
1269 "produces":[
1270 "application/xml",
1271 "application/json"
1272 ],
1273 "parameters":[
1275 "name":"username",
1276 "in":"query",
1277 "description":"The user name for login",
1278 "required":true,
1279 "type":"string"
1280 },
1282 "name":"password",
1283 "in":"query",
1284 "description":"The password for login in clear text",
1285 "required":true,
1286 "type":"string"
1288 ],
1289 "responses":{
1290 "200":{
1291 "description":"successful operation",
1292 "schema":{
1293 "type":"string"
1294 },
1295 "headers":{
1296 "X-Rate-Limit":{
1297 "type":"integer",
1298 "format":"int32",
1299 "description":"calls per hour allowed by the user"
1300 },
1301 "X-Expires-After":{
1302 "type":"string",
1303 "format":"date-time",
1304 "description":"date in UTC when toekn expires"
1307 },
1308 "400":{
1309 "description":"Invalid username/password supplied"
1313 },
1314 "/user/logout":{
1315 "get":{
1316 "tags":[
1317 "user"
1318 ],
1319 "summary":"Logs out current logged in user session",
1320 "description":"",
1321 "operationId":"logoutUser",
1322 "produces":[
1323 "application/xml",
1324 "application/json"
1325 ],
1326 "parameters": [],
1327 "responses":{
1328 "default":{
1329 "description":"successful operation"
1333 },
1334 "/user/{username}":{
1335 "get":{
1336 "tags":[
1337 "user"
1338 ],
1339 "summary":"Get user by user name",
1340 "description":"",
1341 "operationId":"getUserByName",
1342 "produces":[
1343 "application/xml",
1344 "application/json"
1345 ],
1346 "parameters":[
1348 "name":"username",
1349 "in":"path",
1350 "description":"The name that needs to be fetched. Use user1 for testing. ",
1351 "required":true,
1352 "type":"string"
1354 ],
1355 "responses":{
1356 "200":{
1357 "description":"successful operation",
1358 "schema":{
1359 "$ref":"#/definitions/User"
1361 },
1362 "400":{
1363 "description":"Invalid username supplied"
1364 },
1365 "404":{
1366 "description":"User not found"
1369 },
1370 "put":{
1371 "tags":[
1372 "user"
1373 ],
1374 "summary":"Updated user",
1375 "description":"This can only be done by the logged in user.",
1376 "operationId":"updateUser",
1377 "produces":[
1378 "application/xml",
1379 "application/json"
1380 ],
1381 "parameters":[
1383 "name":"username",
1384 "in":"path",
1385 "description":"name that need to be deleted",
1386 "required":true,
1387 "type":"string"
1388 },
1390 "in":"body",
1391 "name":"body",
1392 "description":"Updated user object",
1393 "required":true,
1394 "schema":{
1395 "$ref":"#/definitions/User"
1398 ],
1399 "responses":{
1400 "400":{
1401 "description":"Invalid user supplied"
1402 },
1403 "404":{
1404 "description":"User not found"
1407 },
1408 "delete":{
1409 "tags":[
1410 "user"
1411 ],
1412 "summary":"Delete user",
1413 "description":"This can only be done by the logged in user.",
1414 "operationId":"deleteUser",
1415 "produces":[
1416 "application/xml",
1417 "application/json"
1418 ],
1419 "parameters":[
1421 "name":"username",
1422 "in":"path",
1423 "description":"The name that needs to be deleted",
1424 "required":true,
1425 "type":"string"
1427 ],
1428 "responses":{
1429 "400":{
1430 "description":"Invalid username supplied"
1431 },
1432 "404":{
1433 "description":"User not found"
1438 },
1439 "securityDefinitions":{
1440 "petstore_auth":{
1441 "type":"oauth2",
1442 "authorizationUrl":"http://petstore.swagger.io/api/oauth/dialog",
1443 "flow":"implicit",
1444 "scopes":{
1445 "write:pets":"modify pets in your account",
1446 "read:pets":"read your pets"
1448 },
1449 "api_key":{
1450 "type":"apiKey",
1451 "name":"api_key",
1452 "in":"header"
1454 },
1455 "definitions":{
1456 "Order":{
1457 "type":"object",
1458 "properties":{
1459 "id":{
1460 "type":"integer",
1461 "format":"int64"
1462 },
1463 "petId":{
1464 "type":"integer",
1465 "format":"int64"
1466 },
1467 "quantity":{
1468 "type":"integer",
1469 "format":"int32"
1470 },
1471 "shipDate":{
1472 "type":"string",
1473 "format":"date-time"
1474 },
1475 "status":{
1476 "type":"string",
1477 "description":"Order Status",
1478 "enum":[
1479 "placed",
1480 "approved",
1481 "delivered"
1483 },
1484 "complete":{
1485 "type":"boolean",
1486 "default":false
1488 },
1489 "xml":{
1490 "name":"Order"
1492 },
1493 "Category":{
1494 "type":"object",
1495 "properties":{
1496 "id":{
1497 "type":"integer",
1498 "format":"int64"
1499 },
1500 "name":{
1501 "type":"string"
1503 },
1504 "xml":{
1505 "name":"Category"
1507 },
1508 "User":{
1509 "type":"object",
1510 "properties":{
1511 "id":{
1512 "type":"integer",
1513 "format":"int64"
1514 },
1515 "username":{
1516 "type":"string"
1517 },
1518 "firstName":{
1519 "type":"string"
1520 },
1521 "lastName":{
1522 "type":"string"
1523 },
1524 "email":{
1525 "type":"string"
1526 },
1527 "password":{
1528 "type":"string"
1529 },
1530 "phone":{
1531 "type":"string"
1532 },
1533 "userStatus":{
1534 "type":"integer",
1535 "format":"int32",
1536 "description":"User Status"
1538 },
1539 "xml":{
1540 "name":"User"
1542 },
1543 "Tag":{
1544 "type":"object",
1545 "properties":{
1546 "id":{
1547 "type":"integer",
1548 "format":"int64"
1549 },
1550 "name":{
1551 "type":"string"
1553 },
1554 "xml":{
1555 "name":"Tag"
1557 },
1558 "Pet":{
1559 "type":"object",
1560 "required":[
1561 "name",
1562 "photoUrls"
1563 ],
1564 "properties":{
1565 "id":{
1566 "type":"integer",
1567 "format":"int64"
1568 },
1569 "category":{
1570 "$ref":"#/definitions/Category"
1571 },
1572 "name":{
1573 "type":"string",
1574 "example":"doggie"
1575 },
1576 "photoUrls":{
1577 "type":"array",
1578 "xml":{
1579 "name":"photoUrl",
1580 "wrapped":true
1581 },
1582 "items":{
1583 "type":"string"
1585 },
1586 "tags":{
1587 "type":"array",
1588 "xml":{
1589 "name":"tag",
1590 "wrapped":true
1591 },
1592 "items":{
1593 "$ref":"#/definitions/Tag"
1595 },
1596 "status":{
1597 "type":"string",
1598 "description":"pet status in the store",
1599 "enum":[
1600 "available",
1601 "pending",
1602 "sold"
1605 },
1606 "xml":{
1607 "name":"Pet"
1609 },
1610 "ApiResponse":{
1611 "type":"object",
1612 "properties":{
1613 "code":{
1614 "type":"integer",
1615 "format":"int32"
1616 },
1617 "type":{
1618 "type":"string"
1619 },
1620 "message":{
1621 "type":"string"
1625 },
1626 "externalDocs":{
1627 "description":"Find out more about Swagger",
1628 "url":"http://swagger.io"
1633compositionSchemaExample :: Schema
1634compositionSchemaExample = mempty
1635 & type_ .~ SwaggerObject
1636 & Data.Swagger.allOf ?~ [
1637 Ref (Reference "Other")
1638 , Inline (mempty
1639 & type_ .~ SwaggerObject
1640 & properties .~
1641 [ ("greet", Inline $ mempty
1642 & type_ .~ SwaggerString) ])
1645compositionSchemaExampleJSON :: Value
1646compositionSchemaExampleJSON = [aesonQQ|
1648 "type": "object",
1649 "allOf": [
1651 "$ref": "#/definitions/Other"
1652 },
1654 "type": "object",
1655 "properties": {
1656 "greet": { "type": "string" }