Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
28 changes: 20 additions & 8 deletions templates/openapi-generator/python/README.mustache
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# FattureInCloud Python SDK

[![PyPI](https://img.shields.io/pypi/v/fattureincloud-python-sdk?color=g)](https://pypi.org/project/fattureincloud-python-sdk/) ![unit tests](https://github.com/fattureincloud/fattureincloud-python-sdk/actions/workflows/validate.yaml/badge.svg)

# {{{projectName}}}
{{#appDescriptionWithNewLines}}
{{{.}}}
Expand All @@ -14,24 +10,39 @@ This Python package is automatically generated by the [OpenAPI Generator](https:
{{^hideGenerationTimestamp}}
- Build date: {{generatedDate}}
{{/hideGenerationTimestamp}}
- Generator version: {{generatorVersion}}
- Build package: {{generatorClass}}
{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}

## Requirements.

Python >= 3.9
Python {{{generatorLanguageVersion}}}

## Installation & Usage
### pip install

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

```sh
pip install fattureincloud-python-sdk
pip install git+https://{{gitHost}}/{{{gitUserId}}}/{{{gitRepoId}}}.git
```
(you may need to run `pip` with root permission: `sudo pip install fattureincloud-python-sdk`)
(you may need to run `pip` with root permission: `sudo pip install git+https://{{gitHost}}/{{{gitUserId}}}/{{{gitRepoId}}}.git`)

Then import the package:
```python
import {{{packageName}}}
```

### Setuptools

Install via [Setuptools](http://pypi.python.org/pypi/setuptools).

```sh
python setup.py install --user
```
(or `sudo python setup.py install` to install the package for all users)

Then import the package:
```python
Expand All @@ -47,3 +58,4 @@ Execute `pytest` to run the tests.
Please follow the [installation procedure](#installation--usage) and then run the following:

{{> common_README }}

22 changes: 13 additions & 9 deletions templates/openapi-generator/python/api.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding: utf-8

{{>partial_header}}

import warnings
from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt
from typing import Any, Dict, List, Optional, Tuple, Union
Expand Down Expand Up @@ -31,37 +32,40 @@ class {{classname}}:


@validate_call
{{#asyncio}}async {{/asyncio}}def {{operationId}}{{>partial_api_args}} -> {{{returnType}}}{{^returnType}}None{{/returnType}}:
{{#async}}async {{/async}}def {{operationId}}{{>partial_api_args}} -> {{{returnType}}}{{^returnType}}None{{/returnType}}:
{{>partial_api}}
response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(

response_data = {{#async}}await {{/async}}self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
{{#asyncio}}await {{/asyncio}}response_data.read()
{{#async}}await {{/async}}response_data.read()
return self.api_client.response_deserialize(
response_data=response_data,
response_types_map=_response_types_map,
).data


@validate_call
{{#asyncio}}async {{/asyncio}}def {{operationId}}_with_http_info{{>partial_api_args}} -> ApiResponse[{{{returnType}}}{{^returnType}}None{{/returnType}}]:
{{#async}}async {{/async}}def {{operationId}}_with_http_info{{>partial_api_args}} -> ApiResponse[{{{returnType}}}{{^returnType}}None{{/returnType}}]:
{{>partial_api}}
response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(

response_data = {{#async}}await {{/async}}self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
{{#asyncio}}await {{/asyncio}}response_data.read()
{{#async}}await {{/async}}response_data.read()
return self.api_client.response_deserialize(
response_data=response_data,
response_types_map=_response_types_map,
)


@validate_call
{{#asyncio}}async {{/asyncio}}def {{operationId}}_without_preload_content{{>partial_api_args}} -> RESTResponseType:
{{#async}}async {{/async}}def {{operationId}}_without_preload_content{{>partial_api_args}} -> RESTResponseType:
{{>partial_api}}
response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(

response_data = {{#async}}await {{/async}}self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
Expand Down Expand Up @@ -141,7 +145,7 @@ class {{classname}}:
_query_params.append(('{{baseName}}', {{paramName}}))
{{/isDate}}
{{^isDateTime}}{{^isDate}}
_query_params.append(('{{baseName}}', {{paramName}}{{#isEnumRef}}{{/isEnumRef}}))
_query_params.append(('{{baseName}}', {{paramName}}{{#isEnumRef}}.value{{/isEnumRef}}))
{{/isDate}}{{/isDateTime}}
{{/queryParams}}
# process the header parameters
Expand Down
24 changes: 20 additions & 4 deletions templates/openapi-generator/python/model_generic.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,22 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}

{{/isNullable}}
{{/required}}
{{#isContainer}}
{{#isArray}}
for i in value:
if i not in set([{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]):
raise ValueError("each list item must be one of ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})")
{{/isArray}}
{{^isArray}}
{{#isMap}}
for i in value.values():
if i not in set([{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]):
raise ValueError("dict values must be one of enum values ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})")
{{/isMap}}
{{/isContainer}}
{{^isContainer}}
if value not in set([{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]):
raise ValueError("must be one of enum values ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})")
{{/isArray}}
{{/isContainer}}
return value
{{/isEnum}}
{{/vars}}
Expand Down Expand Up @@ -234,6 +241,15 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
_dict[_key] = _value

{{/isAdditionalPropertiesTrue}}
{{#allVars}}
{{#isNullable}}
# set to None if {{{name}}} (nullable) is None
# and model_fields_set contains the field
if self.{{name}} is None and "{{{name}}}" in self.model_fields_set:
_dict['{{{baseName}}}'] = None

{{/isNullable}}
{{/allVars}}
return _dict

{{#hasChildren}}
Expand Down Expand Up @@ -340,7 +356,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
{{/items.isContainer}}
{{/items.isEnumOrRef}}
{{#items.isEnumOrRef}}
"{{{baseName}}}": dict((_k, _v) for _k, _v in obj.get("{{{baseName}}}").items()){{^-last}},{{/-last}}
"{{{baseName}}}": dict((_k, _v) for _k, _v in obj.get("{{{baseName}}}").items()) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
{{/items.isEnumOrRef}}
{{/items.isPrimitiveType}}
{{#items.isPrimitiveType}}
Expand All @@ -354,7 +370,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
"{{{baseName}}}": {{{dataType}}}.from_dict(obj["{{{baseName}}}"]) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
{{/isEnumOrRef}}
{{#isEnumOrRef}}
"{{{baseName}}}": obj.get("{{{baseName}}}"){{#defaultValue}} if obj.get("{{baseName}}") is not None else {{defaultValue}}{{/defaultValue}}{{^-last}},{{/-last}}
"{{{baseName}}}": obj.get("{{{baseName}}}"){{#defaultValue}} if obj.get("{{baseName}}") is not None else {{{defaultValue}}}{{/defaultValue}}{{^-last}},{{/-last}}
{{/isEnumOrRef}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
Expand Down
7 changes: 1 addition & 6 deletions templates/openapi-generator/python/partial_api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,4 @@
'{{code}}': {{#dataType}}"{{.}}"{{/dataType}}{{^dataType}}None{{/dataType}},
{{/isWildcard}}
{{/responses}}
}

response_data = self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
}
8 changes: 8 additions & 0 deletions templates/openapi-generator/python/requirements.mustache
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{{^async}}
urllib3 >= 2.1.0, < 3.0.0
{{/async}}
python_dateutil >= 2.8.2
{{#asyncio}}
aiohttp >= 3.8.4
aiohttp-retry >= 2.8.3
{{/asyncio}}
{{#httpx}}
httpx = ">= 0.28.1"
{{/httpx}}
{{#tornado}}
tornado = ">= 4.2, < 5"
{{/tornado}}
Expand All @@ -13,3 +18,6 @@ pycryptodome >= 3.9.0
{{/hasHttpSignatureMethods}}
pydantic >= 2
typing-extensions >= 4.7.1
{{#lazyImports}}
lazy-imports >= 1, < 2
{{/lazyImports}}
31 changes: 15 additions & 16 deletions templates/openapi-generator/python/setup.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

{{>partial_header}}


from setuptools import setup, find_packages # noqa: H301

# To install the library, run the following
Expand All @@ -13,16 +14,18 @@ from setuptools import setup, find_packages # noqa: H301
NAME = "{{{projectName}}}"
VERSION = "{{packageVersion}}"
PYTHON_REQUIRES = ">= 3.9"
{{#apiInfo}}
{{#apis}}
{{#-last}}
REQUIRES = [
{{^async}}
"urllib3 >= 2.1.0, < 3.0.0",
{{/async}}
"python-dateutil >= 2.8.2",
{{#asyncio}}
"aiohttp >= 3.8.4",
"aiohttp-retry >= 2.8.3",
{{/asyncio}}
{{#httpx}}
"httpx >= 0.28.1",
{{/httpx}}
{{#tornado}}
"tornado>=4.2, < 5",
{{/tornado}}
Expand All @@ -32,30 +35,26 @@ REQUIRES = [
{{/hasHttpSignatureMethods}}
"pydantic >= 2",
"typing-extensions >= 4.7.1",
{{#lazyImports}}
"lazy-imports >= 1, < 2",
{{/lazyImports}}
]

def readme():
with open('README.md') as f:
return f.read()

file = readme()

setup(
name=NAME,
version=VERSION,
description="Python SDK for the Fatture in Cloud API",
description="{{appName}}",
author="{{infoName}}{{^infoName}}OpenAPI Generator community{{/infoName}}",
author_email="{{infoEmail}}{{^infoEmail}}team@openapitools.org{{/infoEmail}}",
url="{{packageUrl}}",
keywords=["fattureincloud", "fatture in cloud", "fatture", "fic", "fattureincloud sdk", "fatture in cloud sdk"],
keywords=["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"],
install_requires=REQUIRES,
packages=find_packages(exclude=["test", "tests"]),
include_package_data=True,
{{#licenseInfo}}license="{{.}}",
{{/licenseInfo}}long_description_content_type='text/markdown',
long_description=file, # noqa: E501
long_description="""\
{{appDescription}}
""", # noqa: E501
package_data={"{{{packageName}}}": ["py.typed"]},
)
{{/-last}}
{{/apis}}
{{/apiInfo}}
)