...
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
class {{ class_name }}(BaseModel):
|
||||
{% for prop_name, prop_info in properties.items() -%}
|
||||
{{ prop_name }}: {{prop_info.type_name}} = {{python_code_generator.get_pydantic_field_params(prop_info)}}
|
||||
{% endfor %}
|
18
_archive/openrpc/generator/code/python/templates/enum.jinja
Normal file
18
_archive/openrpc/generator/code/python/templates/enum.jinja
Normal file
@@ -0,0 +1,18 @@
|
||||
{% if is_integer %}
|
||||
class {{ type_name }}(Enum):
|
||||
{% for elem in enum -%}
|
||||
{{ number_to_words(elem) }} = {{ elem }}
|
||||
{% endfor %}
|
||||
{% else -%}
|
||||
class {{ type_name }}(str, Enum):
|
||||
{% for elem in enum -%}
|
||||
{{ elem.upper() }} = '{{ elem }}'
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{# @classmethod
|
||||
def load(cls, data: Dict[str, Any]) -> "{{type_name}}":
|
||||
return cls(
|
||||
{% for elem in enum -%}
|
||||
{{elem}} = data.get('{{elem}}'),
|
||||
{% endfor %}
|
||||
) #}
|
@@ -0,0 +1,30 @@
|
||||
{% if method_example != "" -%}
|
||||
# Example:
|
||||
# {{ method_example }}
|
||||
{% endif -%}
|
||||
def {{ function_name }}({{ python_code_generator.get_method_params(method_params) }}){% if method_result %} -> {{ method_result }}{% endif %}:
|
||||
{% if method_description != "" -%}
|
||||
"""
|
||||
{{ method_description }}
|
||||
"""
|
||||
{% endif -%}
|
||||
url = "{{base_url}}"
|
||||
headers = {"content-type": "application/json"}
|
||||
|
||||
params = {
|
||||
{% for param_name, param_type in method_params.items() -%}
|
||||
'{{ param_name }}': {{ param_name }},
|
||||
{% endfor -%}
|
||||
}
|
||||
|
||||
response = requests.post(url, json={"jsonrpc": "2.0", "id": 0, 'method': '{{ method_name }}', 'params': params}, headers=headers).json()
|
||||
|
||||
{% if return_type -%}
|
||||
{% if python_code_generator.is_primitive(return_type) -%}
|
||||
return response['result']
|
||||
{% else -%}
|
||||
return {{return_type}}(response['result'])
|
||||
{% endif -%}
|
||||
{% else -%}
|
||||
response.raise_for_status()
|
||||
{% endif -%}
|
@@ -0,0 +1,5 @@
|
||||
from typing import List, Optional, Union, Any, Dict
|
||||
from pydantic import BaseModel, Field
|
||||
from enum import Enum
|
||||
import requests
|
||||
|
Reference in New Issue
Block a user