-
Notifications
You must be signed in to change notification settings - Fork 253
No difference between no security requirement and empty security requirement on Operations #1426
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
Comments
Thank you for bringing this to our attention. We have two options here to solve this problem. We can either add a new // Option 1 - Breaking change
var operation = new OpenApiOperation();
operation.Security = null; // Default value
// Set Anonymous access
operation.Security = new List<OpenApiSecurityRequirement>() [];
// Option 2 - Non breaking change
var operation = new OpenApiOperation();
operation.Security = new List<OpenApiSecurityRequirement>() []; // Default value
operation.AnonymousAccess = false; // Anonymous access default
// Set Anonymous access
operation.AnonymousAccess = true; We can do Option 2 in the current major version of OpenAPI.NET because it is not breaking, however, if we go with Option 1 we will need to wait until the v2 release. |
Personally, I think nulling it, is more in line with what is expected from a dotnet point of view.
Edited: to state the desired option without option number.
|
I think option 1 and 2 have been flipped around, from the description to the examples: Option 1 adding Defaulting to null is the breaking change, so you both seem in agreement to wait for a v2 with it. Null vs. default is similar to how it would be treated in F# (to my understanding) with |
Hello, Any update on this issue ? Thanks |
Hi! Has a decision been reached on how to best proceed? Returning There seems to be a v2 version on it's way as preview5 has been released recently. I might be interested in contributing a fix (since I need a fix 😬) but then it's good to be sure what the approach should be. |
@paulmendix We would be most appreciative of a PR. However, this work should be only done after we have completed the NRT work #1971 and #2146 |
Thanks for the update! I will keep an eye on these issues |
@paulmendix both the NRT and perf work are complete if you'd still like to contribute by sending a PR our way.🙂 |
Thanks @MaggieKimani1 I will give it a go |
…rosoft#1426 make distinction between empty security requirements and no security requirements on an operation. empty security requirements are read as an empty list, no security requirements are read as null for OpenAPI v2/v3/v3.1. This is a breaking change, previously both cases were read as an empty list. also includes a change to OpenApiOperation.SerializeInternal so it can serialize these two cases separately. this required a new method OpenApiWriterExtensions.WriteOptionalOrEmptyCollection. includes unit tests, change to PublicApi.approved.txt to include the new method, and I removed a couple of unused usings and a typo in test name `SerializeDocWithSecuritySchemeWithInlineReferencesWorks`.
…crosoft#1426 make distinction between empty security requirements and no security requirements on an operation. empty security requirements are read as an empty list, no security requirements are read as null for OpenAPI v2/v3/v3.1. This is a breaking change, previously both cases were read as an empty list. also includes a change to OpenApiOperation.SerializeInternal so it can serialize these two cases separately. this required a new method OpenApiWriterExtensions.WriteOptionalOrEmptyCollection. includes unit tests, change to PublicApi.approved.txt to include the new method, and I removed a couple of unused usings and a typo in test name `SerializeDocWithSecuritySchemeWithInlineReferencesWorks`.
Describe the bug
There is no way of telling 'empty' from 'not defined' security requirement objects, during deserialization.
I.e no way of distinguishing the 2 different security requirement objects
Why is this important?
The specification states the following for Operation Security
i.e
security: []
however it is expected that if security is not defined on an operation level
That the global security is applied, defined on the top level document object.
in the following spec
post deserialization, it is impossible to determine which security is actually applied between the 2 operations, as both security requirements are deserialized into the same value
public IList<OpenApiSecurityRequirement> Security { get; set; } = new List<OpenApiSecurityRequirement>();
which ends up being empty in both cases.
The reason for this is most likely that during reading a new
OpenApiSecurityRequirement()
and as this is a dictionary, there is no way of specifying a null key, so to speak.The problem being that the semantics between the 2 operations are different in the spec.
To Reproduce
Deserialize the above spec.
Expected behavior
To have a way of differentiating the 2 scenarios. (feasibly one would be empty, the other would be null.
Screenshots/Code Snippets
The text was updated successfully, but these errors were encountered: