Skip to content

Commit 45275ed

Browse files
committed
Replace AEP-143 custom function with JSONPath approach
1 parent cb247e7 commit 45275ed

File tree

4 files changed

+19
-51
lines changed

4 files changed

+19
-51
lines changed

aep/0143.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
functionsDir: ../functions
22
functions:
33
- standardized-codes
4-
- standardized-codes-string-type
54

65
rules:
76
aep-143-standardized-codes:
@@ -14,10 +13,19 @@ rules:
1413
function: standardized-codes
1514

1615
aep-143-standardized-codes-string-type:
17-
description: Standardized code fields must be of type string.
18-
message: '{{error}}'
16+
description: Standardized code fields must be of type "string".
17+
message: 'Standardized code field "{{property}}" must be type "string"'
1918
severity: error
2019
formats: ['oas2', 'oas3']
21-
given: $.components.schemas[*]
20+
given:
21+
- $.components.schemas[*].properties[?(@property in ['content_type', 'currency_code', 'language_code'])]
22+
- $.components.schemas[*].properties[?(@property in ['region_code', 'time_zone', 'utc_offset'])]
2223
then:
23-
function: standardized-codes-string-type
24+
function: schema
25+
functionOptions:
26+
schema:
27+
type: object
28+
required: ['type']
29+
properties:
30+
type:
31+
const: string

functions/standardized-codes-string-type.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

spectral.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ functions:
2121
- parameter-names-unique
2222
- operations-endpoint
2323
- standardized-codes
24-
- standardized-codes-string-type
2524
rules:
2625
openapi-tags: off
2726
operation-tags: off

test/0143/standardized-codes-string-type.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('aep-143-standardized-codes-string-type', () => {
2929
expect(results.length).toBe(1);
3030
expect(results).toContainMatch({
3131
path: ['components', 'schemas', 'Book', 'properties', 'language_code', 'type'],
32-
message: expect.stringContaining('should be of type "string"'),
32+
message: expect.stringContaining('must be type "string"'),
3333
});
3434
});
3535
});
@@ -54,7 +54,7 @@ describe('aep-143-standardized-codes-string-type', () => {
5454
expect(results.length).toBe(1);
5555
expect(results).toContainMatch({
5656
path: ['components', 'schemas', 'Address', 'properties', 'region_code', 'type'],
57-
message: expect.stringContaining('should be of type "string"'),
57+
message: expect.stringContaining('must be type "string"'),
5858
});
5959
});
6060
});
@@ -79,7 +79,7 @@ describe('aep-143-standardized-codes-string-type', () => {
7979
expect(results.length).toBe(1);
8080
expect(results).toContainMatch({
8181
path: ['components', 'schemas', 'Price', 'properties', 'currency_code', 'type'],
82-
message: expect.stringContaining('should be of type "string"'),
82+
message: expect.stringContaining('must be type "string"'),
8383
});
8484
});
8585
});
@@ -104,7 +104,7 @@ describe('aep-143-standardized-codes-string-type', () => {
104104
expect(results.length).toBe(1);
105105
expect(results).toContainMatch({
106106
path: ['components', 'schemas', 'File', 'properties', 'content_type', 'type'],
107-
message: expect.stringContaining('should be of type "string"'),
107+
message: expect.stringContaining('must be type "string"'),
108108
});
109109
});
110110
});
@@ -129,7 +129,7 @@ describe('aep-143-standardized-codes-string-type', () => {
129129
expect(results.length).toBe(1);
130130
expect(results).toContainMatch({
131131
path: ['components', 'schemas', 'Event', 'properties', 'time_zone', 'type'],
132-
message: expect.stringContaining('should be of type "string"'),
132+
message: expect.stringContaining('must be type "string"'),
133133
});
134134
});
135135
});
@@ -154,7 +154,7 @@ describe('aep-143-standardized-codes-string-type', () => {
154154
expect(results.length).toBe(1);
155155
expect(results).toContainMatch({
156156
path: ['components', 'schemas', 'TimeInfo', 'properties', 'utc_offset', 'type'],
157-
message: expect.stringContaining('should be of type "string"'),
157+
message: expect.stringContaining('must be type "string"'),
158158
});
159159
});
160160
});

0 commit comments

Comments
 (0)