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

Uninherited read-only flag for CMDClsSchemaBase code generation #378

Merged
merged 1 commit into from
Jun 26, 2024
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
18 changes: 9 additions & 9 deletions src/aaz_dev/cli/controller/az_operation_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,24 +940,24 @@ def render_schema(schema, cls_map, name):


def render_schema_base(schema, cls_map, schema_kwargs=None):
if schema_kwargs is None:
schema_kwargs = {}

flags = schema_kwargs.get('flags', {})
# read_only is not inherited by class schema, so we need to set it here
if schema.read_only:
flags['read_only'] = True

if isinstance(schema, CMDClsSchemaBase):
cls_name = schema.type[1:]
schema = cls_map[cls_name].schema
else:
cls_name = getattr(schema, 'cls', None)
cls_builder_name = parse_cls_builder_name(cls_name) if cls_name else None

if schema_kwargs is None:
schema_kwargs = {}


if schema.nullable:
schema_kwargs['nullable'] = True

flags = schema_kwargs.get('flags', {})

if schema.read_only:
flags['read_only'] = True

if isinstance(schema, CMDStringSchemaBase):
schema_type = "AAZStrType"
elif isinstance(schema, CMDIntegerSchemaBase):
Expand Down
7 changes: 7 additions & 0 deletions src/aaz_dev/command/model/configuration/_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ def get_unwrapped(self, **kwargs):
raise NotImplementedError()
data = {k: v for k, v in self.implement.to_native().items() if k in cls._schema.valid_input_keys}
data.update(kwargs)
# uninherent read_only
uninherent = {
"read_only": self.read_only,
}
data.update(uninherent)
unwrapped = cls(data)
return unwrapped

Expand Down Expand Up @@ -879,6 +884,7 @@ class CMDObjectSchemaBase(CMDSchemaBase):
# - description
# - skip_url_encoding
# - client_flatten
# - read_only
cls = CMDClassField()

def _diff_base(self, old, level, diff):
Expand Down Expand Up @@ -993,6 +999,7 @@ class CMDArraySchemaBase(CMDSchemaBase):
# - required
# - description
# - skip_url_encoding
# - read_only
cls = CMDClassField()

def _get_type(self):
Expand Down
Loading