ru-openapi-cg 0.1.4

A powerful OpenAPI 3.0 code generator written in Rust that supports multiple programming languages and frameworks
# Auto-generated Python API extension
from typing import Any, List, Dict
import requests
import json

class {{target}}:
    """Base API client class"""
    def __init__(self, base_url: str = ""):
        self.base_url = base_url

class {{target}}Api({{target}}):
    """Extended API client with generated methods"""
    
{{#each endpoints}}
    def {{this.name}}(self,
        {{#each this.params}}{{this.name}}: {{this.ty}}, {{/each}}
        {{#if this.body_param}}form: {{this.body_param.ty}}, {{/if}}
    ) -> {{this.response_type}}:
        """
        {{#if this.description}}{{this.description}}{{else}}{{this.name}}{{/if}}
        """
        {{#if this.params}}
        url = f"{self.base_url}{{this.path}}"{{#each this.params}}{{#if (eq this.location "path")}}.replace("{{this.name}}", str({{this.name}})){{/if}}{{/each}}
        {{else}}
        url = f"{self.base_url}{{this.path}}"
        {{/if}}
        
        {{#if this.query_params.length}}
        params = {}
        {{#each this.query_params}}
        if {{this.name}} is not None:
            params['{{this.name}}'] = {{this.name}}
        {{/each}}
        {{else}}
        params = None
        {{/if}}
        
        {{#if this.body_param}}
        data = json.dumps(form) if form else None
        headers = {'Content-Type': 'application/json'}
        {{else}}
        data = None
        headers = None
        {{/if}}
        
        response = requests.{{this.method}}(url, params=params, data=data, headers=headers)
        response.raise_for_status()
        
        {{#if (eq this.response_type "str")}}
        return response.text
        {{else}}
        return response.json()
        {{/if}}

{{/each}}