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

config option for additionalProperties on false by default #61

Closed
remuspoienar opened this issue Feb 7, 2020 · 5 comments
Closed

config option for additionalProperties on false by default #61

remuspoienar opened this issue Feb 7, 2020 · 5 comments

Comments

@remuspoienar
Copy link

Hi,

Thanks for writing this library !

Got used to most of the DSLs provided and was wondering if there is a way to configure additionalProperties to be implicitly false on all schemas/subschemas if not specified.

I'd like to be able to either configure it globally in the configuration file or in a schema object and have it applied on all schemas that are nested.

@remuspoienar remuspoienar changed the title option for additionalProperties on false by default config option for additionalProperties on false by default Feb 7, 2020
@zhandao
Copy link
Owner

zhandao commented Feb 7, 2020

The code to handle additionalProperties is: https://github.com/zhandao/zero-rails_openapi/blob/master/lib/oas_objs/schema_obj.rb#L58

Do you mean, when additionalProperties is not specified, this line of code returns a { additionalProperties: false }? (And the behavior is configurable?)

@remuspoienar
Copy link
Author

remuspoienar commented Feb 7, 2020

Yes, that is indeed the behaviour i would like, since in OAS3 additionalProperties is true by default. And i think this should be configurable, since it is not desirable for everyone that uses the library. I use api response validation in tests based on the swagger definition, and i want my tests to fail if new fields are added (when additionalProperties is false in the definition) or removed(when fields are required in the definition).
So adding additionalProperties: false on every schema and nested schemas inside will greatly bloat my code, since its always the same value on every schema

As an example for the following data structure
{ a: { b: { c: { d: 'some string' } } } }

i would have the following schema in the components section of a doc

schema SomeSchema: [ { a!: [ { b!: [ { c!: [ { d!: String }, additional_properties: false ], }, additional_properties: false ] }, additional_properties: false ] }, additional_properties: false ]

If i write in the initializer file something like
self.implicit_additional_properties_value = false

Then i could simplify the above code like this

schema SomeSchema: [ { a!: { b!: { c!: { d!: String } } } } ]

@zhandao
Copy link
Owner

zhandao commented Feb 7, 2020

OK, I'll do this in a few hours.

@zhandao
Copy link
Owner

zhandao commented Feb 8, 2020

Done. Try the latest version 2.1.3.

@zhandao zhandao closed this as completed Feb 13, 2020
@remuspoienar
Copy link
Author

Works great. Thanks so much !

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

No branches or pull requests

2 participants