Skip to content

Commit

Permalink
Merge pull request #378 from kairu-ms/fix-readonly-cls-generation-issue
Browse files Browse the repository at this point in the history
Uninherited read-only flag for CMDClsSchemaBase code generation
  • Loading branch information
necusjz authored Jun 26, 2024
2 parents 38a4f6b + 8ac7edd commit d3fa8c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
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

0 comments on commit d3fa8c9

Please sign in to comment.