Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

16 findHWReservationById API response schema patch #52

Merged
merged 8 commits into from
Jan 11, 2023

Conversation

rinzler-17
Copy link
Contributor

Addresses #51

Description
Following schema worked with the previous version of openapi-generator:

"customdata": {
"default": {}
}

When autocommit bumped the generator version to 6.3.0-SNAPSHOT, oas build errored which has been fixed with "default": null.
Also, response schema of findHardwareReservationById has been changed From Device to HardwareReservation.

@rinzler-17 rinzler-17 self-assigned this Jan 9, 2023
@rinzler-17 rinzler-17 requested a review from displague January 9, 2023 06:47
@rinzler-17 rinzler-17 added bug Something isn't working enhancement New feature or request labels Jan 9, 2023
"customdata": {
"description": "Customdata is an arbitrary JSON value that can be accessed via the\nmetadata service.",
- "default": {}
+ "default": null
Copy link
Member

@displague displague Jan 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backend allows for this field to be submitted as a JSON string ("customdata": "{\"foo\": \"bar\"}") or as an object ("customdata": {"foo":"bar"}).

When omitted in the request, the default value in the response is : {} (an empty object).

My inclination here would be to represent the field as an object with default {}. Is the problem that type: object and additionalProperties (https://swagger.io/docs/specification/data-models/dictionaries/#free-form) was not included in the OAS3 spec?

Suggested change
+ "default": null
"default": {},
"type": "object",
"additionalProperties": true,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backend allows for this field to be submitted as a JSON string ("customdata": "{\"foo\": \"bar\"}") or as an object ("customdata": {"foo":"bar"}).

So with this change, customdata will have one string key "{\"foo\": \"bar\"}" mapped to null or an empty string "" mapped to {"foo":"bar"} after deserialization?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customdata is the key to an arbitrary value. You may submit a string, null, a boolean, or an object here.

However, if the request looks like quoted JSON, it will be parsed. See the "serialized in" columns of this table: equinixmetal-archive/packngo#225 (comment)

This is why I believe the best OAS3 approach will be additionalProperties: true, with type: object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, incorporated suggestion in 2587209

@@ -7741,7 +7741,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Device"
"$ref": "#/components/schemas/HardwareReservation"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙃 Nice find.

@rinzler-17 rinzler-17 requested a review from displague January 11, 2023 02:57
@displague displague merged commit 8c7aeae into equinix-labs:main Jan 11, 2023
@displague
Copy link
Member

Thanks, @rinzler-17. I'll start the process of upstreaming this spec change.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API spec] findHardwareReservationById response and customdata default in DeviceCreateInput are incorrect
2 participants