Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

[BUG] Regex patterns without trailing slashes break Python client generation #11

@antssilva96

Description

@antssilva96

Bug Report Checklist

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

When trying to generate a Python client SDK for a simple openAPI spec with an id with a given regex pattern, the generation fails with error Caused by: com.github.curiousoddman.rgxgen.parsing.dflt.RgxGenParseException: Unbalanced '{' - missing '}' at 'F0-9]{12' and (partial) stack trace

at com.github.curiousoddman.rgxgen.parsing.dflt.DefaultTreeBuilder.handleRepeatInCurvyBraces (DefaultTreeBuilder.java:479)
    at com.github.curiousoddman.rgxgen.parsing.dflt.DefaultTreeBuilder.handleRepeat (DefaultTreeBuilder.java:503)
    at com.github.curiousoddman.rgxgen.parsing.dflt.DefaultTreeBuilder.handleRepeatCharacter (DefaultTreeBuilder.java:314)
    at com.github.curiousoddman.rgxgen.parsing.dflt.DefaultTreeBuilder.parseGroup (DefaultTreeBuilder.java:249)
    at com.github.curiousoddman.rgxgen.parsing.dflt.DefaultTreeBuilder.build (DefaultTreeBuilder.java:664)
    at com.github.curiousoddman.rgxgen.parsing.dflt.DefaultTreeBuilder.get (DefaultTreeBuilder.java:673)
    at com.github.curiousoddman.rgxgen.RgxGen.<init> (RgxGen.java:71)
    at com.github.curiousoddman.rgxgen.RgxGen.<init> (RgxGen.java:62)
    at org.openapitools.codegen.languages.PythonClientCodegen.toExampleValueRecursive (PythonClientCodegen.java:1200)
    at org.openapitools.codegen.languages.PythonClientCodegen.toExampleValueRecursive (PythonClientCodegen.java:1128)
    at org.openapitools.codegen.languages.PythonClientCodegen.toExampleValue (PythonClientCodegen.java:1023)
    at org.openapitools.codegen.languages.PythonClientCodegen.setParameterExampleValue (PythonClientCodegen.java:1434)

This is not specific to the regex expression in my example and should happen with any regex that does not have ah extra char at the end that can be stripped without compromising the check that should be done.

openapi-generator version

6.0.0

OpenAPI declaration file content or url
---
openapi: 3.0.3
info:
  title: Test
  version: 1.0.0-SNAPSHOT
paths:
  /test:
    get:
      tags:
        - Test Resource
      parameters:
        - name: uuid
          in: query
          schema:
            $ref: '#/components/schemas/UUID'
      responses:
        "200":
          description: OK

components:
  schemas:
    UUID:
      format: uuid
      pattern: "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"
      type: string
Generation Details

Regular maven plugin generation with <generatorName>python</generatorName>

Steps to reproduce
  1. place the open api spec above somwhere the maven plugin can get it
  2. run mvn clean package in a pom.xml file with <inputSpec> linking to the file created in 1
  3. check the error that should be Unbalanced '{' - missing '}' at 'F0-9]{12'
Related issues/PRs
Suggest a fix

The problem seems to be with the REGEX in https://github.com/OpenAPITools/openapi-generator/blame/0c825ad3019e76b9d85e9883ef960a4643277c54/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java#L1179 where it should only strip of leading /, trailing / or trailing /i.

However, this REGEX is placing ANY final char into the second group, which means that in the case represented in this issue the main group will be [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12, because the final } is being captured as part of group 2.

Examples here: https://regex101.com/r/4YqK9h/1

I think what we want is something like ^/?(.+?)/?(i?)$ as shown in https://regex101.com/r/RAxPJU/1, where we really only capture trailing / or /i, not any last character that might be in the pattern.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions