Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Common.elm
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ replaceSymbolsWith replacement input =
input
|> String.map
(\c ->
if c /= '_' && not (Char.isAlphaNum c) then
if Char.toCode c /= {- '_' -} 95 && not (Char.isAlphaNum c) then
replacement

else
Expand Down
36 changes: 20 additions & 16 deletions src/OpenApi/Generate.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2734,7 +2734,7 @@ makeNamespaceValid : String -> String
makeNamespaceValid str =
String.map
(\char ->
if List.member char invalidModuleNameChars then
if isInvalidForModuleName char then
'_'

else
Expand All @@ -2745,18 +2745,22 @@ makeNamespaceValid str =

removeInvalidChars : String -> String
removeInvalidChars str =
String.filter (\char -> char /= '\'') str


invalidModuleNameChars : List Char
invalidModuleNameChars =
[ ' '
, '.'
, '/'
, '{'
, '}'
, '-'
, ':'
, '('
, ')'
]
String.filter (\char -> Char.toCode char /= {- '\'' -} 39) str


isInvalidForModuleName : Char -> Bool
isInvalidForModuleName char =
let
code : Int
code =
Char.toCode char
in
(code == {- ' ' -} 32)
|| (code == {- '.' -} 46)
|| (code == {- '/' -} 47)
|| (code == {- '{' -} 123)
|| (code == {- '}' -} 125)
|| (code == {- '-' -} 45)
|| (code == {- ':' -} 58)
|| (code == {- '(' -} 40)
|| (code == {- ')' -} 41)
14 changes: 10 additions & 4 deletions src/Utils.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ sanitizeModuleName str =
String.filter
(\char ->
Char.isAlphaNum char
|| (char == '_')
|| (char == '-')
|| (char == ' ')
|| (char == ':')
|| (let
code : Int
code =
Char.toCode char
in
(code == {- '_' -} 95)
|| (code == {- '-' -} 45)
|| (code == {- ' ' -} 32)
|| (code == {- ':' -} 58)
)
)
str
|> String.replace "_" " "
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCommon.elm
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ isLower c =

isAlphaNumOrUnderscore : Char -> Bool
isAlphaNumOrUnderscore c =
Char.isAlphaNum c || c == '_' || Unicode.isAlphaNum c
Char.isAlphaNum c || Char.toCode c == {- '_' -} 95 || Unicode.isAlphaNum c


escape : String -> String
Expand Down