Skip to content

Commit 402c1f3

Browse files
committed
Tests for unevaluatedProperties
1 parent 4c6dc2a commit 402c1f3

File tree

4 files changed

+197
-0
lines changed

4 files changed

+197
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
openapi: 3.3.0
2+
info:
3+
title: API
4+
version: 1.0.0
5+
components:
6+
schemas:
7+
discriminator-with-unevaluated-properties:
8+
type: object
9+
discriminator:
10+
not-allowed: here
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
openapi: 3.3.0
2+
info:
3+
title: API
4+
version: 1.0.0
5+
components:
6+
schemas:
7+
externalDocs-with-unevaluated-properties:
8+
type: object
9+
externalDocs:
10+
url: https://example.com/docs
11+
not-allowed: here

tests/schema/minimal-objects.yaml

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Minimal instances of Objects defined in the OpenAPI specification
2+
#
3+
# Each instance includes only the required properties for that Object.
4+
# These instances are used to verify that the Object does not allow additional properties.
5+
6+
# OpenAPI Object has separate test cases
7+
8+
- objectName: Info Object
9+
subSchemaPath: /$defs/info
10+
minimalInstance:
11+
title: Sample API
12+
version: 1.0.0
13+
14+
- objectName: Contact Object
15+
subSchemaPath: /$defs/contact
16+
minimalInstance: {}
17+
18+
- objectName: License Object
19+
subSchemaPath: /$defs/license
20+
minimalInstance:
21+
name: Apache 2.0
22+
23+
- objectName: Server Object
24+
subSchemaPath: /$defs/server
25+
minimalInstance:
26+
url: https://example.com/docs
27+
28+
- objectName: Server Variable Object
29+
subSchemaPath: /$defs/server-variable
30+
minimalInstance:
31+
default: defaultValue
32+
33+
- objectName: Components Object
34+
subSchemaPath: /$defs/components
35+
minimalInstance: {}
36+
37+
- objectName: Paths Object
38+
subSchemaPath: /$defs/paths
39+
minimalInstance: {}
40+
41+
- objectName: Path Item Object
42+
subSchemaPath: /$defs/path-item
43+
minimalInstance: {}
44+
45+
- objectName: Operation Object
46+
subSchemaPath: /$defs/operation
47+
minimalInstance: {}
48+
49+
- objectName: External Documentation Object
50+
subSchemaPath: /$defs/external-documentation
51+
minimalInstance:
52+
url: https://example.com/docs
53+
54+
- objectName: Parameter Object
55+
subSchemaPath: /$defs/parameter
56+
minimalInstance:
57+
name: sampleParam
58+
in: query
59+
schema: # content could also be used, one of them is required
60+
type: string
61+
62+
- objectName: Request Body Object
63+
subSchemaPath: /$defs/request-body
64+
minimalInstance:
65+
content:
66+
application/json:
67+
schema:
68+
type: object
69+
70+
- objectName: Media Type Object
71+
subSchemaPath: /$defs/media-type
72+
minimalInstance: {}
73+
74+
- objectName: Encoding Object
75+
subSchemaPath: /$defs/encoding
76+
minimalInstance: {}
77+
78+
- objectName: Responses Object
79+
subSchemaPath: /$defs/responses
80+
minimalInstance:
81+
default: {} # or "200": {}, any response would do, Responses Object requires at least one response
82+
83+
- objectName: Response Object
84+
subSchemaPath: /$defs/response
85+
minimalInstance: {}
86+
87+
- objectName: Callback Object
88+
subSchemaPath: /$defs/callbacks
89+
minimalInstance: {}
90+
91+
- objectName: Example Object
92+
subSchemaPath: /$defs/example
93+
minimalInstance: {}
94+
95+
- objectName: Link Object
96+
subSchemaPath: /$defs/link
97+
minimalInstance:
98+
operationId: sampleOperation # operationRef could also be used, one of them is required
99+
100+
- objectName: Header Object
101+
subSchemaPath: /$defs/header
102+
minimalInstance:
103+
schema: # content could also be used, one of them is required
104+
type: string
105+
106+
- objectName: Tag Object
107+
subSchemaPath: /$defs/tag
108+
minimalInstance:
109+
name: Sample Tag
110+
111+
# Reference Object allows additional properties (which SHALL be ignored)
112+
113+
# Schema Object allows additional properties
114+
115+
# Discriminator Object is defined in meta.yaml, test case fail/discriminator-unexpected-property.yaml
116+
117+
# XML Object is defined in meta.yaml
118+
119+
- objectName: Security Scheme Object (HTTP Basic)
120+
subSchemaPath: /$defs/security-scheme
121+
minimalInstance:
122+
type: http
123+
scheme: basic
124+
125+
- objectName: OAuth Flows Object
126+
subSchemaPath: /$defs/oauth-flows
127+
minimalInstance: {}
128+
129+
- objectName: OAuth Flow Object (implicit)
130+
subSchemaPath: /$defs/oauth-flows/$defs/implicit
131+
minimalInstance:
132+
authorizationUrl: https://example.com/auth
133+
scopes: {}
134+
135+
- objectName: OAuth Flow Object (password)
136+
subSchemaPath: /$defs/oauth-flows/$defs/password
137+
minimalInstance:
138+
tokenUrl: https://example.com/token
139+
scopes: {}
140+
141+
- objectName: OAuth Flow Object (clientCredentials)
142+
subSchemaPath: /$defs/oauth-flows/$defs/client-credentials
143+
minimalInstance:
144+
tokenUrl: https://example.com/token
145+
scopes: {}
146+
147+
- objectName: OAuth Flow Object (authorizationCode)
148+
subSchemaPath: /$defs/oauth-flows/$defs/authorization-code
149+
minimalInstance:
150+
authorizationUrl: https://example.com/auth
151+
tokenUrl: https://example.com/token
152+
scopes: {}
153+
154+
- objectName: OAuth Flow Object (deviceAuthorization)
155+
subSchemaPath: /$defs/oauth-flows/$defs/device-authorization
156+
minimalInstance:
157+
deviceAuthorizationUrl: https://example.com/device
158+
tokenUrl: https://example.com/auth
159+
scopes: {}
160+
161+
# Security Requirement Object allows additional properties

tests/schema/schema.test.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,19 @@ describe("v3.3", () => {
5353
});
5454
});
5555
});
56+
57+
describe("Unevaluated properties in schema.yaml subschemas", () => {
58+
const schema = "https://spec.openapis.org/oas/3.3/schema/WORK-IN-PROGRESS";
59+
const minimalObjects = parseYamlFromFile("./tests/schema/minimal-objects.yaml");
60+
61+
for (const { objectName, subSchemaPath, minimalInstance } of minimalObjects) {
62+
test(objectName, async () => {
63+
// verify that minimal instance passes
64+
await expect(minimalInstance).to.matchJsonSchema(`${schema}#${subSchemaPath}`);
65+
// verify that adding a very unlikely property fails
66+
const extendedInstance = { ...minimalInstance, not_allowed: true };
67+
await expect(extendedInstance).to.not.matchJsonSchema(`${schema}#${subSchemaPath}`);
68+
});
69+
}
70+
});
5671
});

0 commit comments

Comments
 (0)