Skip to content

Additional properties: false to allow better type checking from JSON schemas #3388

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

Closed
wants to merge 3 commits into from
Closed

Additional properties: false to allow better type checking from JSON schemas #3388

wants to merge 3 commits into from

Conversation

quentinus95
Copy link

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tickets fixes #3382
License MIT
Doc PR -

This change sets additional properties to false on all definitions so developers using code generators (e.g. TypeScript code generators from JSON schema) can have safer type checks.

@alanpoulain
Copy link
Member

You should fix the CS too 🙂

@quentinus95
Copy link
Author

Done! I was double checking the failing tests as well but it seems unrelated.

@teohhanhui
Copy link
Contributor

Let's wait for #3402 first, as it'll make use of additionalProperties.

@quentinus95
Copy link
Author

@teohhanhui is there anything I can do to speed up the merging process? Having this change merged and released would highly reduce the bug risks in my production-deployed TypeScript consumers.

@soyuka
Copy link
Member

soyuka commented Feb 26, 2020

@quentinus95 we need to progress at our own pace :|. You should be able to use your fork (and this patch) by tweaking the composer.json file on your project. Would that work temporarily?

@quentinus95
Copy link
Author

@soyuka sure! It was just to be 100% sure nothing more was required on my side.

@quentinus95
Copy link
Author

@teohhanhui any feedback now that #3402 has been merged?

@soyuka
Copy link
Member

soyuka commented Apr 15, 2020

could you rebase? thanks!

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

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

Sorry for the late review...

Can you also rebase please?

@@ -110,6 +110,7 @@ public function buildSchema(string $className, string $format = 'json', string $
}

$definition = new \ArrayObject(['type' => 'object']);
$definition['additionalProperties'] = false;
Copy link
Member

Choose a reason for hiding this comment

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

We should set this flag only if the allow_extra_attributes normalization context option is set to false: #1217

@soyuka
Copy link
Member

soyuka commented Nov 13, 2020

Thanks @quentinus95 ! Superseeded by #3804

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

Successfully merging this pull request may close these issues.

JSON Schemas generated by API Platform should include additionalProperties: false
5 participants