[BUG][Python] Python server string pattern regex improperly escaped.
Created by: daniellehanks
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 python-flask generator, string regex patterns have forward slashes somehow additionally escaped, changing the meaning of the pattern.
I found this bug that seems related. Seems like a reoccurrence.
Generated line: Actual:
if bar is not None and not re.search(r'^foo\\/bar$', bar): # noqa: E501
Expected:
if bar is not None and not re.search(r'^foo\/bar$', bar): # noqa: E501
With the current implementation, the input body "{"bar": "foo/bar"} passes the jsonschema validation (as it should), but then the model conversion fails with the raised ValueError, causing a 500.
openapi-generator version
Verified on 5.0.0-beta2 and 4.3.1.
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Foo API
description:
Test out deepObjects with query
version: 0.1.0
servers:
- url: 'http://localhost:8080/v1'
components:
schemas:
Foo:
type: object
properties:
bar:
type: string
pattern: '^foo\/bar$'
description:
A Foo object
paths:
/foo:
post:
operationId: CreateFoo
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Foo'
responses:
'200':
description: OK
'400':
description: Bad request
Generation Details
Steps to reproduce
Save the above yaml as openapi.yaml
, then run either:
openapi-generator-cli generate -i openapi.yaml -g python-flask -o out/
or
docker run --rm -t -v $(pwd):/tmp:rw openapitools/openapi-generator-cli:latest generate -i tmp/openapi.yaml -g python-flask -o tmp/out/
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/1823
Suggest a fix
I suspect something somewhere around here or the base class, since that is what the referenced bug added, but I can't quite seem to figure out what.