-
-
Save brprice/796be7b6f9c94355b8e119b3d44aacc2 to your computer and use it in GitHub Desktop.
openapi3 bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- The generated openapi spec for hetrogenous pairs (and other tuples) is invalid: | |
-- the "items" property cannot be an array. I don't see how to create a valid | |
-- spec for hetrogenous pairs at all! | |
{-# LANGUAGE OverloadedLists #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Control.Lens | |
import Data.Aeson.Encode.Pretty (encodePretty) | |
import Data.ByteString.Lazy.Char8 as BSL | |
import Data.Proxy | |
import Data.OpenApi | |
main :: IO () | |
main = BSL.putStrLn $ encodePretty $ (mempty :: OpenApi) & | |
components . schemas .~ [ ("Buggy", toSchema (Proxy :: Proxy (Int, String)))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"components": { | |
"schemas": { | |
"Buggy": { | |
"minItems": 2, | |
"items": [ | |
{ | |
"maximum": 9223372036854775807, | |
"minimum": -9223372036854775808, | |
"type": "integer" | |
}, | |
{ | |
"type": "string" | |
} | |
], | |
"maxItems": 2, | |
"type": "array" | |
} | |
} | |
}, | |
"openapi": "3.0.0", | |
"info": { | |
"version": "", | |
"title": "" | |
}, | |
"paths": {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- The same problem afflicts homogenous pairs, as they are not treated any differently | |
-- to hetrogenous ones. However, it is clear how to write a valid openapi spec for them | |
{-# LANGUAGE OverloadedLists #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Control.Lens | |
import Data.Aeson.Encode.Pretty (encodePretty) | |
import Data.ByteString.Lazy.Char8 as BSL | |
import Data.Proxy | |
import Data.OpenApi | |
main :: IO () | |
main = BSL.putStrLn $ encodePretty $ (mempty :: OpenApi) & | |
components . schemas .~ [ ("Buggy", toSchema (Proxy :: Proxy (String, String)))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"components": { | |
"schemas": { | |
"Buggy": { | |
"minItems": 2, | |
"items": [ | |
{ | |
"type": "string" | |
}, | |
{ | |
"type": "string" | |
} | |
], | |
"maxItems": 2, | |
"type": "array" | |
} | |
} | |
}, | |
"openapi": "3.0.0", | |
"info": { | |
"version": "", | |
"title": "" | |
}, | |
"paths": {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- The problem with tuples causes knock-on problems elsewhere. | |
-- One particular place is maps. | |
-- For "complex" keys, Map k a is encoded as [(k,a)] | |
{-# LANGUAGE OverloadedLists #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Control.Lens | |
import Data.Aeson.Encode.Pretty (encodePretty) | |
import Data.ByteString.Lazy.Char8 as BSL | |
import Data.Map (Map) | |
import Data.Proxy | |
import Data.OpenApi | |
main :: IO () | |
main = BSL.putStrLn $ encodePretty $ (mempty :: OpenApi) & | |
components . schemas .~ [ ("Buggy", toSchema (Proxy :: Proxy (Map [Int] Bool)))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"components": { | |
"schemas": { | |
"Buggy": { | |
"items": { | |
"minItems": 2, | |
"items": [ | |
{ | |
"items": { | |
"maximum": 9223372036854775807, | |
"minimum": -9223372036854775808, | |
"type": "integer" | |
}, | |
"type": "array" | |
}, | |
{ | |
"type": "boolean" | |
} | |
], | |
"maxItems": 2, | |
"type": "array" | |
}, | |
"type": "array" | |
} | |
} | |
}, | |
"openapi": "3.0.0", | |
"info": { | |
"version": "", | |
"title": "" | |
}, | |
"paths": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment