Skip to content

Commit 7302b2e

Browse files
authored
fix(cli): handle security: [] correctly in v3 OpenAPI importer (#11474)
handle correctly in OpenAPI v3 importer
1 parent 7ac0d22 commit 7302b2e

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

packages/cli/api-importers/openapi-to-ir/src/3.1/paths/operations/OperationConverter.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,7 @@ export class OperationConverter extends AbstractOperationConverter {
196196
),
197197
sdkRequest: undefined,
198198
errors,
199-
auth:
200-
this.operation.security != null ||
201-
this.context.spec.security != null ||
202-
this.shouldApplyDefaultAuthOverrides(),
199+
auth: this.computeEndpointAuth(),
203200
security:
204201
this.operation.security ?? this.context.spec.security ?? this.getDefaultSecurityFromAuthOverrides(),
205202
availability: this.context.getAvailability({
@@ -463,6 +460,21 @@ export class OperationConverter extends AbstractOperationConverter {
463460
return convertedResponseBody;
464461
}
465462

463+
private computeEndpointAuth(): boolean {
464+
if (this.operation.security != null && this.operation.security.length === 0) {
465+
return false;
466+
}
467+
468+
if (this.operation.security != null && this.operation.security.length > 0) {
469+
return true;
470+
}
471+
472+
return (
473+
(this.context.spec.security != null && this.context.spec.security.length > 0) ||
474+
this.shouldApplyDefaultAuthOverrides()
475+
);
476+
}
477+
466478
/**
467479
* Converts security scheme IDs to HTTP headers
468480
* @param securitySchemeIds - List of security scheme IDs
@@ -474,7 +486,8 @@ export class OperationConverter extends AbstractOperationConverter {
474486
}
475487

476488
const hasGlobalSecurity = this.context.spec.security != null && this.context.spec.security.length > 0;
477-
const hasEndpointSecurity = this.operation.security != null;
489+
// Check for non-empty endpoint security (empty array means explicit no-auth, not "has security")
490+
const hasEndpointSecurity = this.operation.security != null && this.operation.security.length > 0;
478491

479492
// If there's already security defined (global or endpoint), don't apply defaults
480493
return !(hasGlobalSecurity || hasEndpointSecurity);

packages/cli/api-importers/v3-importer-tests/src/__test__/__snapshots__/v3-sdks/security-explicit-none.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
"queryParameters": [],
259259
"headers": [],
260260
"errors": [],
261-
"auth": true,
261+
"auth": false,
262262
"security": [],
263263
"userSpecifiedExamples": [],
264264
"autogeneratedExamples": [

packages/cli/cli/versions.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# yaml-language-server: $schema=../../../fern-versions-yml.schema.json
2+
- version: 3.37.4
3+
changelogEntry:
4+
- summary: |
5+
Fix `security: []` handling in OpenAPI importer to correctly mark endpoints as not requiring authentication.
6+
type: fix
7+
createdAt: "2026-01-10"
8+
irVersion: 62
29

310
- version: 3.37.3
411
changelogEntry:

0 commit comments

Comments
 (0)