Skip to content

Commit

Permalink
[JsonGen] Fix legacy optional (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaszm authored Jun 26, 2024
1 parent ec50515 commit b57b252
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
8 changes: 2 additions & 6 deletions JsonGenerator/source/class_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ def IsObjectRestricted(argument):
return False

def IsObjectOptionalOrOpaque(argument):
if isinstance(argument.parent, JsonMethod):
return False
elif argument.optional:
return False
else:
return (argument.schema.get("opaque") or "required" not in argument.parent.schema or (argument.json_name not in argument.parent.schema["required"]))
_by_required = ("required" in argument.parent.schema and argument.json_name not in argument.parent.schema["required"])
return (argument.schema.get("opaque") or argument.schema.get("@optional") or _by_required) and not argument.optional

def IsObjectOptional(argument):
if argument.optional or IsObjectOptionalOrOpaque(argument):
Expand Down
27 changes: 15 additions & 12 deletions JsonGenerator/source/rpc_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,22 +1001,25 @@ def _Invoke(params, response, parent="", repsonse_parent="", const_cast=False):

index_name = index_name_converted

elif not IsObjectOptional(m.index):
# Ensure the not-optional index is not empty
assert isinstance(m.index, JsonString)
optional_checked = True
elif isinstance(m.index, JsonString):
if not IsObjectOptional(m.index):
# Ensure the not-optional index is not empty
assert isinstance(m.index, JsonString)
optional_checked = True

emit.Line("if (%s.empty() == true) {" % index_name)
emit.Indent()
emit.Line("if (%s.empty() == true) {" % index_name)
emit.Indent()

emit.Line("%s = %s;" % (error_code.temp_name, CoreError("bad_request")))
emit.Line("%s = %s;" % (error_code.temp_name, CoreError("bad_request")))

if is_read_write:
emit.Line("%s%s.Null(true);" % ("// " if isinstance(response, (JsonArray, JsonObject)) else "", response.local_name)) # FIXME
if is_read_write:
emit.Line("%s%s.Null(true);" % ("// " if isinstance(response, (JsonArray, JsonObject)) else "", response.local_name)) # FIXME

emit.Unindent()
emit.Line("} else {")
emit.Indent()
emit.Unindent()
emit.Line("} else {")
emit.Indent()
else:
assert False, "Invalid type for index"

if is_read_write:
emit.Line("if (%s.IsSet() == false) {" % (params.local_name))
Expand Down

0 comments on commit b57b252

Please sign in to comment.