Skip to content

Commit 8036b4b

Browse files
committed
cr
1 parent d1cbc3c commit 8036b4b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/serverless-openapi-typescript.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,19 @@ export default class ServerlessOpenapiTypeScript {
189189
fs.writeFileSync(outputFile, outputFile.endsWith('json') ? JSON.stringify(encodedOpenAPI, null, 2) : yaml.dump(encodedOpenAPI));
190190
}
191191

192+
// OpenApi spec define ^[a-zA-Z0-9\.\-_]+$ for legal fields - https://spec.openapis.org/oas/v3.1.0#components-object
193+
// ts-json-schema-generator - create fields with <,> for generic types and encode them in the ref
192194
encodeOpenApiToStandard(openApi) {
193195
const INVALID_CHARACTERS_KEY = /<|>/g;
194-
const INVALID_CHARACTERS_REF = /%3C|%3E/g;
196+
const INVALID_CHARACTERS_ENCODED = /%3C|%3E/g; // %3C = <, %3E = >
195197

196198
const mapObject = mapKeysDeep(openApi, (value, key) =>
197199
INVALID_CHARACTERS_KEY.test(key) ? key.replace(INVALID_CHARACTERS_KEY, '_') : key
198200
);
199201

200202
return mapValuesDeep(mapObject, (value, key) =>
201-
isString(value) && key === '$ref' && INVALID_CHARACTERS_REF.test(value) ?
202-
value.replace(INVALID_CHARACTERS_REF, '_') : value
203+
key === '$ref' && INVALID_CHARACTERS_ENCODED.test(value) ?
204+
value.replace(INVALID_CHARACTERS_ENCODED, '_') : value
203205
);
204206
}
205207

0 commit comments

Comments
 (0)