Skip to content
Merged
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
13 changes: 13 additions & 0 deletions template/plugin/pdk_types.py.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@ class <%- capitalize(schema.name) %>(extism.Json):
<% if (p.description) { -%>
# <%- formatCommentBlock(p.description, "# ") %>
<% } -%>
<% if (!p.nullable) {%>
<%- p.name %>: <%- toPythonType(p) %>
<% } %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the only difference b/w these two loops is the nullable part. maybe we can merge them something like this?


@dataclass
class <%- capitalize(schema.name) %>(extism.Json):
<% schema.properties.forEach(p => { -%>
<% if (p.description) { -%>
  # <%- formatCommentBlock(p.description, "# ") %>
<% } -%>
<% if (p.nullable) {%>
  <%- p.name %>: <%- toPythonType(p) %> = None
<% } else { %>
  <%- p.name %>: <%- toPythonType(p) %>
<% } %>
<% }) %>

<% } %>
<% }); %>

or just customize the = None part

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an ordering issue, the fields with default values have to come after the fields with no defaults.

<% }) %>

<% schema.properties.forEach(p => { -%>
<% if (p.description) { -%>
# <%- formatCommentBlock(p.description, "# ") %>
<% } -%>
<% if (p.nullable) {%>
<%- p.name %>: <%- toPythonType(p) %> = None
<% } %>
<% }) %>

<% } %>
<% }); %>