Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: component-name-unique rule should report location #1759

Merged
merged 12 commits into from
Oct 28, 2024
5 changes: 5 additions & 0 deletions .changeset/real-chicken-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@redocly/openapi-core": minor
---

Fixed `component-name-unique` problems to include correct location.
209 changes: 176 additions & 33 deletions packages/core/src/rules/oas3/__tests__/component-name-unique.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,31 @@ describe('Oas3 component-name-unique', () => {
{
"location": [
{
"pointer": "#/",
"pointer": "#/components/schemas/SomeSchema",
"reportOnKey": false,
"source": "/foobar.yaml",
},
],
"message": "Component 'schemas/SomeSchema' is not unique. It is defined at:
- /foobar.yaml#/components/schemas/SomeSchema
"message": "Component 'schemas/SomeSchema' is not unique. It is also defined at:
- /test.yaml#/components/schemas/SomeSchema",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
{
"location": [
{
"pointer": "#/components/schemas/SomeSchema",
"reportOnKey": false,
"source": "/test.yaml",
},
],
"message": "Component 'schemas/SomeSchema' is not unique. It is also defined at:
- /foobar.yaml#/components/schemas/SomeSchema",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
]
`);
});
Expand Down Expand Up @@ -99,18 +112,31 @@ describe('Oas3 component-name-unique', () => {
{
"location": [
{
"pointer": "#/",
"pointer": "#/components/schemas/SomeSchema",
"reportOnKey": false,
"source": "/foobar.yaml",
},
],
"message": "Component 'schemas/SomeSchema' is not unique. It is defined at:
- /foobar.yaml#/components/schemas/SomeSchema
"message": "Component 'schemas/SomeSchema' is not unique. It is also defined at:
- /SomeSchema.yaml",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
{
"location": [
{
"pointer": "#/",
"reportOnKey": false,
"source": "/SomeSchema.yaml",
},
],
"message": "Component 'schemas/SomeSchema' is not unique. It is also defined at:
- /foobar.yaml#/components/schemas/SomeSchema",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
]
`);
});
Expand Down Expand Up @@ -202,18 +228,31 @@ describe('Oas3 component-name-unique', () => {
{
"location": [
{
"pointer": "#/",
"pointer": "#/components/parameters/ParameterOne",
"reportOnKey": false,
"source": "/foobar.yaml",
},
],
"message": "Component 'parameters/ParameterOne' is not unique. It is defined at:
- /foobar.yaml#/components/parameters/ParameterOne
"message": "Component 'parameters/ParameterOne' is not unique. It is also defined at:
- /test.yaml#/components/parameters/ParameterOne",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
{
"location": [
{
"pointer": "#/components/parameters/ParameterOne",
"reportOnKey": false,
"source": "/test.yaml",
},
],
"message": "Component 'parameters/ParameterOne' is not unique. It is also defined at:
- /foobar.yaml#/components/parameters/ParameterOne",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
]
`);
});
Expand Down Expand Up @@ -261,18 +300,31 @@ describe('Oas3 component-name-unique', () => {
{
"location": [
{
"pointer": "#/",
"pointer": "#/components/parameters/ParameterOne",
"reportOnKey": false,
"source": "/foobar.yaml",
},
],
"message": "Component 'parameters/ParameterOne' is not unique. It is defined at:
- /foobar.yaml#/components/parameters/ParameterOne
"message": "Component 'parameters/ParameterOne' is not unique. It is also defined at:
- /ParameterOne.yaml",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
{
"location": [
{
"pointer": "#/",
"reportOnKey": false,
"source": "/ParameterOne.yaml",
},
],
"message": "Component 'parameters/ParameterOne' is not unique. It is also defined at:
- /foobar.yaml#/components/parameters/ParameterOne",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
]
`);
});
Expand Down Expand Up @@ -378,18 +430,31 @@ describe('Oas3 component-name-unique', () => {
{
"location": [
{
"pointer": "#/",
"pointer": "#/components/responses/SuccessResponse",
"reportOnKey": false,
"source": "/foobar.yaml",
},
],
"message": "Component 'responses/SuccessResponse' is not unique. It is defined at:
- /foobar.yaml#/components/responses/SuccessResponse
"message": "Component 'responses/SuccessResponse' is not unique. It is also defined at:
- /test.yaml#/components/responses/SuccessResponse",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
{
"location": [
{
"pointer": "#/components/responses/SuccessResponse",
"reportOnKey": false,
"source": "/test.yaml",
},
],
"message": "Component 'responses/SuccessResponse' is not unique. It is also defined at:
- /foobar.yaml#/components/responses/SuccessResponse",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
]
`);
});
Expand Down Expand Up @@ -444,18 +509,31 @@ describe('Oas3 component-name-unique', () => {
{
"location": [
{
"pointer": "#/",
"pointer": "#/components/responses/SuccessResponse",
"reportOnKey": false,
"source": "/foobar.yaml",
},
],
"message": "Component 'responses/SuccessResponse' is not unique. It is defined at:
- /foobar.yaml#/components/responses/SuccessResponse
"message": "Component 'responses/SuccessResponse' is not unique. It is also defined at:
- /SuccessResponse.yaml",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
{
"location": [
{
"pointer": "#/",
"reportOnKey": false,
"source": "/SuccessResponse.yaml",
},
],
"message": "Component 'responses/SuccessResponse' is not unique. It is also defined at:
- /foobar.yaml#/components/responses/SuccessResponse",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
]
`);
});
Expand Down Expand Up @@ -565,18 +643,31 @@ describe('Oas3 component-name-unique', () => {
{
"location": [
{
"pointer": "#/",
"pointer": "#/components/requestBodies/MyRequestBody",
"reportOnKey": false,
"source": "/foobar.yaml",
},
],
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is defined at:
- /foobar.yaml#/components/requestBodies/MyRequestBody
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
- /test.yaml#/components/requestBodies/MyRequestBody",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
{
"location": [
{
"pointer": "#/components/requestBodies/MyRequestBody",
"reportOnKey": false,
"source": "/test.yaml",
},
],
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
- /foobar.yaml#/components/requestBodies/MyRequestBody",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
]
`);
});
Expand Down Expand Up @@ -632,18 +723,31 @@ describe('Oas3 component-name-unique', () => {
{
"location": [
{
"pointer": "#/",
"pointer": "#/components/requestBodies/MyRequestBody",
"reportOnKey": false,
"source": "/foobar.yaml",
},
],
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is defined at:
- /foobar.yaml#/components/requestBodies/MyRequestBody
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
- /MyRequestBody.yaml",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
{
"location": [
{
"pointer": "#/",
"reportOnKey": false,
"source": "/MyRequestBody.yaml",
},
],
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
- /foobar.yaml#/components/requestBodies/MyRequestBody",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
]
`);
});
Expand Down Expand Up @@ -761,13 +865,12 @@ describe('Oas3 component-name-unique', () => {
{
"location": [
{
"pointer": "#/",
"pointer": "#/components/requestBodies/MyRequestBody",
"reportOnKey": false,
"source": "/foobar.yaml",
},
],
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is defined at:
- /foobar.yaml#/components/requestBodies/MyRequestBody
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
- /test.yaml#/components/requestBodies/MyRequestBody",
"ruleId": "component-name-unique",
"severity": "error",
Expand All @@ -776,18 +879,45 @@ describe('Oas3 component-name-unique', () => {
{
"location": [
{
"pointer": "#/",
"pointer": "#/components/requestBodies/MyRequestBody",
"reportOnKey": false,
"source": "/test.yaml",
},
],
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
- /foobar.yaml#/components/requestBodies/MyRequestBody",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
{
"location": [
{
"pointer": "#/components/schemas/SomeSchema",
"reportOnKey": false,
"source": "/foobar.yaml",
},
],
"message": "Component 'schemas/SomeSchema' is not unique. It is defined at:
- /foobar.yaml#/components/schemas/SomeSchema
"message": "Component 'schemas/SomeSchema' is not unique. It is also defined at:
- /test.yaml#/components/schemas/SomeSchema",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
{
"location": [
{
"pointer": "#/components/schemas/SomeSchema",
"reportOnKey": false,
"source": "/test.yaml",
},
],
"message": "Component 'schemas/SomeSchema' is not unique. It is also defined at:
- /foobar.yaml#/components/schemas/SomeSchema",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
]
`);
});
Expand All @@ -804,18 +934,31 @@ describe('Oas3 component-name-unique', () => {
{
"location": [
{
"pointer": "#/",
"pointer": "#/components/requestBodies/MyRequestBody",
"reportOnKey": false,
"source": "/foobar.yaml",
},
],
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is defined at:
- /foobar.yaml#/components/requestBodies/MyRequestBody
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
- /test.yaml#/components/requestBodies/MyRequestBody",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
{
"location": [
{
"pointer": "#/components/requestBodies/MyRequestBody",
"reportOnKey": false,
"source": "/test.yaml",
},
],
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
- /foobar.yaml#/components/requestBodies/MyRequestBody",
"ruleId": "component-name-unique",
"severity": "error",
"suggest": [],
},
]
`);
});
Expand Down
Loading
Loading