Skip to content

Add openapi:additionalProperties Meta #3644

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

Merged
merged 3 commits into from
Feb 6, 2025

Conversation

tchssk
Copy link
Member

@tchssk tchssk commented Feb 3, 2025

#2850

  • Currently only boolean values ​​are supported.
  • This is a feature that only affects OpenAPI, but we would like to consider real server validation functionality in the future.

@tchssk tchssk marked this pull request as ready for review February 3, 2025 14:27
@raphael
Copy link
Member

raphael commented Feb 4, 2025

My understanding is that additionalProperties should only be true for maps in Go, Go objects do not make it possible to dynamically add fields to them. Maybe we should instead always set it to false except for maps (which is already taken into consideration)? The specification says:

Consistent with JSON Schema, additionalProperties defaults to true.

So it does seem like we should always generate it and set it to false except for maps.

@tchssk
Copy link
Member Author

tchssk commented Feb 4, 2025

Sorry, I didn't explain it enough. This function was supposed to set additionalProperties: false on an object.

In this case, bar is sent even though it is not defined in the OpenAPI schema, but that is OK because additionalProperties is considered true by default.

OpenAPI schema

Payload:
    title: Payload
    type: object
    properties:
        foo:
            type: string

Incoming request

{"foo":"1","bar":"2"}

If additionalProperties: false is specified, this will be considered an invalid request and will cause OpenAPI validation errors in many libraries.

All of this is about OpenAPI and has nothing to do with the actual server implementation. In terms of Go encoding/json, if the unmarshal target contains undefined fields, they are simply ignored.

@raphael
Copy link
Member

raphael commented Feb 4, 2025

Ah great, that makes sense! Thank you for the explanation.

@raphael raphael merged commit 25c8744 into goadesign:v3 Feb 6, 2025
11 checks passed
@tchssk tchssk deleted the dsl-meta-openapi-additionalproperties branch February 22, 2025 02:06
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.

2 participants