-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from josstn/non-ascii-services
Support non-ascii characters in service name, operation name and parameter name.
- Loading branch information
Showing
13 changed files
with
172 additions
and
29 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
import camelCase from 'camelcase'; | ||
|
||
import { reservedWords } from '../../../utils/reservedWords'; | ||
import sanitizeOperationParameterName from '../../../utils/sanitizeOperationParameterName'; | ||
|
||
/** | ||
* Replaces any invalid characters from a parameter name. | ||
* For example: 'filter.someProperty' becomes 'filterSomeProperty'. | ||
*/ | ||
export const getOperationParameterName = (value: string): string => { | ||
const clean = value | ||
.replace(/^[^a-zA-Z]+/g, '') | ||
.replace(/[^\w\-]+/g, '-') | ||
.trim(); | ||
const clean = sanitizeOperationParameterName(value).trim(); | ||
return camelCase(clean).replace(reservedWords, '_$1'); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import camelCase from 'camelcase'; | ||
|
||
import sanitizeServiceName from '../../../utils/sanitizeServiceName'; | ||
|
||
/** | ||
* Convert the input value to a correct service name. This converts | ||
* the input string to PascalCase. | ||
*/ | ||
export const getServiceName = (value: string): string => { | ||
const clean = value | ||
.replace(/^[^a-zA-Z]+/g, '') | ||
.replace(/[^\w\-]+/g, '-') | ||
.trim(); | ||
const clean = sanitizeServiceName(value).trim(); | ||
return camelCase(clean, { pascalCase: true }); | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
import camelCase from 'camelcase'; | ||
|
||
import { reservedWords } from '../../../utils/reservedWords'; | ||
import sanitizeOperationParameterName from '../../../utils/sanitizeOperationParameterName'; | ||
|
||
/** | ||
* Replaces any invalid characters from a parameter name. | ||
* For example: 'filter.someProperty' becomes 'filterSomeProperty'. | ||
*/ | ||
export const getOperationParameterName = (value: string): string => { | ||
const clean = value | ||
.replace(/^[^a-zA-Z]+/g, '') | ||
.replace('[]', 'Array') | ||
.replace(/[^\w\-]+/g, '-') | ||
.trim(); | ||
const clean = sanitizeOperationParameterName(value).trim(); | ||
return camelCase(clean).replace(reservedWords, '_$1'); | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import camelCase from 'camelcase'; | ||
|
||
import sanitizeServiceName from '../../../utils/sanitizeServiceName'; | ||
|
||
/** | ||
* Convert the input value to a correct service name. This converts | ||
* the input string to PascalCase. | ||
*/ | ||
export const getServiceName = (value: string): string => { | ||
const clean = value | ||
.replace(/^[^a-zA-Z]+/g, '') | ||
.replace(/[^\w\-]+/g, '-') | ||
.trim(); | ||
const clean = sanitizeServiceName(value).trim(); | ||
return camelCase(clean, { pascalCase: true }); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import sanitizeServiceName from './sanitizeServiceName'; | ||
|
||
/** | ||
* sanitizeOperationName does the same as sanitizeServiceName. | ||
*/ | ||
const sanitizeOperationName = sanitizeServiceName; | ||
export default sanitizeOperationName; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import sanitizeOperationName from './sanitizeOperationName'; | ||
|
||
const sanitizeOperationParameterName = (name: string): string => { | ||
const withoutBrackets = name.replace('[]', 'Array'); | ||
return sanitizeOperationName(withoutBrackets); | ||
}; | ||
export default sanitizeOperationParameterName; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Sanitizes service names, so they are valid typescript identifiers of a certain form. | ||
* | ||
* 1: Remove any leading characters that are illegal as starting character of a typescript identifier. | ||
* 2: Replace illegal characters in remaining part of type name with underscore (-). | ||
* | ||
* Step 1 should perhaps instead also replace illegal characters with underscore, or prefix with it, like sanitizeEnumName | ||
* does. The way this is now one could perhaps end up removing all characters, if all are illegal start characters. It | ||
* would be sort of a breaking change to do so, though, previously generated code might change then. | ||
* | ||
* Javascript identifier regexp pattern retrieved from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers | ||
* | ||
* The output of this is expected to be converted to PascalCase | ||
*/ | ||
const sanitizeServiceName = (name: string) => | ||
name.replace(/^[^\p{ID_Start}]+/u, '').replace(/[^$\u200c\u200d\p{ID_Continue}]/gu, '-'); | ||
|
||
export default sanitizeServiceName; |
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
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
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