Skip to content

Commit

Permalink
add normalize_name method
Browse files Browse the repository at this point in the history
  • Loading branch information
ota42y committed Sep 22, 2023
1 parent a0d8401 commit a99a495
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions flask_openapi3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
from flask import make_response, current_app
from flask.wrappers import Response as FlaskResponse
from pydantic import BaseModel, ValidationError
from pydantic.schema import normalize_name
# GenerateJsonSchema class have this method in pydantic 2-x
# use `from pydantic.json_schema import GenerateJsonSchema`

from ._http import HTTP_STATUS, HTTPMethod
from .models import Encoding
Expand Down Expand Up @@ -593,3 +590,7 @@ def convert_responses_key_to_string(responses: ResponseDict) -> ResponseStrKeyDi
_responses[key] = value

return _responses


def normalize_name(name: str) -> str:
return re.sub(r'[^\w.\-]', '_', name)
8 changes: 8 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
# @Author : llc
# @Time : 2022/12/19 10:34

from flask_openapi3.utils import normalize_name

def test_normalize_name():
assert "List-Generic.Response_Detail_" == normalize_name("List-Generic.Response[Detail]")

0 comments on commit a99a495

Please sign in to comment.