Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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