fix(generator): an operation declaring security: [] still got the credential - #107
Open
giraffesyo wants to merge 1 commit into
Open
fix(generator): an operation declaring security: [] still got the credential#107giraffesyo wants to merge 1 commit into
giraffesyo wants to merge 1 commit into
Conversation
…dential Auth was applied in do for every request the client made, and no per-operation security reached the IR, so an endpoint the spec documents as needing no credential received one anyway: sent to that host, written to its logs, and against what the spec plainly said. An empty security requirement now reaches the operation and turns the credential off for it. An absent one is a different declaration and still inherits the document's, so only the explicit opt-out changes. Choosing between several schemes per operation is left alone: the client holds one AuthProvider, and honoring per-operation selection means either several providers or one that knows which scheme it satisfies. The opt-out does not depend on that being settled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #105.
Auth was applied in
dofor every request, and no per-operation security reached the IR at all. A bearer token went to an endpoint the spec documents as needing none, landing in that server's logs, and an unauthenticated endpoint is the one most likely to be served by something other than the API itself.Absent and empty are different declarations
libopenapi distinguishes them, so the analyzer can too: an absent
securityfield arrives as nil and inherits the document's, an empty one arrives as a non-nil empty slice and overrides it. Only the second opts out. An operation naming a scheme explicitly still authenticates.dotakes anauthenticatedargument rather than reading anything global, so the decision is made per operation at generation time and is visible in the generated call.Scope
Choosing between several schemes per operation, or requiring several at once, is deliberately untouched. The client holds one
AuthProvider, and honoring per-operation selection means either several providers or a provider that knows which scheme it satisfies, which is a design question the opt-out does not depend on.ir.OperationDef.SecurityReqsremains unpopulated, as it was.Tests
internal/analyzer/security_test.go: an operation that declares nothing inherits, one withsecurity: []opts out, one naming a scheme does not.internal/generator/e2e_operation_security_test.go: compiles and runs againsthttptest, checking the inheriting operation still sendsBearer s3cr3twhile the public one sends nothing, that opting out changes nothing else about the request (the body still goes), and that a client with no provider is unaffected.gofmt,go vet ./..., andgo test ./...pass.