Skip to content

Property names with at sign throw parsing error in declaration file #1162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 2 tasks
corydeppen opened this issue Jun 11, 2023 · 2 comments · Fixed by #1166
Closed
1 of 2 tasks

Property names with at sign throw parsing error in declaration file #1162

corydeppen opened this issue Jun 11, 2023 · 2 comments · Fixed by #1166
Labels
bug Something isn't working good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-ts Relevant to the openapi-typescript library PRs welcome PRs are welcome to solve this issue!

Comments

@corydeppen
Copy link

Description

After generating the types, there are errors (e.g. Parsing error: Property or signature expected) in the .d.ts file that appear to be caused by unquoted property names that include an at sign. The following is a snippet taken from a StackPath OpenAPI doc.

"apiStatusDetail": {
  "type": "object",
  "properties": { "@type": { "type": "string" } },
  "required": ["@type"],
  "discriminator": { "propertyName": "@type" }
}

The generated file includes the following:

"stackpath.rpc.Help": {
  @type: "stackpath.rpc.Help";
} & Omit<components["schemas"]["apiStatusDetail"], "@type"> & {
  links?: (components["schemas"]["stackpath.rpc.Help.Link"])[];
};
Name Version
openapi-typescript 6.2.6
Node.js 18.16.0
OS + version macOS 12.6.6

Expected result

Property names that include an at sign should be quoted (e.g. "@type": "stackpath.rpc.Help";).

Checklist

@corydeppen corydeppen added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Jun 11, 2023
@drwpow
Copy link
Contributor

drwpow commented Jun 12, 2023

This is a bug in the RegEx that detects when object keys in JS need to be escaped or not (while also escaping / and ~ needed for $refs). Should be a simple fix.

I’ve added the help wanted and good first issue labels as this would be a great PR for someone that wants to contribute. The fix would be:

  1. Changing this RegEx
  2. Adding a test in utils.test.ts to test (ideally before the fix, so it can be recreated & verified)
  3. (optional) Adding a test in schema-object.test.ts to test the wrapping transformation works as intended

@drwpow drwpow added PRs welcome PRs are welcome to solve this issue! good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project labels Jun 12, 2023
@pvanagtmaal
Copy link
Contributor

@drwpow I'm looking into this now and I don't think it's the regex, rather this line seems to be missing an escObjKey call for the property name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-ts Relevant to the openapi-typescript library PRs welcome PRs are welcome to solve this issue!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants