From 0d0ed604d340238d75a3c222a109bfe1e259aa43 Mon Sep 17 00:00:00 2001 From: barcigabri <33417277+barcigabri@users.noreply.github.com> Date: Thu, 1 Jan 2026 01:42:06 +0000 Subject: [PATCH] chore: updating templates for python sdk --- .../openapi-generator/python/README.mustache | 28 ++++++++++++----- .../openapi-generator/python/api.mustache | 22 +++++++------ .../python/model_generic.mustache | 24 +++++++++++--- .../python/partial_api.mustache | 7 +---- .../python/requirements.mustache | 8 +++++ .../openapi-generator/python/setup.mustache | 31 +++++++++---------- 6 files changed, 77 insertions(+), 43 deletions(-) diff --git a/templates/openapi-generator/python/README.mustache b/templates/openapi-generator/python/README.mustache index 5700be01..424335a5 100644 --- a/templates/openapi-generator/python/README.mustache +++ b/templates/openapi-generator/python/README.mustache @@ -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}} {{{.}}} @@ -14,6 +10,7 @@ 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}}}) @@ -21,17 +18,31 @@ For more information, please visit [{{{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 @@ -47,3 +58,4 @@ Execute `pytest` to run the tests. Please follow the [installation procedure](#installation--usage) and then run the following: {{> common_README }} + diff --git a/templates/openapi-generator/python/api.mustache b/templates/openapi-generator/python/api.mustache index 899142af..2f1478a7 100644 --- a/templates/openapi-generator/python/api.mustache +++ b/templates/openapi-generator/python/api.mustache @@ -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 @@ -31,13 +32,14 @@ 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, @@ -45,13 +47,14 @@ class {{classname}}: @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, @@ -59,9 +62,10 @@ class {{classname}}: @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 ) @@ -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 diff --git a/templates/openapi-generator/python/model_generic.mustache b/templates/openapi-generator/python/model_generic.mustache index f89d62c2..70804d44 100644 --- a/templates/openapi-generator/python/model_generic.mustache +++ b/templates/openapi-generator/python/model_generic.mustache @@ -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}} @@ -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}} @@ -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}} @@ -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}} diff --git a/templates/openapi-generator/python/partial_api.mustache b/templates/openapi-generator/python/partial_api.mustache index 73eb916a..dd3a9a1f 100644 --- a/templates/openapi-generator/python/partial_api.mustache +++ b/templates/openapi-generator/python/partial_api.mustache @@ -49,9 +49,4 @@ '{{code}}': {{#dataType}}"{{.}}"{{/dataType}}{{^dataType}}None{{/dataType}}, {{/isWildcard}} {{/responses}} - } - - response_data = self.api_client.call_api( - *_param, - _request_timeout=_request_timeout - ) + } \ No newline at end of file diff --git a/templates/openapi-generator/python/requirements.mustache b/templates/openapi-generator/python/requirements.mustache index a936e455..aef16e4c 100644 --- a/templates/openapi-generator/python/requirements.mustache +++ b/templates/openapi-generator/python/requirements.mustache @@ -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}} @@ -13,3 +18,6 @@ pycryptodome >= 3.9.0 {{/hasHttpSignatureMethods}} pydantic >= 2 typing-extensions >= 4.7.1 +{{#lazyImports}} +lazy-imports >= 1, < 2 +{{/lazyImports}} diff --git a/templates/openapi-generator/python/setup.mustache b/templates/openapi-generator/python/setup.mustache index 7906ac1b..d65485b4 100644 --- a/templates/openapi-generator/python/setup.mustache +++ b/templates/openapi-generator/python/setup.mustache @@ -2,6 +2,7 @@ {{>partial_header}} + from setuptools import setup, find_packages # noqa: H301 # To install the library, run the following @@ -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}} @@ -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}} +) \ No newline at end of file