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
  • #1517
Closed
Open
Issue created Nov 21, 2018 by Administrator@rootContributor

Python client code improperly escaping regex strings

Created by: Raznic

Description

I've got a web server running Django + REST Framework that I am trying to generate Python client code for. One of my Serializers defines a RegexField that includes \d as a part of the regular expression. The generator appears to be escaping these characters in the generated client code.

Serializer regex: r'^\d$' Actual Python client code: re.search(r'^\\d$', value) Expected Python client code: re.search(r'^\d$', value)

openapi-generator version

I've pulled the latest from master and the version shows as 3.3.4-SNAPSHOT.

OpenAPI declaration file content or url
Command line used for generation
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g python -i <development Swagger URL> -o python
Steps to reproduce
  1. Define a Serializer class with a RegexField in your Django + REST Framework app.
from rest_framework.serializers import ModelSerializer, RegexField
from .model import MyModel
class MyModelSeralizer(ModelSerializer):
    value = RegexField(regex=r'^\d$')

    class Meta:
        model = MyModel
        fields = '__all__'
  1. Generate Python client code.

  2. Try to create a model.

import openapi_client

config = openapi_client.Configuration()
client = openapi_client.ApiClient(client)
api_instance = openapi_client.MyModelApi(client)

data = openapi_client.MyModel(value='9')
api_instance.my_model_create(data)
Related issues/PRs

#1392 (closed)

Suggest a fix/enhancement

My Java is pretty rusty, but I would assume the fix for the Python client would be similar to the one for the Ruby client from the related issue/PR.

Assignee
Assign to
Time tracking