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

Add python client generation to /example #27

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
30 changes: 25 additions & 5 deletions example/client.py.plush
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,25 @@ class Client:


<%= for (object) in def.Objects { %>class <%= object.Name %>:
"""<%= format_comment_line(object.Comment) %>"""
"""
<%= format_comment_line(object.Comment) %>

Attributes
----------
<%= for (field) in object.Fields { %><%=field.NameLowerCamel%> : <%= field.Type.PythonType %>
<%= format_comment_line(field.Comment) %>
<% } %>
"""

def __init__(self<%= for (field) in object.Fields { %>, <%=field.NameLowerCamel%>:<%= field.Type.PythonType%><% } %>) -> None:
<%= for (field) in object.Fields { %>self.<%=field.NameLowerCamel%> = <%=field.NameLowerCamel%>
def __init__(self<%= for (field) in object.Fields { %>, <%= field.NameLowerCamel %>: <%= field.Type.PythonType %><% } %>) -> None:
"""
Constructs all of the neccesary attributes for the <%= object.Name %>

<%= for (field) in object.Fields { %><%=field.NameLowerCamel%> : <%= field.Type.PythonType %>
<%= format_comment_line(field.Comment) %>
<% } %>
"""
<%= for (field) in object.Fields { %>self.<%= field.NameLowerCamel %> = <%= field.NameLowerCamel %>
<% } %>
<% } %>
<%= for (service) in def.Services { %>class <%= service.Name %>:
Expand All @@ -26,8 +41,13 @@ class Client:
def __init__(self, client):
self.client = client
<%= for (method) in service.Methods { %>
def <%= method.NameLowerCamel %>(self, <%= method.InputObject.ObjectName %>) -> <%=method.OutputObject.ObjectName%>:
"""<%= format_comment_line(method.Comment) %>"""
def <%= method.NameLowerCamel %>(self, <%= method.InputObject.ObjectName %>: <%= method.InputObject.ObjectName %>) -> <%=method.OutputObject.ObjectName%>:
"""
<%= format_comment_line(method.Comment) %>

:param <%= method.InputObject.ObjectName %> <%= method.InputObject.ObjectName %>:

"""
url = "{}/<%= service.Name %>.<%= method.Name %>".format(self.client.endpoint)
headers = {
'Accept': 'application/json; charset=utf8',
Expand Down
83 changes: 0 additions & 83 deletions example/clientgen.py

This file was deleted.

2 changes: 1 addition & 1 deletion example/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ oto -template client.js.plush \
echo "generated client.gen.js"

oto -template client.py.plush \
-out clientgen.py \
-out ./python/clientgen.py \
-pkg main \
./def
echo "generated client.gen.py"
Expand Down