Skip to content

Commit

Permalink
Generate object with props and additional properties as FreeFormDictT…
Browse files Browse the repository at this point in the history
…ype in CLI
  • Loading branch information
kairu-ms committed Oct 9, 2024
1 parent 255effe commit 8372132
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
16 changes: 10 additions & 6 deletions src/aaz_dev/cli/controller/az_arg_group_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ def __init__(self, name, cmd_ctx, arg):
self.props = []
if isinstance(arg, CMDObjectArgBase):
if arg.args and arg.additional_props:
# not support to translate argument with both args and additional_props
raise NotImplementedError()
if arg.args:
# treated as AAZFreeFormDictArg
pass
elif arg.args:
for a in arg.args:
if a.hide:
# escape hide argument
Expand All @@ -116,9 +116,9 @@ def _iter_scopes_by_arg_base(arg, name, scope_define, cmd_ctx):

if isinstance(arg, CMDObjectArgBase):
if arg.args and arg.additional_props:
# not support to translate argument with both args and additional_props
raise NotImplementedError()
if arg.args:
# treated as AAZFreeFormDictArg so no need to iterate
pass
elif arg.args:
for a in arg.args:
if a.hide:
# escape hide argument
Expand Down Expand Up @@ -428,6 +428,10 @@ def render_arg_base(arg, cmd_ctx, arg_kwargs=None):
if arg.additional_props.any_type is True:
arg_type = "AAZFreeFormDictArg"
arg_fmt_cls = "AAZFreeFormDictArgFormat"
elif arg.args and arg.additional_props:
# not support object with both args and additional_props, so we treat it as AAZFreeFormDictArg
arg_type = "AAZFreeFormDictArg"
arg_fmt_cls = "AAZFreeFormDictArgFormat"
else:
assert arg.additional_props.item is not None
arg_type = "AAZDictArg"
Expand Down
42 changes: 29 additions & 13 deletions src/aaz_dev/cli/controller/az_operation_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,14 +610,18 @@ def __init__(self, cmd_ctx, name, schema):
self.props = []
self.discriminators = []
if isinstance(schema, CMDObjectSchemaBase):
if schema.props and schema.additional_props:
raise NotImplementedError()
if schema.discriminators:
if schema.additional_props:
raise NotImplementedError()
for disc in schema.discriminators:
disc_key = to_snake_case(disc.property)
disc_value = disc.value
self.discriminators.append((disc_key, disc_value))
if schema.props:

if schema.props and schema.additional_props:
# treat it as AAZFreeFormDictType
pass
elif schema.props:
for s in schema.props:
s_name = to_snake_case(s.name)
self.props.append(s_name)
Expand All @@ -643,14 +647,23 @@ def _iter_request_scopes_by_schema_base(schema, name, scope_define, arg_key, cmd
search_schemas = {}
discriminators = []
if isinstance(schema, CMDObjectSchemaBase):
if schema.props and schema.additional_props:
# not support for both props and additional props
raise NotImplementedError()

if schema.discriminators:
if schema.additional_props:
raise NotImplementedError()
discriminators.extend(schema.discriminators)

if schema.props:
if schema.props and schema.additional_props:
# treat it as AAZFreeFormDictType
s_name = '{}'
r_key = '.' # if element exist, always fill it

is_const = False
const_value = None
rendered_schemas.append(
(s_name, None, is_const, const_value, r_key, None, None)
)

elif schema.props:
for s in schema.props:
s_name = s.name
s_typ, s_typ_kwargs, cls_builder_name = render_schema(s, cmd_ctx.update_clses, s_name)
Expand Down Expand Up @@ -833,14 +846,16 @@ def _iter_response_scopes_by_schema_base(schema, name, scope_define, cmd_ctx):
search_schemas = {}
discriminators = []
if isinstance(schema, CMDObjectSchemaBase):
if schema.props and schema.additional_props:
# not support to parse schema with both props and additional_props
raise NotImplementedError()

if schema.discriminators:
if schema.additional_props:
raise NotImplementedError()
discriminators.extend(schema.discriminators)

if schema.props:
if schema.props and schema.additional_props:
# treat it as AAZFreeFormDictType
pass
elif schema.props:
for s in schema.props:
s_name = to_snake_case(s.name)
s_typ, s_typ_kwargs, cls_builder_name = render_schema(s, cmd_ctx.response_clses, s_name)
Expand Down Expand Up @@ -970,7 +985,8 @@ def render_schema_base(schema, cls_map, schema_kwargs=None):
if schema.props or schema.discriminators:
schema_type = "AAZObjectType"
if schema.additional_props:
raise NotImplementedError()
# treat it as AAZFreeFormDictType
schema_type = "AAZFreeFormDictType"
elif schema.additional_props:
if schema.additional_props.any_type is True:
schema_type = "AAZFreeFormDictType"
Expand Down

0 comments on commit 8372132

Please sign in to comment.