Emit per-operation security metadata behind a feature flag (SOAR-0015) - #927
Open
vdsingh wants to merge 2 commits into
Open
Emit per-operation security metadata behind a feature flag (SOAR-0015)#927vdsingh wants to merge 2 commits into
vdsingh wants to merge 2 commits into
Conversation
Add a `securityMetadata` feature flag that makes the types translator emit the OpenAPI security requirements it currently discards. Each `Operations.<Name>` namespace gains a `securityRequirements` property, and a top-level `OperationSecurity` namespace exposes a `requirementsByOperationID` map, both typed as `[OpenAPIRuntime.SecurityRequirement]`. An operation without a `security` field inherits the document-level requirements; `security: []` is emitted as an empty array (explicitly public). Each AND-group is sorted by scheme name so output is deterministic. Unsupported schemes (mutualTLS, non-bearer/basic HTTP) raise a diagnostic. With the flag off, generated output is unchanged. Requires the SecurityRequirement value types from swift-openapi-runtime. Resolves part of apple#37; see SOAR-0015.
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.
Implements SOAR-0015 (proposal included in this PR) and addresses #37.
Motivation
The generator discards the OpenAPI
security/securitySchemessections entirely, so aClientMiddleware— which only receives anoperationID— cannot tell which operations require authentication, or which scheme. Adopters must either apply credentials unconditionally or hand-maintain a list that drifts from the document (#37, and the per-operation targeting gap in #551).Modifications
Adds a
securityMetadatafeature flag. When enabled,TypesFileTranslatoremits, per operation, the security requirements it currently drops:Semantics mirror OpenAPI: outer array = OR of alternatives, each requirement's
schemes= AND-group,[]= explicitly public; an operation withoutsecurityinherits the document-level requirements. AND-groups are sorted by scheme name for deterministic output. Unsupported cases (mutualTLS, non-bearer/basicHTTP) raise a diagnostic. With the flag off, generated output is byte-identical.Also includes the SOAR-0015 proposal, the
Proposals.mdentry, and the corresponding checkboxes in the supported-features article.Result
Adopters can enable
securityMetadataand drive a conditional-authentication middleware fromOperationSecurity.requirementsByOperationID— applying credentials only where required and failing fast when a required one is missing.Test Plan
Adds reference tests in
SnippetBasedReferenceTestsfor inherited document-level security, operation-level AND/OR groups (apiKey + http-bearer + oauth2), explicitsecurity: [], theOperationSecuritynamespace, and that nothing is emitted when the flag is off. Full suite passes (330 tests). Also dogfooded end-to-end against a real 130-operation document, generating and compiling the metadata (114 authenticated / 16 public) into an app.cc @czechboy0 @simonjbeaumont - flagging per the proposal process.