-
Notifications
You must be signed in to change notification settings - Fork 30
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
JsonOverlay should not remove security: [] #235
Comments
@chris-brace , not sure whether it's helpful to point this out, but it seems what you want is an empty array, not an empty object. Is there a serialization option to remove empty objects, but preserve empty arrays? If so, would that still give you too much noise in the serialized OpenAPI doc, and ensuing errors, warnings, etc.? Is there a way to explicitly set the value of the Sorry that I don't know the answers to these questions, and I'm not set up to look at it right now. But if my musings here don't lead to a solution, I will take a closer look, hopefully next week. |
A hunch: Security Requirement Object is a map of Security Scheme names to an array of scope requirements for that security scheme. In KZOP,
I think the
At first glance, it seems like we need a similar solution for SecurityRequirements. We know this works for SecurityParameter, because OpenAPI requires empty scope arrays on Security Requirement Objects for schemes of any type other than oauth2 or openIdConnect. The requirement for empty scope array is explicit in the spec, and is very commonly used in lots of API documents.
Empty security requirements array as a
The open pull request #1886 adds explicit support for an empty Security Requirement Object in the array. It's intended for cases where security is optional, as in this example, showing the empty object in an array with other, non-empty Security Requirement Objects. I'm guessing you'll hit the same problem, trying to create an array with a single, empty Security Requirement object. This needs a little more thought... |
Sorry, I edited my issue to be specific that what i want is, in the case that it is present, an empty list for |
@chris-brace , just to cover the bases, it would help to know:
|
@chris-brace , I took some time this weekend to experiment with serialization, focusing on several cases of empty objects and empty arrays that are meaningful in Security Scheme and Security Requirement objects. You can see an OpenAPI YAML test input and failing JUnit test in the task/#235 branch. It seems that the problems with serialization are pretty extensive. There is the big problem of empty objects and empty arrays described in the docs:
Also described in issue #114. I am also seeing that So it seems that serialization is incomplete, not ready for real use at this point. You can use the parser to read, traverse, and inspect an OpenAPI model (which is what our application code does), even modify the OpenAPI model in-memory, but not to write changes back to a file. The fix for these problems is going to require some design changes that are beyond what we can do right now. I'd like to keep this open as a back-burner issue, and try to rework the design to handle serialization properly. But I can't offer a time frame for this. |
Thank you for your thorough analysis! I understand what’s wrong and perhaps
at some point I’ll be able to take a look for myself. In the mean time I’ve
gotten it working with the little hacks I described :)
|
I am serializing a OAS3 model to YAML using the following boilerplate described in the docs
My API has a default security scheme applied to all routes except one, which defines
security: []
to override the rootsecurity
object as is (extremely poorly) described in "step two" of this document https://swagger.io/docs/specification/authentication/ . The serializers remove this, so right now i am doing some gross string substitution to fix it.The point is, that empty list has significance.
Also, I am aware that I can disable removal of all empty lists and objects using serialization options, but this is not what i want to do as the output generates tons of errors and warnings from parsers and editors.
In case anyone else ends up here my gross solution is, for the following spec:
I do the following to the final, serialized, prettyprinted YAML file:
The text was updated successfully, but these errors were encountered: