Skip to content

Commit e1cee9d

Browse files
committed
chore: change default allowAdditionalProperties and minify tests
1 parent 66dd0eb commit e1cee9d

File tree

7 files changed

+25
-164
lines changed

7 files changed

+25
-164
lines changed

packages/core/src/rules/common/__tests__/no-invalid-parameter-examples.test.ts

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -52,67 +52,6 @@ describe('no-invalid-parameter-examples', () => {
5252
`);
5353
});
5454

55-
it('should report on invalid example with additional properties when allowAdditionalProperties is false', async () => {
56-
const document = parseYamlToDocument(
57-
outdent`
58-
openapi: 3.0.0
59-
paths:
60-
/users:
61-
get:
62-
parameters:
63-
- name: filter
64-
in: query
65-
schema:
66-
type: object
67-
properties:
68-
name:
69-
type: string
70-
age:
71-
type: number
72-
example:
73-
name: "John"
74-
age: 30
75-
extraProperty: "not allowed"
76-
`,
77-
'foobar.yaml'
78-
);
79-
80-
const results = await lintDocument({
81-
externalRefResolver: new BaseResolver(),
82-
document,
83-
config: await createConfig({
84-
rules: {
85-
'no-invalid-parameter-examples': {
86-
severity: 'error',
87-
allowAdditionalProperties: false,
88-
},
89-
},
90-
}),
91-
});
92-
93-
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
94-
[
95-
{
96-
"from": {
97-
"pointer": "#/paths/~1users/get/parameters/0",
98-
"source": "foobar.yaml",
99-
},
100-
"location": [
101-
{
102-
"pointer": "#/paths/~1users/get/parameters/0/example/extraProperty",
103-
"reportOnKey": true,
104-
"source": "foobar.yaml",
105-
},
106-
],
107-
"message": "Example value must conform to the schema: must NOT have unevaluated properties \`extraProperty\`.",
108-
"ruleId": "no-invalid-parameter-examples",
109-
"severity": "error",
110-
"suggest": [],
111-
},
112-
]
113-
`);
114-
});
115-
11655
it('should report on invalid example in examples object when allowAdditionalProperties is false', async () => {
11756
const document = parseYamlToDocument(
11857
outdent`

packages/core/src/rules/common/__tests__/no-invalid-schema-examples.test.ts

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -85,63 +85,6 @@ describe('no-invalid-schema-examples', () => {
8585
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
8686
});
8787

88-
it('should report on invalid example with additional properties', async () => {
89-
const document = parseYamlToDocument(
90-
outdent`
91-
openapi: 3.0.0
92-
components:
93-
schemas:
94-
Car:
95-
type: object
96-
properties:
97-
color:
98-
type: string
99-
model:
100-
type: string
101-
example:
102-
color: "red"
103-
model: "sedan"
104-
extraProperty: "not allowed"
105-
`,
106-
'foobar.yaml'
107-
);
108-
109-
const results = await lintDocument({
110-
externalRefResolver: new BaseResolver(),
111-
document,
112-
config: await createConfig({
113-
rules: {
114-
'no-invalid-schema-examples': {
115-
severity: 'error',
116-
allowAdditionalProperties: false,
117-
},
118-
},
119-
}),
120-
});
121-
122-
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
123-
[
124-
{
125-
"from": {
126-
"pointer": "#/components/schemas/Car",
127-
"source": "foobar.yaml",
128-
},
129-
"location": [
130-
{
131-
"pointer": "#/components/schemas/Car/example/extraProperty",
132-
"reportOnKey": true,
133-
"source": "foobar.yaml",
134-
},
135-
],
136-
"message": "Example value must conform to the schema: must NOT have unevaluated properties \`extraProperty\`.",
137-
"ruleId": "no-invalid-schema-examples",
138-
"severity": "error",
139-
"suggest": [],
140-
},
141-
]
142-
`);
143-
});
144-
14588
it('should report on invalid examples with additional properties', async () => {
14689
const document = parseYamlToDocument(
14790
outdent`

packages/core/src/rules/common/no-invalid-parameter-examples.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export const NoInvalidParameterExamples: any = (opts: any) => {
1010
leave(parameter: Oas3Parameter, ctx: UserContext) {
1111
const allowAdditionalProperties = isDefined(opts.allowAdditionalProperties)
1212
? opts.allowAdditionalProperties
13-
: true;
13+
: false;
14+
1415
if (isDefined(parameter.example)) {
1516
validateExample(
1617
parameter.example,

packages/core/src/rules/common/no-invalid-schema-examples.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const NoInvalidSchemaExamples: Oas3Rule | Oas2Rule = (opts: any) => {
1212
const examples = (schema as Oas3_1Schema).examples;
1313
const allowAdditionalProperties = isDefined(opts.allowAdditionalProperties)
1414
? opts.allowAdditionalProperties
15-
: true;
15+
: false;
1616

1717
if (examples) {
1818
for (const example of examples) {

packages/core/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ describe('no-invalid-media-type-examples', () => {
735735
`);
736736
});
737737

738-
it('should allow additional properties by default for example', async () => {
738+
it('should report additional properties by default for example', async () => {
739739
const document = parseYamlToDocument(
740740
outdent`
741741
openapi: 3.0.0
@@ -771,47 +771,26 @@ describe('no-invalid-media-type-examples', () => {
771771
}),
772772
});
773773

774-
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
775-
});
776-
777-
it('should allow additional properties by default for examples', async () => {
778-
const document = parseYamlToDocument(
779-
outdent`
780-
openapi: 3.0.0
781-
paths:
782-
/pet:
783-
get:
784-
responses:
785-
200:
786-
content:
787-
application/json:
788-
examples:
789-
example1:
790-
value:
791-
color: "red"
792-
model: "sedan"
793-
extraProperty: "allowed by default"
794-
schema:
795-
type: object
796-
properties:
797-
color:
798-
type: string
799-
model:
800-
type: string
801-
`,
802-
'foobar.yaml'
803-
);
804-
805-
const results = await lintDocument({
806-
externalRefResolver: new BaseResolver(),
807-
document,
808-
config: await createConfig({
809-
rules: {
810-
'no-invalid-media-type-examples': 'error',
774+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
775+
[
776+
{
777+
"from": {
778+
"pointer": "#/paths/~1pet/get/responses/200/content/application~1json",
779+
"source": "foobar.yaml",
780+
},
781+
"location": [
782+
{
783+
"pointer": "#/paths/~1pet/get/responses/200/content/application~1json/example/extraProperty",
784+
"reportOnKey": true,
785+
"source": "foobar.yaml",
786+
},
787+
],
788+
"message": "Example value must conform to the schema: must NOT have unevaluated properties \`extraProperty\`.",
789+
"ruleId": "no-invalid-media-type-examples",
790+
"severity": "error",
791+
"suggest": [],
811792
},
812-
}),
813-
});
814-
815-
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
793+
]
794+
`);
816795
});
817796
});

packages/core/src/rules/oas3/no-invalid-media-type-examples.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const ValidContentExamples: Oas3Rule = (opts) => {
1717
const { location, resolve } = ctx;
1818
const allowAdditionalProperties = isDefined(opts.allowAdditionalProperties)
1919
? opts.allowAdditionalProperties
20-
: true;
20+
: false;
2121

2222
if (isDefined(mediaType.example)) {
2323
resolveAndValidateExample(mediaType.example, location.child('example'));

tests/e2e/lint/no-invalid-examples-allow-additional-properties-in-config/redocly.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ rules:
88
allowAdditionalProperties: true
99
no-invalid-parameter-examples:
1010
severity: error
11-
allowAdditionalProperties: false
1211
no-invalid-media-type-examples:
1312
severity: error
1413
allowAdditionalProperties: false

0 commit comments

Comments
 (0)