git.iko.soy/typeable/openapi3
on master help sign in
Empty paths field (#213)
fd42a5afisx
src/Data/Swagger/Internal.hs+4−1
@@ -1079,7 +1079,10 @@ instance ToJSON SecuritySchemeType where
1079 <+> object [ "type" .= ("oauth2" :: Text) ]
1079 <+> object [ "type" .= ("oauth2" :: Text) ]
1080
1080
1081instance ToJSON Swagger where
1081instance ToJSON Swagger where
1082− toJSON = sopSwaggerGenericToJSON
1082+ toJSON a = sopSwaggerGenericToJSON a &
1083+ if InsOrdHashMap.null (_swaggerPaths a)
1084+ then (<+> object ["paths" .= object []])
1085+ else id
1083 toEncoding = sopSwaggerGenericToEncoding
1086 toEncoding = sopSwaggerGenericToEncoding
1084
1087
1085instance ToJSON SecurityScheme where
1088instance ToJSON SecurityScheme where
test/Data/SwaggerSpec.hs+13
@@ -46,6 +46,7 @@ spec = do
46 describe "OAuth2 Security Definitions with merged Scope" $ oAuth2SecurityDefinitionsExample <=> oAuth2SecurityDefinitionsExampleJSON
46 describe "OAuth2 Security Definitions with merged Scope" $ oAuth2SecurityDefinitionsExample <=> oAuth2SecurityDefinitionsExampleJSON
47 describe "Composition Schema Example" $ compositionSchemaExample <=> compositionSchemaExampleJSON
47 describe "Composition Schema Example" $ compositionSchemaExample <=> compositionSchemaExampleJSON
48 describe "Swagger Object" $ do
48 describe "Swagger Object" $ do
49+ context "Example with no paths" $ emptyPathsFieldExample <=> emptyPathsFieldExampleJSON
49 context "Todo Example" $ swaggerExample <=> swaggerExampleJSON
50 context "Todo Example" $ swaggerExample <=> swaggerExampleJSON
50 context "PetStore Example" $
51 context "PetStore Example" $
51 it "decodes successfully" $ do
52 it "decodes successfully" $ do
@@ -537,6 +538,18 @@ oAuth2SecurityDefinitionsExampleJSON = [aesonQQ|
537-- Swagger object
538-- Swagger object
538-- =======================================================================
539-- =======================================================================
539
540
541+emptyPathsFieldExample :: Swagger
542+emptyPathsFieldExample = mempty
543+
544+emptyPathsFieldExampleJSON :: Value
545+emptyPathsFieldExampleJSON = [aesonQQ|
546+{
547+ "swagger": "2.0",
548+ "info": {"version": "", "title": ""},
549+ "paths": {}
550+}
551+|]
552+
540swaggerExample :: Swagger
553swaggerExample :: Swagger
541swaggerExample = mempty
554swaggerExample = mempty
542 & basePath ?~ "/"
555 & basePath ?~ "/"