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

AdditionalProperties true by default #139

Closed
injeniero opened this issue Feb 21, 2024 · 4 comments
Closed

AdditionalProperties true by default #139

injeniero opened this issue Feb 21, 2024 · 4 comments

Comments

@injeniero
Copy link
Contributor

Hi @LucasRoesler!

While I was working on the issue #136 I found that starting from OpenAPI 3.0.2 they clarified that additionalProperties is true by default.

The current implementation does not follow this. So wanted to start a discussion on this, should this be fixed?

@injeniero
Copy link
Contributor Author

injeniero commented Feb 21, 2024

I personally don't like the idea of having to set additionalProperties: false on every schema. Feels like an odd direction to follow, but it is the standard. Not sure how many generators respect this.

I would be fine not following it and explain that in the documentation. I think the current implementation is as follow:

Object with no properties

Here it assumes additionalProperties: true

type: object
map[string]interface{}

Object with additionalProperties set to true|{}

This is just like not setting it

type: object
additionalProperties: true|{}
map[string]interface{}

Object with additionalProperties set to false

This is a weird case, but it should be supported.

type: object
additionalProperties: false
struct{}

Object with properties

It assumes additionalProperties: false

type: object
properties:
  field1:
    type: string
struct {
  Field1 string
}

Object with properties and additionalProperties set to true|{}

type: object
properties:
  field1:
    type: string
additionalProperties: true|{}
struct {
  Field1 string
  AdditionalProperties map[string]interface{}
}

@LucasRoesler
Copy link
Member

I very much agree with you, this is a weird default and would be very annoying to model and use in Go. I would rather document this as an exception.

@LucasRoesler
Copy link
Member

I guess we could also consider a flag --strict to toggle this behavior.

But it is definitely not something I would use. When I am designing an API I never assume additional properties, I design the fields I want and only rarely allow additional properties when the application needs it.

@injeniero
Copy link
Contributor Author

Great, I was also thinking on the "--strict" flag, but that could be something for the future.

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