Skip to content

Commit fde1451

Browse files
committed
feat(rulesets): improve OAS 3.1 external references validation
- Update OAS 3.1 schema to better support external references - Add external references test scenario in test-harness - Update Arazzo schema validators to use improved OAS 3.1 schema - Enhance OAS 3 schema test coverage Fixes issues with external reference validation in OpenAPI 3.1 documents.
1 parent 724c7f8 commit fde1451

File tree

4 files changed

+71
-2
lines changed

4 files changed

+71
-2
lines changed

packages/rulesets/src/arazzo/schemas/validators.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

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 Ref 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: "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}
39+
====stdout====
40+
No results with a severity of 'error' found!

0 commit comments

Comments
 (0)