-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into pre-commit-ci-update-config
- Loading branch information
Showing
10 changed files
with
392 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# generated by datamodel-codegen: | ||
# filename: api.yaml | ||
# timestamp: 2019-07-26T00:00:00+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from typing import List, Optional | ||
|
||
from pydantic import AnyUrl, BaseModel, Field, StrictStr | ||
|
||
|
||
class Pet(BaseModel): | ||
id: int | ||
name: StrictStr | ||
tag: Optional[StrictStr] = None | ||
|
||
|
||
class Pets(BaseModel): | ||
__root__: List[Pet] | ||
|
||
|
||
class User(BaseModel): | ||
id: int | ||
name: StrictStr | ||
tag: Optional[StrictStr] = None | ||
|
||
|
||
class Users(BaseModel): | ||
__root__: List[User] | ||
|
||
|
||
class Id(BaseModel): | ||
__root__: StrictStr | ||
|
||
|
||
class Rules(BaseModel): | ||
__root__: List[StrictStr] | ||
|
||
|
||
class Error(BaseModel): | ||
code: int | ||
message: StrictStr | ||
|
||
|
||
class Api(BaseModel): | ||
apiKey: Optional[StrictStr] = Field( | ||
None, description='To be used as a dataset parameter value' | ||
) | ||
apiVersionNumber: Optional[StrictStr] = Field( | ||
None, description='To be used as a version parameter value' | ||
) | ||
apiUrl: Optional[AnyUrl] = Field( | ||
None, description="The URL describing the dataset's fields" | ||
) | ||
apiDocumentationUrl: Optional[AnyUrl] = Field( | ||
None, description='A URL to the API console for each API' | ||
) | ||
|
||
|
||
class Apis(BaseModel): | ||
__root__: List[Api] | ||
|
||
|
||
class Event(BaseModel): | ||
name: Optional[StrictStr] = None | ||
|
||
|
||
class Result(BaseModel): | ||
event: Optional[Event] = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from datamodel_code_generator.format import PythonVersion | ||
from datamodel_code_generator.imports import ( | ||
IMPORT_LITERAL, | ||
IMPORT_LITERAL_BACKPORT, | ||
IMPORT_OPTIONAL, | ||
) | ||
from datamodel_code_generator.types import DataType | ||
|
||
|
||
class TestDataType: | ||
def test_imports_with_literal_one(self): | ||
"""Test imports for a DataType with single literal value""" | ||
data_type = DataType(literals=[''], python_version=PythonVersion.PY_38) | ||
|
||
# Convert iterator to list for assertion | ||
imports = list(data_type.imports) | ||
assert IMPORT_LITERAL in imports | ||
assert len(imports) == 1 | ||
|
||
def test_imports_with_literal_one_and_optional(self): | ||
"""Test imports for an optional DataType with single literal value""" | ||
data_type = DataType( | ||
literals=[''], is_optional=True, python_version=PythonVersion.PY_38 | ||
) | ||
|
||
imports = list(data_type.imports) | ||
assert IMPORT_LITERAL in imports | ||
assert IMPORT_OPTIONAL in imports | ||
assert len(imports) == 2 | ||
|
||
def test_imports_with_literal_empty(self): | ||
"""Test imports for a DataType with no literal values""" | ||
data_type = DataType(literals=[], python_version=PythonVersion.PY_38) | ||
|
||
imports = list(data_type.imports) | ||
assert len(imports) == 0 | ||
|
||
def test_imports_with_literal_python37(self): | ||
"""Test imports for a DataType with literal in Python 3.7""" | ||
data_type = DataType(literals=[''], python_version=PythonVersion.PY_37) | ||
|
||
imports = list(data_type.imports) | ||
assert IMPORT_LITERAL_BACKPORT in imports | ||
assert len(imports) == 1 | ||
|
||
def test_imports_with_nested_dict_key(self): | ||
"""Test imports for a DataType with dict_key containing literals""" | ||
dict_key_type = DataType(literals=['key'], python_version=PythonVersion.PY_38) | ||
|
||
data_type = DataType(python_version=PythonVersion.PY_38, dict_key=dict_key_type) | ||
|
||
imports = list(data_type.imports) | ||
assert IMPORT_LITERAL in imports | ||
assert len(imports) == 1 | ||
|
||
def test_imports_without_duplicate_literals(self): | ||
"""Test that literal import is not duplicated""" | ||
dict_key_type = DataType(literals=['key1'], python_version=PythonVersion.PY_38) | ||
|
||
data_type = DataType( | ||
literals=['key2'], | ||
python_version=PythonVersion.PY_38, | ||
dict_key=dict_key_type, | ||
) | ||
|
||
imports = list(data_type.imports) | ||
assert IMPORT_LITERAL in imports |
Oops, something went wrong.