From 8ac7edd46ef6b8ed018c2788025211ff7f2953f4 Mon Sep 17 00:00:00 2001 From: kai ru Date: Tue, 25 Jun 2024 18:30:47 +0800 Subject: [PATCH] Fix read only class code generation issue --- .../cli/controller/az_operation_generator.py | 18 +++++++++--------- .../command/model/configuration/_schema.py | 7 +++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/aaz_dev/cli/controller/az_operation_generator.py b/src/aaz_dev/cli/controller/az_operation_generator.py index 91fa012b..e533c1af 100644 --- a/src/aaz_dev/cli/controller/az_operation_generator.py +++ b/src/aaz_dev/cli/controller/az_operation_generator.py @@ -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): diff --git a/src/aaz_dev/command/model/configuration/_schema.py b/src/aaz_dev/command/model/configuration/_schema.py index 95627a5e..da157f07 100644 --- a/src/aaz_dev/command/model/configuration/_schema.py +++ b/src/aaz_dev/command/model/configuration/_schema.py @@ -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 @@ -879,6 +884,7 @@ class CMDObjectSchemaBase(CMDSchemaBase): # - description # - skip_url_encoding # - client_flatten + # - read_only cls = CMDClassField() def _diff_base(self, old, level, diff): @@ -993,6 +999,7 @@ class CMDArraySchemaBase(CMDSchemaBase): # - required # - description # - skip_url_encoding + # - read_only cls = CMDClassField() def _get_type(self):