Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #8625
Closed
Open
Issue created Feb 05, 2021 by Jorge Rodríguez Martín@jorgerodContributor5 of 6 checklist items completed5/6 checklist items

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

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.

Assignee
Assign to
Time tracking