on develop help sign in
Adding more edge cases to determine stable scope names
commit3df7095c320a2034acf301cd99521a29fbe16f0e authorBrendan Hay <brendan.g.hay@gmail.com> dateTue 22 Mar 2016, 08:04 (11 years ago) parentf2ead7e
1 file changed+29−6
gen/src/Gen/Types/Schema.hs+29−6
gen/src/Gen/Types/Schema.hs+29−6
@@ -437,11 +437,34 @@ serviceName :: Service a -> String
437437serviceName = Text.unpack . (<> "Service") . toCamel . _sCanonicalName
438438
439439scopeName :: Service a -> Text -> String
440−scopeName s k = Text.unpack . toCamel $
441− case filter (not . url) (Text.split (== '/') k) of
440+scopeName s k = Text.unpack . lowerHead $
441+ case breakParts k of
442442 [] -> _sCanonicalName s <> "AllScope"
443− xs -> foldMap upperHead xs <> "Scope"
443+ xs -> foldMap named xs <> "Scope"
444444 where
445− url x = Text.null x
446− || Text.isPrefixOf "http" x
447− || Text.isPrefixOf "www" x
445+ breakParts =
446+ concatMap (Text.split split)
447+ . filter (not . ignore)
448+ . Text.split (== '/')
449+
450+ split x =
451+ dot x
452+ || separator x
453+
454+ ignore x =
455+ Text.null x
456+ || "auth" == x
457+ || Text.isPrefixOf "http" x
458+ || Text.isPrefixOf "www" x
459+
460+ named x
461+ | x == lower = pascal
462+ | otherwise = replaceAll (upperHead (upperAcronym x)) special
463+
464+ pascal = toPascal (_sCanonicalName s)
465+ lower = Text.toLower (_sCanonicalName s)
466+
467+ special =
468+ [ ("only", "Only")
469+ , ("manage", "Manage")
470+ ]