Skip to content

api: Allow for an empty string for Isolation in Swagger specs #48616

Merged
thaJeztah merged 1 commit intomoby:masterfrom
dgunzy:47452-allow-empty-isolation-string
Dec 19, 2024
Merged

api: Allow for an empty string for Isolation in Swagger specs #48616
thaJeztah merged 1 commit intomoby:masterfrom
dgunzy:47452-allow-empty-isolation-string

Conversation

@dgunzy
Copy link
Copy Markdown
Contributor

@dgunzy dgunzy commented Oct 9, 2024

- What I did
Modified the Swagger specification to allow an empty string to be a valid option for the Isolation field when inspecting a container with code generated with these specifications. On non Windows systems this is always blank, so it should not give an error in those cases. If there is another approach I should take, or do something different please let me know! I am new to contributing to open source.

- How I did it
I updated the api/swagger.yaml to include - "" as an enum value so it no longer throws an error while inspecting the Isolation field.

- How to verify it

1. generate code e.g. with openapi-generator-cli
2. Inspect container on non-windows system
3. get error about invalid value for Isolation ("")

- Screenshots
Result of inspecting Container Before Change
Before
Result of inspecting Container After Change
After

- Description for the changelog

api: Allow empty string for Isolation field in container inspection

Comment thread api/swagger.yaml
- "default"
- "process"
- "hyperv"
- ""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wondering if we should try if some permutation of "nullable" would work for this; it looks like it's hard to do correct in combination with enum though; OAI/OpenAPI-Specification#1900

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @thaJeztah, having it nullable would be great. I am struggling to have it work successfully with an enum as well.
So far I tried:
oneOf: - type: "null" - type: "string" enum: - "default" - "process" - "hyperv"
Also tried just adding:
Isolation: type: "string" type: "null"
Isolation: type: "string" type: "nullable"
I also added nullable: true, which I think is part of openapi 3.1 I believe which did not work.
All of these still cause my test to fail, and is not recognizing null as valid.
I also noticed that one of the Isolations had a default: "default" and added that to all the different enums, but encountered the same error.

Open to other suggestions!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Yes, I also went looking, and it looks like options are a bit limited for Swagger / OpenAPI 2 sadly. We do have the x-nullable: true option, but I don't think that helps for this case.

Unfortunately, we're currently stuck at OpenAPI 2 (due to some go frameworks we use for these), so I think this is indeed the best we can do for now.

…ds an empty string as a valid option for the Isolation field when inspecting a container. On non windows systems, this is always empty, so no error should be returned. Fixes moby#47452

Signed-off-by: Daniel Guns <[email protected]>
@dgunzy dgunzy force-pushed the 47452-allow-empty-isolation-string branch from f754f30 to 26049fe Compare October 10, 2024 12:48
@dgunzy
Copy link
Copy Markdown
Contributor Author

dgunzy commented Nov 26, 2024

@thaJeztah Would you be able to give the another review if you had time? Happy to try something else if there is more to be done here.

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

I'll do some follow-ups to put these changes in the versioned swagger files we use in our docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty string not allowed for "Isolation" in Swagger specs

3 participants