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
  • #11521
Closed
Open
Issue created Feb 04, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][Python] Client generation doesn't handle regex pattern correctly

Created by: aaronatbissell

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 generating a python client library where a string pattern like this is present, the validation logic in the client code is incorrect

datetime:
  type: string
  pattern: '[\d]{4}-[\d]{2}-[\d]{2}T[\d]{1,2}:[\d]{2}Z'
openapi-generator version

5.4.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  description: a spec to test free form object models
  version: 1.0.0
  title: OpenAPI Petstore
  license:
    name: Apache-2.0
    url: "https://www.apache.org/licenses/LICENSE-2.0.html"
tags: []
paths: {}
components:
  schemas:
    DateTimeObject:
      properties:
        datetime:
          type: string
          pattern: '[\d]{4}-[\d]{2}-[\d]{2}T[\d]{1,2}:[\d]{2}Z'
Generation Details
openapi-generator generate -i spec.yaml -g python

This generates a validation string of:

validations = {
  ('datetime',): {
    'regex': {
      'pattern': r'[d]{4}-[\d]{2}-[\d]{2}T[\d]{1,2}:[\d]{2}Z/', # noqa: E501
    },
  },
}
Steps to reproduce

Using a config like this:

openapi: 3.0.0
info:
  description: a spec to test free form object models
  version: 1.0.0
  title: OpenAPI Petstore
  license:
    name: Apache-2.0
    url: "https://www.apache.org/licenses/LICENSE-2.0.html"
tags: []
paths: {}
components:
  schemas:
    DateTimeObject:
      properties:
        datetime:
          type: string
          pattern: '[\d]{4}-[\d]{2}-[\d]{2}T[\d]{1,2}:[\d]{2}Z'

Then running

openapi-generator generate -i spec.yaml -g python

This generates a validation string of:

validations = {
  ('datetime',): {
    'regex': {
      'pattern': r'[d]{4}-[\d]{2}-[\d]{2}T[\d]{1,2}:[\d]{2}Z/', # noqa: E501
    },
  },
}

and it should be

r'[\d]{4}-[\d]{2}-[\d]{2}T[\d]{1,2}:[\d]{2}Z'
Related issues/PRs

#1823 (closed) - related but for the python-server code base #8098 - similar, but python-flask and specific to escaped characters

Suggest a fix

I'll try to post a PR soon

Assignee
Assign to
Time tracking