Skip to content

Commit 907cd84

Browse files
committed
fix(rulesets): allow external references in OAS 3.1 paths
Fix schema validation error where path items with were incorrectly flagged as having unevaluated properties. Changed paths pattern properties to use path-item-or-reference instead of path-item to properly support external references in OpenAPI 3.1 specifications. Fixes issue where documents like: paths: /greetings: $ref: 'greetings.yaml' Would generate: "~1greetings" property must not have unevaluated properties. - Update OAS 3.1 schema to use path-item-or-reference for paths - Add test case for external references validation - Add test harness scenario for CLI integration testing
1 parent 724c7f8 commit 907cd84

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

packages/rulesets/src/oas/__tests__/oas3-schema.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,33 @@ testRule('oas3-schema', [
580580
},
581581
errors: [],
582582
},
583+
{
584+
name: 'oas3.1: document with external references',
585+
document: {
586+
openapi: '3.1.0',
587+
info: {
588+
title: 'Example API',
589+
version: '1.0.0',
590+
description: 'Example API description',
591+
},
592+
paths: {
593+
'/greetings': {
594+
$ref: 'greetings.yaml',
595+
},
596+
},
597+
tags: [
598+
{
599+
name: 'User',
600+
description: 'Info about users',
601+
},
602+
],
603+
servers: [
604+
{
605+
url: 'https://example-url.com',
606+
description: 'Example server',
607+
},
608+
],
609+
},
610+
errors: [], // No errors expected
611+
},
583612
]);

packages/rulesets/src/oas/schemas/oas/v3.1/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@
276276
"type": "object",
277277
"patternProperties": {
278278
"^/": {
279-
"$ref": "#/$defs/path-item"
279+
"$ref": "#/$defs/path-item-or-reference"
280280
}
281281
},
282282
"$ref": "#/$defs/specification-extensions",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
====test====
2+
OAS 3.1 - External References Validation
3+
====document====
4+
openapi: 3.1.0
5+
info:
6+
title: Example API
7+
version: 1.0.0
8+
description: Example API description
9+
paths:
10+
/greetings:
11+
$ref: "{asset:greetings.yaml}"
12+
tags:
13+
- name: User
14+
description: Info about users
15+
servers:
16+
- url: https://example-url.com
17+
description: Example server
18+
====asset:greetings.yaml====
19+
get:
20+
description: Get a greeting
21+
operationId: getGreeting
22+
responses:
23+
"200":
24+
description: OK
25+
content:
26+
application/json:
27+
schema:
28+
type: object
29+
properties:
30+
message:
31+
type: string
32+
example: Hello there!
33+
====asset:ruleset.yaml====
34+
extends: [[spectral:oas, off]]
35+
rules:
36+
oas3-schema: error
37+
====command====
38+
{bin} lint {document} --ruleset {asset:ruleset.yaml} --resolve
39+
====expected-stdout====
40+
No results with a severity of 'error' found!

0 commit comments

Comments
 (0)