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

Generate object with props and additional properties as FreeFormDictType in CLI #415

Merged
Show file tree
Hide file tree
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
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
Loading