From b76cae3cb3ac2c3a90d412b1f379a2b84bfb068b Mon Sep 17 00:00:00 2001 From: Gavin Hayes Date: Fri, 10 Jan 2025 11:15:11 -0500 Subject: [PATCH 1/2] hack: list required nullable properties first before non-required properties Workaround nullable refs not being handled (fixed in #23) --- template/plugin/pdk_types.py.ejs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/template/plugin/pdk_types.py.ejs b/template/plugin/pdk_types.py.ejs index edea53e..2a78c5b 100644 --- a/template/plugin/pdk_types.py.ejs +++ b/template/plugin/pdk_types.py.ejs @@ -28,7 +28,16 @@ class <%- pythonTypeName(schema.name) %>(JSONWizard): <% }) %> <% schema.properties.forEach(p => { -%> -<% if (p.nullable || !p.required) {%> +<% if (p.nullable && p.required) {%> + <% if (p.description) { -%> + # <%- formatCommentBlock(p.description, "# ") %> + <% } -%> + <%- p.name %>: <%- toPythonType(p, p.required) %> +<% } %> +<% }) %> + +<% schema.properties.forEach(p => { -%> +<% if (!p.required) {%> <% if (p.description) { -%> # <%- formatCommentBlock(p.description, "# ") %> <% } -%> From 40b6eb9830bde38fe357f83be755afa6d6486006 Mon Sep 17 00:00:00 2001 From: Gavin Hayes Date: Fri, 10 Jan 2025 11:55:57 -0500 Subject: [PATCH 2/2] fix/feat: skip serializing None non-required values --- template/plugin/pdk_types.py.ejs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/template/plugin/pdk_types.py.ejs b/template/plugin/pdk_types.py.ejs index 2a78c5b..cd73582 100644 --- a/template/plugin/pdk_types.py.ejs +++ b/template/plugin/pdk_types.py.ejs @@ -5,7 +5,7 @@ from enum import Enum # noqa: F401 from typing import Optional, List # noqa: F401 from datetime import datetime # noqa: F401 from dataclasses import dataclass # noqa: F401 -from dataclass_wizard import JSONWizard # noqa: F401 +from dataclass_wizard import JSONWizard, skip_if_field, IS # noqa: F401 from dataclass_wizard.type_def import JSONObject from base64 import b64encode, b64decode @@ -41,7 +41,7 @@ class <%- pythonTypeName(schema.name) %>(JSONWizard): <% if (p.description) { -%> # <%- formatCommentBlock(p.description, "# ") %> <% } -%> - <%- p.name %>: <%- toPythonType(p, p.required) %> = None + <%- p.name %>: <%- toPythonType(p, p.required) %> = skip_if_field(IS(None), default=None) <% } %> <% }) %>