Akhil Nair e823290c8f
[PYTHON] GetItem not working for Client generated allOf model and broken since 5.2.0 (#12239)
* I feel the issue is due to the creation of self._var_name_to_model_instances while doing the deserialization of the data.

Earlier the Python SDK code was using get_var_name_to_model_instances function which was adding var name to model instances that contain it. So <class 'openapi_client.model.stream_options_all_of'> will not part of mapping in self._var_name_to_model_instances for variable name stream_options.

Now with the latest Python SDK code following is the way through which var_name_to_model_instances is created:

    for prop_name in model_args:
        if prop_name not in discarded_args:
            var_name_to_model_instances[prop_name] = [self] + composed_instances
Now as we can see that the var_name_to_model_instances is populated with self and composed_instance which will also contain stream_options_all_of as a composed instance and there will be no check that if stream_options is present in composed_instances or not.

As there is no attribute_mapping found for stream_options in stream_options_all_of, the type for stream_options will be treated as dict for mapping stream_options_all_of as mentioned by @Chekov2k.

So what I suggest is the following code:

    for prop_name in model_args:
        if prop_name not in discarded_args:
           var_name_to_model_instances[prop_name] = [self] + list(
                filter(
                    lambda x: prop_name in x.openapi_types, composed_instances))
This way we can check if the property name is present in that composed instance or not. If it's okay for @spacether I can raise a PR for this.

* [get_item_all_of_bug]
Added samples, test cases to validate all_of schema.

* [getiem_all_of_bug]

Updated docs and samples.

* [getiem_all_of_bug]

Updated test cases, docs and samples.
2022-05-27 21:09:48 -07:00
..
2021-09-09 12:49:03 +08:00

dynamic-servers

This specification shows how to use dynamic servers.

This Python package is automatically generated by the OpenAPI Generator project:

  • API version: 1.0.0
  • Package version: 1.0.0
  • Build package: org.openapitools.codegen.languages.PythonClientCodegen

Requirements.

Python >=3.6

Installation & Usage

pip install

If the python package is hosted on a repository, you can install directly using:

pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git

(you may need to run pip with root permission: sudo pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git)

Then import the package:

import dynamic_servers

Setuptools

Install via Setuptools.

python setup.py install --user

(or sudo python setup.py install to install the package for all users)

Then import the package:

import dynamic_servers

Getting Started

Please follow the installation procedure and then run the following:


import time
import dynamic_servers
from pprint import pprint
from dynamic_servers.api import usage_api
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
# See configuration.py for a list of all supported configuration parameters.
configuration = dynamic_servers.Configuration(
    host = "http://petstore.swagger.io:80/v2"
)



# Enter a context with an instance of the API client
with dynamic_servers.ApiClient(configuration) as api_client:
    # Create an instance of the API class
    api_instance = usage_api.UsageApi(api_client)

    try:
        # Use custom server
        api_response = api_instance.custom_server()
        pprint(api_response)
    except dynamic_servers.ApiException as e:
        print("Exception when calling UsageApi->custom_server: %s\n" % e)

Documentation for API Endpoints

All URIs are relative to http://petstore.swagger.io:80/v2

Class Method HTTP request Description
UsageApi custom_server GET /custom Use custom server
UsageApi default_server GET /default Use default server

Documentation For Models

Documentation For Authorization

All endpoints do not require authorization.

Author

Notes for Large OpenAPI documents

If the OpenAPI document is large, imports in dynamic_servers.apis and dynamic_servers.models may fail with a RecursionError indicating the maximum recursion limit has been exceeded. In that case, there are a couple of solutions:

Solution 1: Use specific imports for apis and models like:

  • from dynamic_servers.api.default_api import DefaultApi
  • from dynamic_servers.model.pet import Pet

Solution 2: Before importing the package, adjust the maximum recursion limit as shown below:

import sys
sys.setrecursionlimit(1500)
import dynamic_servers
from dynamic_servers.apis import *
from dynamic_servers.models import *