-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Webhook openAPI spec and code disagrees on property casing #5110
Comments
The API is yaml and not a JSON ;-). The api/webhook.yaml file is manually generated (see blame). Ideally, automating its generation would have addressed this issue. |
Not sure what you mean. external-dns sends JSON to the webhook provider APIs. Not Yaml. The openAPI spec may be YAML, but end of the day we're dealing with JSON objects. All of the other JSON objects sent to the webhook provider follow lowerCamelCase convention for property names. So, I would reason the idea is to use lowerCamelCase and the fact that Changes struct doesn't have the proper lowerCamelCase name overrides in the Go json tags is not how it should be. |
I'm not familiar with the webhook api. You pointed to a manually generate yaml file..... This is the method where Encoding and Decoding is happening
While is nice to have json tags on objects, they are not required for Go.... Proof how it works, you could have any case when tags not set, is actually more flexible, thereby promoting language-agnostic compatibility. Open API speck expects that implementations can handle different casing variations of the same logical property name. Please explain why tagging on that Structs is needed, not sure why it's a bug. OpenAPI specifies that schema element names are case insensitive for schema element names (within the same scope). The OpenAPI spec focuses on the structure and semantics of the API, rather than strict naming conventions for element names. So you could have any case you like, to provide out-of-the box compatibility with other protocols or programming languages out-of-the-box conventions. crEate:
$ref: '#/components/schemas/endpoints'
updateold:
$ref: '#/components/schemas/endpoints'
updaTenew:
$ref: '#/components/schemas/endpoints'
DELETE:
$ref: '#/components/schemas/endpoints' I prefer camelCase as well. There probably no harm to add json tags, but not too sure, this may break some compatibility. |
Actually no, that's just one of Go idiosyncrasies, where it tries to be helpful and unmarshal things case-insensitively. OpenAPI spec, JavaScript, and many other environments that deal with JSON are case-sensitive by default. For example, if you run the following in your browser devconsole (or in a playground): let data = JSON.parse('{"CreAtE": "foo"}');
console.log('Parsed data', data);
console.log('Value of create', data.create);
console.log('Value of CreAtE', data.CreAtE); You can see that the properties are case-sensitive. Why I stumbled upon this was because I was implementing a webhook in Rust and it caused some headbanging. From my (the users) point of view, one of the two places should be fixed:
Since I'm not the maintainer of this project, I'm in no position to decide which one is correct. As you pointed out there may be some compatibility issues; however, if all the existing webhooks are Go based it won't affect them. |
Exactly same behaviour in Node
You could try here https://playcode.io/new I'm more then sure, .Net behaves exactly the same, even by convention expected fist letter to be capitilise. From the specification itself, the response content itself does not have a strict case-sensitivity rule. This feels like is outside of Open API spec, so if we discussing JSON, is most likely one of the JSON specification (RFC XXXX). I'm easy where or not tags a present on Go. And I agree
I'll add a label, feel free to open a pull request. /help |
@ivankatliarchuk: GuidelinesPlease ensure that the issue body includes answers to the following questions:
For more details on the requirements of such an issue, please see here and ensure that they are met. If this request no longer meets these requirements, the label can be removed In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
What happened:
In the api/webhook.yaml openAPI spec, the changes component lists the properties as starting with lower-case.
external-dns/api/webhook.yaml
Lines 250 to 257 in 58ac76e
However, the Changes struct in Go side doesn't have the JSON tag giving it an eplicit name, so Go will default to the field names (
Create
,UpdateOld
,UpdateNew
,Delete
) in the generated JSON.external-dns/plan/plan.go
Lines 55 to 64 in 58ac76e
What you expected to happen:
I would expect the openAPI spec and code to agree. Even though Go doesn't care about casing, other platforms do.
How to reproduce it (as minimally and precisely as possible):
Anything else we need to know?:
Environment:
external-dns --version
): v0.15.1The text was updated successfully, but these errors were encountered: