Skip to content

Commit

Permalink
Merge pull request #428 from kairu-ms/fix-cdn-issue
Browse files Browse the repository at this point in the history
Apply cls defintions repeatly to avoid definition loss.
  • Loading branch information
kairu-ms authored Nov 19, 2024
2 parents 941b3d0 + fedb2c6 commit ea0344d
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions src/aaz_dev/swagger/model/schema/cmd_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
CMDArraySchema, CMDArraySchemaBase, \
CMDClsSchema, CMDClsSchemaBase, \
CMDHttpResponseJsonBody
from command.controller.workspace_cfg_editor import WorkspaceCfgEditor

from swagger.model.specs._utils import operation_id_separate
from swagger.utils import exceptions
Expand Down Expand Up @@ -625,30 +626,37 @@ def apply_cls_definitions(self, *cmd_ops):
for name, definition in self.cls_definitions.items():
if definition['count'] > 1:
definition['model'].cls = name
schema_cls_register_map = {}
for cmd_op in cmd_ops:
cmd_op.register_cls(cls_register_map=schema_cls_register_map)

for name, cls_register in schema_cls_register_map.items():
if cls_register.get('implement', None):
continue
from command.controller.workspace_cfg_editor import WorkspaceCfgEditor
new_schema = None

for parent, schema, _ in WorkspaceCfgEditor.iter_schema_cls_reference_in_operations(cmd_ops, name):
if schema.frozen:
continue

if new_schema is not None:
schema.implement = new_schema
new_schema.cls = name
check = True
while check:
check = False
schema_cls_register_map = {}
for cmd_op in cmd_ops:
cmd_op.register_cls(cls_register_map=schema_cls_register_map)

for name, cls_register in schema_cls_register_map.items():
if cls_register.get('implement', None):
continue

new_schema = schema.get_unwrapped()
new_schema.cls = None
assert new_schema is not None
WorkspaceCfgEditor.replace_schema(parent, schema, new_schema)
self.cls_definitions[name]['model'] = new_schema
new_schema = None

for parent, schema, _ in WorkspaceCfgEditor.iter_schema_cls_reference_in_operations(cmd_ops, name):
if schema.frozen:
continue

if new_schema is not None:
schema.implement = new_schema
new_schema.cls = name
continue

# the linked implement will be lost when it's rebuild in the get_unwrapped()
schema.implement = self.cls_definitions[name]['model']
new_schema = schema.get_unwrapped()
assert new_schema is not None
new_schema.cls = None
WorkspaceCfgEditor.replace_schema(parent, schema, new_schema)
self.cls_definitions[name]['model'] = new_schema
# because the schema is updated, need to re-check the loop
check = True

def get_pageable(self, path_item, op):
pageable = getattr(path_item, self.method).x_ms_pageable
Expand Down

0 comments on commit ea0344d

Please sign in to comment.