on develop help sign in
Ensuring OAuth scopes are correctly disambiguated
commit933705e55ca848a0ab1f1dcca318c6f4fd6cd664 authorBrendan Hay <brendan.g.hay@gmail.com> dateSat 19 Mar 2016, 09:04 (11 years ago) parent247dde0
1 file changed+11−8
gen/src/Gen/Types/Schema.hs+11−8
gen/src/Gen/Types/Schema.hs+11−8
@@ -31,6 +31,7 @@ import Data.Aeson hiding (Array, Bool, Object, String)
3131import qualified Data.Aeson as A
3232import Data.Aeson.TH
3333import Data.Aeson.Types (Parser)
34+import Data.Foldable (foldMap)
3435import Data.Function (on)
3536import qualified Data.HashMap.Strict as Map
3637import Data.Maybe
@@ -437,11 +438,13 @@ serviceName :: Service a -> String
437438serviceName = Text.unpack . (<> "Service") . toCamel . _sCanonicalName
438439
439440scopeName :: Service a -> Text -> String
440−scopeName s k =
441− let y = _sCanonicalName s <> "AllScope"
442− in Text.unpack . toCamel $
443− case Text.split (== '/') k of
444− [] -> y
445− xs -> case last xs of
446− "" -> y
447− x -> x <> "Scope"
441+scopeName s k = Text.unpack . toCamel $
442+ case parts of
443+ [] -> _sCanonicalName s <> "AllScope"
444+ xs -> foldMap upperHead xs <> "Scope"
445+ where
446+ parts = filter (not . url) (Text.split (== '/') k)
447+
448+ url x = Text.null x
449+ || Text.isPrefixOf "http" x
450+ || Text.isPrefixOf "www" x