Oats can't handle query parameters defined with a hyphen `-`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 14
- Forks
- 5
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 1
Description
The following error is printed when trying to generate code from the attached swagger.
```sh
# yarn run oats oats/hyphen.yaml > hyphen.ts
(node:47395) UnhandledPromiseRejectionWarning: SyntaxError: Property or signature expected. (109:3)
107 |
108 | query?: {
> 109 | stuff-filter?: string;
| ^
110 | };
111 |
112 |
at t (/go/src/github.com/influxdata/ui/node_modules/prettier/parser-typescript.js:1:285)
at Object.parse (/go/src/github.com/influxdata/ui/node_modules/prettier/parser-typescript.js:14:180461)
at Object.parse (/go/src/github.com/influxdata/ui/node_modules/prettier/index.js:9739:19)
at coreFormat (/go/src/github.com/influxdata/ui/node_modules/prettier/index.js:13252:23)
at format (/go/src/github.com/influxdata/ui/node_modules/prettier/index.js:13510:73)
at formatWithCursor (/go/src/github.com/influxdata/ui/node_modules/prettier/index.js:13526:12)
at /go/src/github.com/influxdata/ui/node_modules/prettier/index.js:44207:15
at Object.format (/go/src/github.com/influxdata/ui/node_modules/prettier/index.js:44226:12)
at generate (/go/src/github.com/influxdata/ui/node_modules/@influxdata/oats/dist/generate.js:235:31)
at async Command. (/go/src/github.com/influxdata/ui/node_modules/@influxdata/oats/bin/oats:7:18)
(node:47395) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:47395) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
```
**oats/hyphen.yaml**
```yaml
openapi: "3.0.0"
info:
title: Stuff service
version: 0.0.0
servers:
- url: /api/v2
paths:
/stuff:
get:
operationId: getStuff
parameters:
- $ref: "#/components/parameters/StuffFilter"
responses:
'204':
$ref: "#/components/responses/NoContent"
components:
parameters:
StuffFilter:
in: query
name: stuff-filter
required: false
description: stuff to return
schema:
type: string
responses:
NoContent:
description: No content
```
Word on the street is that something like this works fine, maybe if the names are quoted to avoid this error:
```ts
const foo = {
'stuff-filter': 'some filter'
}
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with oats/hyphen.yaml using the documented yarn run oats oats/hyphen.yaml > hyphen.ts command, then inspect the generated TypeScript around the query parameter. The fix is complete when the hyphenated parameter produces valid TypeScript with the original query name preserved and the generator no longer fails during formatting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100