feat: add example validation and mismatch reporting for OpenAPI schemas
This commit is contained in:
@@ -29,3 +29,81 @@ export function toCamelCase(name: string): string {
|
||||
const pascal = toPascalCase(name);
|
||||
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
||||
}
|
||||
|
||||
const JS_RESERVED_WORDS = new Set([
|
||||
'abstract',
|
||||
'arguments',
|
||||
'await',
|
||||
'boolean',
|
||||
'break',
|
||||
'byte',
|
||||
'case',
|
||||
'catch',
|
||||
'char',
|
||||
'class',
|
||||
'const',
|
||||
'continue',
|
||||
'debugger',
|
||||
'default',
|
||||
'delete',
|
||||
'do',
|
||||
'double',
|
||||
'else',
|
||||
'enum',
|
||||
'eval',
|
||||
'export',
|
||||
'extends',
|
||||
'false',
|
||||
'final',
|
||||
'finally',
|
||||
'float',
|
||||
'for',
|
||||
'function',
|
||||
'goto',
|
||||
'if',
|
||||
'implements',
|
||||
'import',
|
||||
'in',
|
||||
'instanceof',
|
||||
'int',
|
||||
'interface',
|
||||
'let',
|
||||
'long',
|
||||
'native',
|
||||
'new',
|
||||
'null',
|
||||
'package',
|
||||
'private',
|
||||
'protected',
|
||||
'public',
|
||||
'return',
|
||||
'short',
|
||||
'static',
|
||||
'super',
|
||||
'switch',
|
||||
'synchronized',
|
||||
'this',
|
||||
'throw',
|
||||
'throws',
|
||||
'transient',
|
||||
'true',
|
||||
'try',
|
||||
'typeof',
|
||||
'undefined',
|
||||
'var',
|
||||
'void',
|
||||
'volatile',
|
||||
'while',
|
||||
'with',
|
||||
'yield'
|
||||
]);
|
||||
|
||||
/** Returns true if the given name is a JS/TS reserved word. */
|
||||
export function isReservedWord(name: string): boolean {
|
||||
return JS_RESERVED_WORDS.has(name);
|
||||
}
|
||||
|
||||
/** Prefixes reserved words with `_` to produce a safe identifier. */
|
||||
export function safePropertyName(name: string): string {
|
||||
return isReservedWord(name) ? `_${name}` : name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user