fix(core): validate/remove unused securitySchemes and securityDefinitions correctly#2830
Conversation
🦋 Changeset detectedLatest commit: 8b9854a The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
f9e0615 to
91e2f41
Compare
|
@cursor review |
|
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
📦 A new experimental 🧪 version v0.0.0-snapshot.1779373140 of Redocly CLI has been published for testing. Install with NPM: npm install @redocly/cli@0.0.0-snapshot.1779373140
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1779373140
# or
npm install @redocly/respect-core@0.0.0-snapshot.1779373140 |
91e2f41 to
25d2099
Compare
|
📦 A new experimental 🧪 version v0.0.0-snapshot.1779448714 of Redocly CLI has been published for testing. Install with NPM: npm install @redocly/cli@0.0.0-snapshot.1779448714
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1779448714
# or
npm install @redocly/respect-core@0.0.0-snapshot.1779448714 |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 25d2099. Configure here.
25d2099 to
10890ac
Compare
b5d7491 to
4a59f32
Compare
kanoru3101
left a comment
There was a problem hiding this comment.
I found one issue with the wrong warn/error location
If try with
openapi: 3.1.0
servers:
- url: https://test.com
info:
title: PR 2830 repro — $ref chain between securitySchemes
version: 1.0.0
paths:
/foo:
get:
security:
- base: []
summary: Uses 'derived', which is itself a $ref to 'base'
responses:
'200':
description: ok
components:
securitySchemes:
base:
type: apiKey
name: x-api-key
in: header
derived:
$ref: '#/components/securitySchemes/base'
The warning says "derived" is never used but points to line 18 (base:) instead of line 22 where derived is declared



What/Why/How?
no-unused-componentsrule to validate unused security schemesremove-unused-componentsdecorator to remove unused security schemes (fixed in Swagger 2.0; added in OAS 3.x)Reference
Resolves #944
Testing
Internal tests passed: https://github.com/Redocly/redocly/pull/23392
Screenshots (optional)
Check yourself
Security
Note
Medium Risk
Changes lint warnings and bundle output for security-related components; APIs with defined-but-unreferenced schemes may see new warnings or lose those schemes when bundling with remove-unused-components.
Overview
no-unused-componentsnow treatscomponents.securitySchemes(and Swagger 2securityDefinitions) as used when they appear by name in anysecurityrequirement, not only via$ref. Unused schemes get dedicated diagnostics (e.g.Security scheme: "…" is never used.).remove-unused-componentsuses the same notion of “used” so bundling keeps schemes referenced insecurity(including$refchains between schemes) and can drop schemes that are only defined or only referenced indirectly through an unused base scheme.Docs and changesets note that lint may surface extra warnings and
bundle --remove-unused-componentsmay strip more entries than before.Reviewed by Cursor Bugbot for commit 8b9854a. Bugbot is set up for automated code reviews on this repo. Configure here.