Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace exponential in name for FieldnameResolver #833

Merged
merged 2 commits into from
Sep 22, 2022

Conversation

PTank
Copy link
Contributor

@PTank PTank commented Aug 27, 2022

[#749]
Numbers ¹ to ⁹ were not supported by '\W' in re.sub

schema example

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "test": {
  	"type": "string",
  	"default": "²",
  	"enum": [
  	  "²",
  	  "oky⁵"
  	]
     }
    }
  }
}

Do an infinite loop before the fix in

while not (
            new_name.isidentifier() ...

Output with the fix

# cmd: datamodel-codegen --input-file-type jsonschema --input
 schema.json 
# generated by datamodel-codegen:
#   filename:  schema.json
#   timestamp: 2022-08-27T10:04:55+00:00

from __future__ import annotations

from enum import Enum
from typing import List, Optional

from pydantic import BaseModel


class Test(Enum):
    _ = '²'
    oky_ = 'oky⁵'


class ModelItem(BaseModel):
    test: Optional[Test] = '²'


class Model(BaseModel):
    __root__: List[ModelItem]

@codecov
Copy link

codecov bot commented Sep 5, 2022

Codecov Report

Merging #833 (651dd35) into master (e9b6edf) will not change coverage.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##            master      #833     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files           11        21     +10     
  Lines         1020      2518   +1498     
  Branches       201       558    +357     
===========================================
+ Hits          1020      2518   +1498     
Flag Coverage Δ
unittests 99.92% <99.89%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
datamodel_code_generator/model/__init__.py 100.00% <ø> (ø)
datamodel_code_generator/__init__.py 100.00% <100.00%> (ø)
datamodel_code_generator/__main__.py 100.00% <100.00%> (ø)
datamodel_code_generator/format.py 100.00% <100.00%> (ø)
datamodel_code_generator/http.py 100.00% <100.00%> (ø)
datamodel_code_generator/imports.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/base.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/enum.py 100.00% <100.00%> (ø)
...atamodel_code_generator/model/pydantic/__init__.py 100.00% <100.00%> (ø)
...amodel_code_generator/model/pydantic/base_model.py 100.00% <100.00%> (ø)
... and 18 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@koxudaxi koxudaxi merged commit 6d51d6b into koxudaxi:master Sep 22, 2022
@koxudaxi
Copy link
Owner

@PTank
Thank you for creating the PR.
I'm sorry for the late release of the fixed 🙇
version 0.13.2 has been released.
https://github.com/koxudaxi/datamodel-code-generator/releases/tag/0.13.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants