-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Closed
Labels
Description
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 pythonThis 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 pythonThis 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 - 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