Closed
Description
I was using a hashing algo to get unique operationIds and noticed this causes prettier to fail.
Here is a minimal example
openapi: 3.1.0
info:
title: Test
description: 'Test'
license:
name: MIT
version: 1.0.0
servers:
-
url: 'https://localhost'
paths:
/test:
get:
operationId: 7e5753f74779264a6442b8a6e96b44c27b2db2a006417f583eb0e94498b3faaa
parameters:
-
name: id
in: query
schema:
type: array
items:
type:
- string
- 'null'
Which according to the swagger editor is valid. But results in:
SyntaxError: An identifier or keyword cannot immediately follow a numeric literal. (239:7)
237 | * @request GET:/test
238 | */
> 239 | 7E5753F74779264A6442B8A6E96B44C27B2Db2A006417F583Eb0E94498B3Faaa: (query?: {
| ^
240 | id?: (string | null)[],
241 |
242 | }, params: RequestParams = {}) =>
at Q4 (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/plugins/typescript.mjs:17:76108)
at x3 (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/plugins/typescript.mjs:20:773)
at Object.w3 [as parse] (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/plugins/typescript.mjs:20:1164)
at parse4 (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/index.mjs:20685:24)
at async coreFormat (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/index.mjs:21146:7)
at async formatWithCursor (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/index.mjs:21348:14)
at async Module.format2 (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/index.mjs:22733:25)
at async Z.prettierFormat (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/swagger-typescript-api/dist/chunk-M2JPSLFC.js:16:479)
at async Z.formatCode (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/swagger-typescript-api/dist/chunk-M2JPSLFC.js:16:639)
at async ve.createOutputFileInfo (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/swagger-typescript-api/dist/chunk-M2JPSLFC.js:54:499) {
loc: { start: { line: 239, column: 7 }, end: { line: 239, column: 7 } },
cause: ud: An identifier or keyword cannot immediately follow a numeric literal.
at md (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/plugins/typescript.mjs:17:8577)
at vd (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/plugins/typescript.mjs:17:10477)
at y0 (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/plugins/typescript.mjs:17:71407)
at $4 (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/plugins/typescript.mjs:17:75969)
at I0 (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/plugins/typescript.mjs:17:75711)
at file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/plugins/typescript.mjs:20:1128
at K4 (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/plugins/typescript.mjs:17:76262)
at Object.w3 [as parse] (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/plugins/typescript.mjs:20:1112)
at parse4 (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/index.mjs:20685:24)
at async coreFormat (file:///.npm/_npx/ad2f6472e51cc62f/node_modules/prettier/index.mjs:21146:7) {
fileName: 'estree.ts',
location: { start: [Object], end: [Object] }
},
codeFrame: '\x1B[0m \x1B[90m 237 |\x1B[39m \x1B[90m * @request GET:/test\x1B[39m\n' +
' \x1B[90m 238 |\x1B[39m \x1B[90m */\x1B[39m\n' +
'\x1B[31m\x1B[1m>\x1B[22m\x1B[39m\x1B[90m 239 |\x1B[39m \x1B[35m7E5753\x1B[39m\x1B[33mF74779264A6442B8A6E96B44C27B2Db2A006417F583Eb0E94498B3Faaa\x1B[39m\x1B[33m:\x1B[39m (query\x1B[33m?\x1B[39m\x1B[33m:\x1B[39m {\n' +
' \x1B[90m |\x1B[39m \x1B[31m\x1B[1m^\x1B[22m\x1B[39m\n' +
' \x1B[90m 240 |\x1B[39m id\x1B[33m?\x1B[39m\x1B[33m:\x1B[39m (string \x1B[33m|\x1B[39m \x1B[36mnull\x1B[39m)[]\x1B[33m,\x1B[39m\n' +
' \x1B[90m 241 |\x1B[39m\n' +
' \x1B[90m 242 |\x1B[39m }\x1B[33m,\x1B[39m params\x1B[33m:\x1B[39m \x1B[33mRequestParams\x1B[39m \x1B[33m=\x1B[39m {}) \x1B[33m=>\x1B[39m\x1B[0m'
}
I think it needs to surround the member name with a quote when it detects a number at the start. So "7e5753f74779264a6442b8a6e96b44c27b2db2a006417f583eb0e94498b3faaa":
instead of just 7e5753f74779264a6442b8a6e96b44c27b2db2a006417f583eb0e94498b3faaa:
Metadata
Metadata
Assignees
Labels
No labels