openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][typescript] Unbalanced brackets in patterns during parsing

Open zodiia opened this issue 3 years ago • 4 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] Have you tested with the latest master to confirm the issue still exists?
  • [x] Have you searched for related issues/PRs?
  • [x] What's the actual output vs expected output?
Description

I am trying to generated an OpenAPI client using the typescript generator. Unfortunately, I am hitting a bug with the parser, which seemingly forgets the last character of regex patterns.

With the pattern [A-Z]{3}, I get the following error message:

  Exception: Unbalanced '{' - missing '}' at 
'[A-Z]{3'
      ^

Caused by: com.github.curiousoddman.rgxgen.parsing.dflt.RgxGenParseException: Unbalanced '{' - missing '}' at 
'[A-Z]{3'
      ^

(full log using the provided sample OpenAPI in attached files: output.log)

Changing the pattern to something else, like [A-Z][A-Z][A-Z] doesn't help either, the same error message pops up with the last character seemingly disappearing. Changing it to [A-Z]{3}} solves the issue, but is obviously not a fix since it will break up other generators.

Note that, in the schemas section of the error message, the parsed schema does have the last pattern character in it (as seen in the full log: pattern: [A-Z]{3}).

openapi-generator version

6.0.1, 6.1.0, 6.2.0

OpenAPI declaration file content or url

test.yml

Generation Details

I am simply using the openapi-generator-cli command, providing an input OpenAPI file, typescript generator and an output directory.

Steps to reproduce

Using the provided sample OpenAPI file above and run the following command: openapi-generator-cli generate -i test.yml -g typescript -o ./out

Related issues/PRs

Not found.

Suggest a fix

My theory is that the typescript generator is, for some reason, removing the last character of patterns, which it shouldn't do.

zodiia avatar Sep 09 '22 10:09 zodiia

I can confirm the bug also when using the new python (experimental) generator

florianfischer91 avatar Sep 25 '22 11:09 florianfischer91

I also noticed the same bug and haven't found any fix yet ...

RemakeTm avatar Sep 29 '22 09:09 RemakeTm

Can confirm this issue is still present in both 6.1.0 and 6.2.0.

zodiia avatar Sep 29 '22 09:09 zodiia

Same when using the python generator at v6.2.0.

  Exception: Unbalanced '{' - missing '}' at
'[0-9]{7'
      ^
        at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1187)
        at org.openapitools.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:1081)
        at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:580)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:915)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:465)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: com.github.curiousoddman.rgxgen.parsing.dflt.RgxGenParseException: Unbalanced '{' - missing '}' at

danihodovic avatar Oct 13 '22 11:10 danihodovic