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
- 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__'
-
Generate Python client code.
-
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
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.