Skip to content

[BUG][Java][Spring] Incorrect code generation with regular expressions #8625

@jorgerod

Description

@jorgerod

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

Using the java Spring generator, string regex patterns have forward slashes somehow additionally escaped, changing the meaning of the pattern.

openapi-generator version

Versions 4.3.1 and 5.0.0

OpenAPI declaration file content or URL
openapi: 3.0.2
...
components:
  parameters:
    ClientKey:
      name: clientKey
      in: header
      description: "Client key"
      schema:
        type: string
        pattern: '^(?!\s*$).+'
...
Generation Details

Generated line:

default ResponseEntity<Void> deleteTokens(@Pattern(regexp="^(?!\\s*$).+") @ApiParam(value = "User token")   String userToken) {​​​​​​​
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }​​​​​​​

Expected line:

default ResponseEntity<Void> deleteTokens(@Pattern(regexp="^(?!\s*$).+") @ApiParam(value = "User token")   String userToken) {​​​​​​​
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }​​​​​​​

As you can see, the pattern (@pattern(regexp="^(?!\\s*$).+") ) has one slash too many and modifies the regex.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions