git.iko.soy/typeable/swagger2
on f057e7c help sign in
2 files changed+65−4
since splitsnapshots
unifiedsplit
src/Data/Swagger/Internal.hs+8−4 src/Data/Swagger/Internal/AesonUtils.hs+57
src/Data/Swagger/Internal.hs+8−4
@@ -55,7 +55,9 @@ import Data.Swagger.Internal.AesonUtils (sopSwaggerGenericToJSON
5555 ,AesonDefaultValue(..)
5656 ,mkSwaggerAesonOptions
5757 ,saoAdditionalPairs
58− ,saoSubObject)
58+ ,saoSubObject
59+ ,percentEncodeT
60+ ,percentDecodeT)
5961import Data.Swagger.Internal.Utils
6062
6163#if MIN_VERSION_aeson(0,10,0)
@@ -1042,6 +1044,7 @@ instance ToJSON Swagger where
10421044 toJSON = sopSwaggerGenericToJSON
10431045 DEFINE_TOENCODING
10441046
1047+
10451048instance ToJSON SecurityScheme where
10461049 toJSON = sopSwaggerGenericToJSON
10471050 DEFINE_TOENCODING
@@ -1113,10 +1116,11 @@ instance ToJSON Example where
11131116 toJSON = toJSON . Map.mapKeys show . getExample
11141117
11151118instance ToJSON Reference where
1116− toJSON (Reference ref) = object [ "$ref" .= ref ]
1119+ toJSON (Reference ref) = object [ "$ref" .= percentEncodeT ref ]
11171120
11181121referencedToJSON :: ToJSON a => Text -> Referenced a -> Value
1119−referencedToJSON prefix (Ref (Reference ref)) = object [ "$ref" .= (prefix <> ref) ]
1122+referencedToJSON prefix (Ref (Reference ref)) =
1123+ object [ "$ref" .= (prefix <> percentEncodeT ref) ]
11201124referencedToJSON _ (Inline x) = toJSON x
11211125
11221126instance ToJSON (Referenced Schema) where toJSON = referencedToJSON "#/definitions/"
@@ -1274,7 +1278,7 @@ instance FromJSON PathItem where
12741278 parseJSON = sopSwaggerGenericParseJSON
12751279
12761280instance FromJSON Reference where
1277− parseJSON (Object o) = Reference <$> o .: "$ref"
1281+ parseJSON (Object o) = Reference . percentDecodeT <$> o .: "$ref"
12781282 parseJSON _ = empty
12791283
12801284referencedParseJSON :: FromJSON a => Text -> Value -> JSON.Parser (Referenced a)
src/Data/Swagger/Internal/AesonUtils.hs+57
@@ -24,6 +24,11 @@ module Data.Swagger.Internal.AesonUtils (
2424 saoPrefix,
2525 saoAdditionalPairs,
2626 saoSubObject,
27+ -- * Percent encoding
28+ percentEncodeS,
29+ percentEncodeT,
30+ percentDecodeS,
31+ percentDecodeT,
2732 ) where
2833
2934import Prelude ()
@@ -330,3 +335,55 @@ sopSwaggerGenericToEncoding'' (SwaggerAesonOptions prefix _ sub) = go
330335 where (x, y) = span isUpper s
331336
332337#endif
338+
339+percentEncodeS :: String -> String
340+percentEncodeS "" = ""
341+percentEncodeS ('!' : s) = "%21" <> percentEncodeS s
342+percentEncodeS ('#' : s) = "%23" <> percentEncodeS s
343+percentEncodeS ('$' : s) = "%24" <> percentEncodeS s
344+percentEncodeS ('%' : s) = "%25" <> percentEncodeS s
345+percentEncodeS ('&' : s) = "%26" <> percentEncodeS s
346+percentEncodeS ('\'' : s) = "%27" <> percentEncodeS s
347+percentEncodeS ('(' : s) = "%28" <> percentEncodeS s
348+percentEncodeS (')' : s) = "%29" <> percentEncodeS s
349+percentEncodeS ('*' : s) = "%2A" <> percentEncodeS s
350+percentEncodeS ('+' : s) = "%2B" <> percentEncodeS s
351+percentEncodeS (',' : s) = "%2C" <> percentEncodeS s
352+percentEncodeS ('/' : s) = "%2F" <> percentEncodeS s
353+percentEncodeS (':' : s) = "%3A" <> percentEncodeS s
354+percentEncodeS (';' : s) = "%3B" <> percentEncodeS s
355+percentEncodeS ('=' : s) = "%3D" <> percentEncodeS s
356+percentEncodeS ('?' : s) = "%3F" <> percentEncodeS s
357+percentEncodeS ('@' : s) = "%40" <> percentEncodeS s
358+percentEncodeS ('[' : s) = "%5B" <> percentEncodeS s
359+percentEncodeS (']' : s) = "%5D" <> percentEncodeS s
360+percentEncodeS (c : s) = c : percentEncodeS s
361+
362+percentEncodeT :: Text -> Text
363+percentEncodeT = T.pack . percentEncodeS . T.unpack
364+
365+percentDecodeS :: String -> String
366+percentDecodeS "" = ""
367+percentDecodeS ('%':'2':'1':s) = '!' : percentDecodeS s
368+percentDecodeS ('%':'2':'3':s) = '#' : percentDecodeS s
369+percentDecodeS ('%':'2':'4':s) = '$' : percentDecodeS s
370+percentDecodeS ('%':'2':'5':s) = '%' : percentDecodeS s
371+percentDecodeS ('%':'2':'6':s) = '&' : percentDecodeS s
372+percentDecodeS ('%':'2':'7':s) = '\'' : percentDecodeS s
373+percentDecodeS ('%':'2':'8':s) = '(' : percentDecodeS s
374+percentDecodeS ('%':'2':'9':s) = ')' : percentDecodeS s
375+percentDecodeS ('%':'2':'A':s) = '*' : percentDecodeS s
376+percentDecodeS ('%':'2':'B':s) = '+' : percentDecodeS s
377+percentDecodeS ('%':'2':'C':s) = ',' : percentDecodeS s
378+percentDecodeS ('%':'2':'F':s) = '/' : percentDecodeS s
379+percentDecodeS ('%':'3':'A':s) = ':' : percentDecodeS s
380+percentDecodeS ('%':'3':'B':s) = ';' : percentDecodeS s
381+percentDecodeS ('%':'3':'D':s) = '=' : percentDecodeS s
382+percentDecodeS ('%':'3':'F':s) = '?' : percentDecodeS s
383+percentDecodeS ('%':'4':'0':s) = '@' : percentDecodeS s
384+percentDecodeS ('%':'5':'B':s) = '[' : percentDecodeS s
385+percentDecodeS ('%':'5':'D':s) = ']' : percentDecodeS s
386+percentDecodeS (c : s) = c : percentDecodeS s
387+
388+percentDecodeT :: Text -> Text
389+percentDecodeT = T.pack . percentDecodeS . T.unpack