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

feat: support empty free-form object #342

Merged
merged 1 commit into from
Mar 25, 2024

Conversation

necusjz
Copy link
Member

@necusjz necusjz commented Mar 25, 2024

Resolve: #339

image

@necusjz necusjz requested a review from AllyW March 25, 2024 06:26
@necusjz necusjz self-assigned this Mar 25, 2024
@necusjz necusjz merged commit 3bb5d41 into Azure:dev Mar 25, 2024
3 checks passed
@@ -544,7 +544,7 @@ def to_cmd(self, builder, **kwargs):
model.props.append(prop)

# additional properties
if self.additional_properties:
if self.additional_properties or not any([model.props, model.additional_props, model.discriminators]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to refactor the loop like this:

if self.additional_properties:

elif not any([model.props, model.additional_props, model.discriminators]):

@@ -544,7 +544,7 @@ def to_cmd(self, builder, **kwargs):
model.props.append(prop)

# additional properties
if self.additional_properties:
if self.additional_properties or not any([model.props, model.additional_props, model.discriminators]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I still have some concern, may be it's better add _patch here instead of changing this logic

def _patch_dict(dct):
for key in [*dct.keys()]:
if key == "additionalProperties" and dct[key] == {}:
# replace `additionalProperties: {}` by `additionalProperties: true`
dct[key] = True
_patch(dct[key])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants