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

[BUG][python] Support named arrays #6493

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private void fixModelImports(Set<String> imports) {

/**
* Override with special post-processing for all models.
*/
*/
@SuppressWarnings({"static-method", "unchecked"})
public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
// loop through all models and delete ones where type!=object and the model has no validations and enums
Expand Down Expand Up @@ -417,14 +417,12 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {

Schema modelSchema = ModelUtils.getSchema(this.openAPI, cm.name);
CodegenProperty modelProperty = fromProperty("value", modelSchema);

if (cm.isEnum || cm.isAlias) {
if (!modelProperty.isEnum && !modelProperty.hasValidation) {
// remove these models because they are aliases and do not have any enums or validations
modelSchemasToRemove.put(cm.name, modelSchema);
}
} else if (cm.isArrayModel && !modelProperty.isEnum && !modelProperty.hasValidation) {
// remove any ArrayModels which lack validation and enums
modelSchemasToRemove.put(cm.name, modelSchema);
}
}
}
Expand Down Expand Up @@ -905,15 +903,15 @@ public String getSimpleTypeDeclaration(Schema schema) {
* Primitive types in the OAS specification are implemented in Python using the corresponding
* Python primitive types.
* Composed types (e.g. allAll, oneOf, anyOf) are represented in Python using list of types.
*
*
* The caller should set the prefix and suffix arguments to empty string, except when
* getTypeString invokes itself recursively. A non-empty prefix/suffix may be specified
* to wrap the return value in a python dict, list or tuple.
*
* Examples:
* - "bool, date, float" The data must be a bool, date or float.
* - "[bool, date]" The data must be an array, and the array items must be a bool or date.
*
*
* @param p The OAS schema.
* @param prefix prepended to the returned value.
* @param suffix appended to the returned value.
Expand Down Expand Up @@ -968,7 +966,7 @@ private String getTypeString(Schema p, String prefix, String suffix, List<String
} else {
return prefix + getTypeString(inner, "[", "]", referencedModelNames) + fullSuffix;
}
}
}
if (ModelUtils.isFileSchema(p)) {
return prefix + "file_type" + fullSuffix;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ from {{packageName}}.model_utils import ( # noqa: F401
{{> python-experimental/model_templates/model_simple }}
{{/isAlias}}
{{^isAlias}}
{{#isArrayModel}}
{{> python-experimental/model_templates/model_simple }}
{{/isArrayModel}}
{{^isArrayModel}}
{{> python-experimental/model_templates/model_normal }}
{{/isArrayModel}}
{{/isAlias}}
{{/interfaces}}
{{#interfaces}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,19 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/HealthCheckResult'
/farm/animals:
get:
tags:
- farm
jirikuncar marked this conversation as resolved.
Show resolved Hide resolved
summary: Animal Farm
operationId: farm
responses:
200:
description: Got named array of enums
content:
application/json:
schema:
$ref: '#/components/schemas/AnimalFarm'
servers:
- url: 'http://{server}.swagger.io:{port}/v2'
description: petstore server
Expand Down Expand Up @@ -1443,7 +1456,7 @@ components:
maximum: 543.2
minimum: 32.1
type: number
multipleOf: 32.5
multipleOf: 32.5
float:
type: number
format: float
Expand Down Expand Up @@ -1969,7 +1982,7 @@ components:
# Here the additional properties are specified using a referenced schema.
# This is just to validate the generated code works when using $ref
# under 'additionalProperties'.
$ref: '#/components/schemas/fruit'
$ref: '#/components/schemas/fruit'
Shape:
oneOf:
- $ref: '#/components/schemas/Triangle'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ README.md
docs/AdditionalPropertiesClass.md
docs/Address.md
docs/Animal.md
docs/AnimalFarm.md
docs/AnotherFakeApi.md
docs/ApiResponse.md
docs/Apple.md
Expand Down Expand Up @@ -35,6 +36,7 @@ docs/EnumTest.md
docs/EquilateralTriangle.md
docs/FakeApi.md
docs/FakeClassnameTags123Api.md
docs/FarmApi.md
docs/File.md
docs/FileSchemaTestClass.md
docs/Foo.md
Expand Down Expand Up @@ -98,6 +100,7 @@ petstore_api/api/another_fake_api.py
petstore_api/api/default_api.py
petstore_api/api/fake_api.py
petstore_api/api/fake_classname_tags_123_api.py
petstore_api/api/farm_api.py
petstore_api/api/pet_api.py
petstore_api/api/store_api.py
petstore_api/api/user_api.py
Expand All @@ -109,6 +112,7 @@ petstore_api/model/__init__.py
petstore_api/model/additional_properties_class.py
petstore_api/model/address.py
petstore_api/model/animal.py
petstore_api/model/animal_farm.py
petstore_api/model/api_response.py
petstore_api/model/apple.py
petstore_api/model/apple_req.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Class | Method | HTTP request | Description
*FakeApi* | [**test_json_form_data**](docs/FakeApi.md#test_json_form_data) | **GET** /fake/jsonFormData | test json serialization of form data
*FakeApi* | [**test_query_parameter_collection_format**](docs/FakeApi.md#test_query_parameter_collection_format) | **PUT** /fake/test-query-paramters |
*FakeClassnameTags123Api* | [**test_classname**](docs/FakeClassnameTags123Api.md#test_classname) | **PATCH** /fake_classname_test | To test class name in snake case
*FarmApi* | [**farm**](docs/FarmApi.md#farm) | **GET** /farm/animals | Animal Farm
*PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store
*PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **DELETE** /pet/{petId} | Deletes a pet
*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **GET** /pet/findByStatus | Finds Pets by status
Expand Down Expand Up @@ -125,6 +126,7 @@ Class | Method | HTTP request | Description
- [additional_properties_class.AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
- [address.Address](docs/Address.md)
- [animal.Animal](docs/Animal.md)
- [animal_farm.AnimalFarm](docs/AnimalFarm.md)
- [api_response.ApiResponse](docs/ApiResponse.md)
- [apple.Apple](docs/Apple.md)
- [apple_req.AppleReq](docs/AppleReq.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# animal_farm.AnimalFarm

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
jirikuncar marked this conversation as resolved.
Show resolved Hide resolved

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# petstore_api.FarmApi

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

Method | HTTP request | Description
------------- | ------------- | -------------
[**farm**](FarmApi.md#farm) | **GET** /farm/animals | Animal Farm


# **farm**
> animal_farm.AnimalFarm farm()

Animal Farm

### Example

```python
from __future__ import print_function
import time
import petstore_api
from petstore_api.api import farm_api
from petstore_api.model import animal_farm
from pprint import pprint
# 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 = petstore_api.Configuration(
host = "http://petstore.swagger.io:80/v2"
)


# Enter a context with an instance of the API client
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = farm_api.FarmApi(api_client)

# example, this endpoint has no required or optional parameters
try:
# Animal Farm
api_response = api_instance.farm()
pprint(api_response)
except petstore_api.ApiException as e:
print("Exception when calling FarmApi->farm: %s\n" % e)
```

### Parameters
This endpoint does not need any parameter.

### Return type

[**animal_farm.AnimalFarm**](AnimalFarm.md)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/json

### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
**200** | Got named array of enums | - |

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from petstore_api.api.default_api import DefaultApi
from petstore_api.api.fake_api import FakeApi
from petstore_api.api.fake_classname_tags_123_api import FakeClassnameTags123Api
from petstore_api.api.farm_api import FarmApi
from petstore_api.api.pet_api import PetApi
from petstore_api.api.store_api import StoreApi
from petstore_api.api.user_api import UserApi
Loading