python: adjust basic typing information (#17511)

* python: adjust basic typing information

This is an initial pass to fix and adjust the typing information for the
generated client. This is enough to have mypy runnning without complains
on all the (modern) generated clients (Pydantic v1 code is not checked
for instance)

mypy is also now run directly in the CI, so further changes will also be
checked and thus, will need to be compliant with good typing
information.

Note that this doesn't *fully* type all the code: mypy is not run in
"strict" mode and there are still many functions/methods/attributes
which are still not fully typed, but it's a first good step in that
direction.

* ApiResponse's raw_data can't be None

* Fix indentation

* Revert test changes

* run mypy on tests/ directory

* don't forcefully convert the client response headers to dict

* override petstore ApiResponse model

* adjust type of 'any/one_of_schemas' fields
This commit is contained in:
Jonathan Ballet
2024-01-06 08:40:42 +01:00
committed by GitHub
parent 4acbd69c3d
commit 22a0fc1727
257 changed files with 3168 additions and 1975 deletions

View File

@@ -1,53 +0,0 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import datetime
import petstore_api
from petstore_api.models.api_response import ApiResponse # noqa: E501
from petstore_api.rest import ApiException
class TestApiResponse(unittest.TestCase):
"""ApiResponse unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional):
"""Test ApiResponse
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
# model = petstore_api.models.api_response.ApiResponse() # noqa: E501
if include_optional :
return ApiResponse(
code = 56,
type = '',
message = ''
)
else :
return ApiResponse(
)
def testApiResponse(self):
"""Test ApiResponse"""
inst_req_only = self.make_instance(include_optional=False)
inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,54 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
import unittest
import datetime
from petstore_api.models.model_api_response import ModelApiResponse
class TestModelApiResponse(unittest.TestCase):
"""ModelApiResponse unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional) -> ModelApiResponse:
"""Test ModelApiResponse
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
# uncomment below to create an instance of `ModelApiResponse`
"""
model = ModelApiResponse()
if include_optional:
return ModelApiResponse(
code = 56,
type = '',
message = ''
)
else:
return ModelApiResponse(
)
"""
def testModelApiResponse(self):
"""Test ModelApiResponse"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()