git.iko.soy/typeable/openapi3
on master help sign in
Empty paths field (#213)
commitfd42a5af9e0a0d616925059a80a9a5e39bc6651c authorfisx <mf@zerobuzz.net> dateWed 20 May 2020, 11:38 (6 years ago) parent228a301
2 files changed+17−1
src/Data/Swagger/Internal.hs+4−1 test/Data/SwaggerSpec.hs+13
src/Data/Swagger/Internal.hs+4−1
@@ -1079,7 +1079,10 @@ instance ToJSON SecuritySchemeType where
10791079 <+> object [ "type" .= ("oauth2" :: Text) ]
10801080
10811081instance 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
10831086 toEncoding = sopSwaggerGenericToEncoding
10841087
10851088instance ToJSON SecurityScheme where
test/Data/SwaggerSpec.hs+13
@@ -46,6 +46,7 @@ spec = do
4646 describe "OAuth2 Security Definitions with merged Scope" $ oAuth2SecurityDefinitionsExample <=> oAuth2SecurityDefinitionsExampleJSON
4747 describe "Composition Schema Example" $ compositionSchemaExample <=> compositionSchemaExampleJSON
4848 describe "Swagger Object" $ do
49+ context "Example with no paths" $ emptyPathsFieldExample <=> emptyPathsFieldExampleJSON
4950 context "Todo Example" $ swaggerExample <=> swaggerExampleJSON
5051 context "PetStore Example" $
5152 it "decodes successfully" $ do
@@ -537,6 +538,18 @@ oAuth2SecurityDefinitionsExampleJSON = [aesonQQ|
537538-- Swagger object
538539-- =======================================================================
539540
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+
540553swaggerExample :: Swagger
541554swaggerExample = mempty
542555 & basePath ?~ "/"