mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-06 04:21:09 +00:00
fix: improve detection accuracy on no-server-example.com rule (#1270)
This commit is contained in:
6
.changeset/plenty-ears-allow.md
Normal file
6
.changeset/plenty-ears-allow.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@redocly/openapi-core': patch
|
||||
'@redocly/cli': patch
|
||||
---
|
||||
|
||||
Fixed pattern for no-server-example.com rule to improve detection accuracy.
|
||||
@@ -1,6 +1,6 @@
|
||||
openapi: 3.1.0
|
||||
servers:
|
||||
- url: http://localhost
|
||||
- url: http://redocly-example.com
|
||||
info:
|
||||
title: Sample API
|
||||
version: 1.0.0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
openapi: 3.1.0
|
||||
servers:
|
||||
- url: https://api.example.com/v1
|
||||
- url: https://api.redocly-example.com/v1
|
||||
security: []
|
||||
info:
|
||||
title: Title
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
openapi: 3.1.0
|
||||
servers:
|
||||
- url: https://api.example.com/v1
|
||||
- url: https://api.redocly-example.com/v1
|
||||
security: []
|
||||
|
||||
info:
|
||||
|
||||
@@ -10,7 +10,7 @@ info:
|
||||
description: Description
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: https://api.example.com/v1
|
||||
- url: https://api.redocly-example.com/v1
|
||||
security: []
|
||||
paths:
|
||||
/my_post:
|
||||
|
||||
@@ -397,7 +397,7 @@ describe('E2E', () => {
|
||||
(<any>expect(result)).toMatchSpecificSnapshot(join(testPath, 'snapshot.js'));
|
||||
|
||||
expect(fs.existsSync(join(testPath, 'nested/redoc-static.html'))).toEqual(true);
|
||||
expect(fs.statSync(join(testPath, 'nested/redoc-static.html')).size).toEqual(32996);
|
||||
expect(fs.statSync(join(testPath, 'nested/redoc-static.html')).size).toEqual(33016);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ info:
|
||||
description: This is an example API.
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: https://example.com/api
|
||||
- url: https://redocly-example.com/api
|
||||
paths:
|
||||
/users/{userId}:
|
||||
parameters:
|
||||
|
||||
@@ -4,7 +4,7 @@ info:
|
||||
description: This is an example API.
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: https://example.com/api
|
||||
- url: https://redocly-example.com/api
|
||||
paths:
|
||||
/users/{userId}/orders/{orderId}:
|
||||
parameters:
|
||||
|
||||
@@ -8,7 +8,7 @@ info:
|
||||
description: This is an example API.
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: https://example.com/api
|
||||
- url: https://redocly-example.com/api
|
||||
tags:
|
||||
- name: bar_other
|
||||
x-displayName: other
|
||||
|
||||
@@ -4,7 +4,7 @@ info:
|
||||
description: This is an example API.
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: https://example.com/api
|
||||
- url: https://redocly-example.com/api
|
||||
paths:
|
||||
/users/{userId}:
|
||||
parameters:
|
||||
|
||||
@@ -4,7 +4,7 @@ info:
|
||||
description: This is an example API.
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: https://example.com/api
|
||||
- url: https://redocly-example.com/api
|
||||
paths:
|
||||
/users/{userId}/orders/{orderId}:
|
||||
parameters:
|
||||
|
||||
@@ -8,7 +8,7 @@ info:
|
||||
description: This is an example API.
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: https://example.com/api
|
||||
- url: https://redocly-example.com/api
|
||||
tags:
|
||||
- name: foo_other
|
||||
x-displayName: other
|
||||
|
||||
@@ -4,7 +4,7 @@ info:
|
||||
description: This is an example API.
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: https://example.com/api
|
||||
- url: https://redocly-example.com/api
|
||||
paths:
|
||||
/users/{userId}/orders/{orderId}:
|
||||
parameters:
|
||||
|
||||
@@ -4,7 +4,7 @@ info:
|
||||
description: This is an example API.
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: https://example.com/api
|
||||
- url: https://redocly-example.com/api
|
||||
paths:
|
||||
/users/{userId}/products/{productId}:
|
||||
parameters:
|
||||
|
||||
@@ -8,7 +8,7 @@ info:
|
||||
description: This is an example API.
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: https://example.com/api
|
||||
- url: https://redocly-example.com/api
|
||||
tags:
|
||||
- name: foo_other
|
||||
x-displayName: other
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
openapi: 3.0.0
|
||||
servers:
|
||||
- url: http://localhost:8080
|
||||
- url: http://redocly-example.com:8080
|
||||
info:
|
||||
description: example test
|
||||
version: 1.0.0
|
||||
|
||||
@@ -14,8 +14,8 @@ info:
|
||||
name: Apache 2.0
|
||||
url: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
servers:
|
||||
- url: http://localhost:8081
|
||||
- url: http://localhost:8080
|
||||
- url: http://redocly-example.com:8081
|
||||
- url: http://redocly-example.com:8080
|
||||
tags:
|
||||
- name: user
|
||||
x-displayName: user
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
openapi: 3.0.0
|
||||
servers:
|
||||
- url: http://localhost:8081
|
||||
- url: http://redocly-example.com:8081
|
||||
info:
|
||||
description: test
|
||||
version: 1.0.0
|
||||
|
||||
@@ -8,7 +8,7 @@ tags:
|
||||
- name: sometag
|
||||
description: sometag
|
||||
servers:
|
||||
- url: https://example.com
|
||||
- url: https://redocly-example.com
|
||||
security: []
|
||||
paths:
|
||||
/someGet:
|
||||
|
||||
@@ -27,7 +27,7 @@ paths:
|
||||
description: summary example
|
||||
externalDocs:
|
||||
description: 'Find more info here'
|
||||
url: 'https://example.com'
|
||||
url: 'https://redocly-example.com'
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
|
||||
@@ -188,7 +188,7 @@ rule/anyType failed because the any description didn't meet the assertions: Shou
|
||||
28 | externalDocs:
|
||||
29 | description: 'Find more info here'
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
30 | url: 'https://example.com'
|
||||
30 | url: 'https://redocly-example.com'
|
||||
31 | requestBody:
|
||||
|
||||
Error was generated by the rule/anyType rule.
|
||||
|
||||
@@ -25,7 +25,7 @@ paths:
|
||||
summary: My resource
|
||||
externalDocs:
|
||||
description: 'Find more info here'
|
||||
url: 'https://example.com'
|
||||
url: 'https://redocly-example.com'
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
|
||||
@@ -3,14 +3,14 @@ info:
|
||||
title: Example OpenAPI 3 definition. Valid.
|
||||
version: 1.0
|
||||
servers:
|
||||
- url: https://example.com/user/{id}/place/{placeId}
|
||||
- url: https://redocly-example.com/user/{id}/place/{placeId}
|
||||
variables:
|
||||
id:
|
||||
enum: []
|
||||
placeId:
|
||||
enum: [b]
|
||||
default: a
|
||||
- url: https://example.com/{var}
|
||||
- url: https://redocly-example.com/{var}
|
||||
variables: {}
|
||||
|
||||
paths:
|
||||
|
||||
@@ -11,7 +11,7 @@ Server variable with \`enum\` must be a non-empty array.
|
||||
4 | version: 1.0
|
||||
5 | servers:
|
||||
| ^^^^^^^
|
||||
6 | - url: https://example.com/user/{id}/place/{placeId}
|
||||
6 | - url: https://redocly-example.com/user/{id}/place/{placeId}
|
||||
7 | variables:
|
||||
|
||||
Error was generated by the no-server-variables-empty-enum rule.
|
||||
@@ -25,7 +25,7 @@ Server variable define \`enum\` and \`default\`. \`enum\` must include default v
|
||||
4 | version: 1.0
|
||||
5 | servers:
|
||||
| ^^^^^^^
|
||||
6 | - url: https://example.com/user/{id}/place/{placeId}
|
||||
6 | - url: https://redocly-example.com/user/{id}/place/{placeId}
|
||||
7 | variables:
|
||||
|
||||
Error was generated by the no-server-variables-empty-enum rule.
|
||||
|
||||
@@ -3,14 +3,14 @@ info:
|
||||
title: Example OpenAPI 3 definition. Valid.
|
||||
version: 1.0
|
||||
servers:
|
||||
- url: https://example.com/user/{id}/place/{placeId}
|
||||
- url: https://redocly-example.com/user/{id}/place/{placeId}
|
||||
variables:
|
||||
id:
|
||||
enum: [c]
|
||||
placeId:
|
||||
enum: [b, a]
|
||||
default: a
|
||||
- url: https://example.com/{var}
|
||||
- url: https://redocly-example.com/{var}
|
||||
variables: {}
|
||||
|
||||
paths:
|
||||
|
||||
@@ -13,7 +13,7 @@ tags:
|
||||
- name: Gameplay
|
||||
description: gameplay tag
|
||||
servers:
|
||||
- url: https://example.com/{var}
|
||||
- url: https://redocly-example.com/{var}
|
||||
variables:
|
||||
var:
|
||||
enum:
|
||||
|
||||
@@ -13,7 +13,7 @@ tags:
|
||||
- name: Gameplay
|
||||
description: gameplay tag
|
||||
servers:
|
||||
- url: https://example.com/{var}
|
||||
- url: https://redocly-example.com/{var}
|
||||
variables:
|
||||
var:
|
||||
enum:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
openapi: 3.0.1
|
||||
servers:
|
||||
- url: http://localhost:8080
|
||||
- url: http://redocly-example.com:8080
|
||||
info:
|
||||
title: Test
|
||||
version: 1.0.0
|
||||
|
||||
@@ -6,7 +6,7 @@ info:
|
||||
title: Test
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: http://localhost:8080
|
||||
- url: http://redocly-example.com:8080
|
||||
security: []
|
||||
paths:
|
||||
/items:
|
||||
@@ -57,7 +57,7 @@ components:
|
||||
Info object should contain \`license\` field.
|
||||
|
||||
2 | servers:
|
||||
3 | - url: http://localhost:8080
|
||||
3 | - url: http://redocly-example.com:8080
|
||||
4 | info:
|
||||
| ^^^^
|
||||
5 | title: Test
|
||||
@@ -82,7 +82,7 @@ validating openapi.yaml...
|
||||
Info object should contain \`license\` field.
|
||||
|
||||
2 | servers:
|
||||
3 | - url: http://localhost:8080
|
||||
3 | - url: http://redocly-example.com:8080
|
||||
4 | info:
|
||||
| ^^^^
|
||||
5 | title: Test
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
openapi: 3.1.0
|
||||
servers:
|
||||
- url: http://localhost
|
||||
- url: http://redocly-example.com
|
||||
info:
|
||||
title: Sample API
|
||||
version: 1.0.0
|
||||
|
||||
@@ -20,7 +20,7 @@ describe('lint', () => {
|
||||
license: Fail
|
||||
|
||||
servers:
|
||||
- url: http://example.com
|
||||
- url: http://redocly-example.com
|
||||
paths: {}
|
||||
`,
|
||||
config: await loadConfig(),
|
||||
|
||||
@@ -30,7 +30,7 @@ describe('Oas3 oas3-no-server-example.com', () => {
|
||||
"source": "foobar.yaml",
|
||||
},
|
||||
],
|
||||
"message": "Server \`url\` should not point at example.com.",
|
||||
"message": "Server \`url\` should not point to example.com or localhost.",
|
||||
"ruleId": "no-server-example.com",
|
||||
"severity": "error",
|
||||
"suggest": Array [],
|
||||
@@ -57,4 +57,39 @@ describe('Oas3 oas3-no-server-example.com', () => {
|
||||
|
||||
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
|
||||
});
|
||||
|
||||
it('oas3-no-server-example.com: should report on server object with "foo.example.com" url', async () => {
|
||||
const document = parseYamlToDocument(
|
||||
outdent`
|
||||
openapi: 3.0.0
|
||||
servers:
|
||||
- url: foo.example.com
|
||||
`,
|
||||
'foobar.yaml'
|
||||
);
|
||||
|
||||
const results = await lintDocument({
|
||||
externalRefResolver: new BaseResolver(),
|
||||
document,
|
||||
config: await makeConfig({ 'no-server-example.com': 'error' }),
|
||||
});
|
||||
|
||||
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"location": Array [
|
||||
Object {
|
||||
"pointer": "#/servers/0/url",
|
||||
"reportOnKey": false,
|
||||
"source": "foobar.yaml",
|
||||
},
|
||||
],
|
||||
"message": "Server \`url\` should not point to example.com or localhost.",
|
||||
"ruleId": "no-server-example.com",
|
||||
"severity": "error",
|
||||
"suggest": Array [],
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('Oas3 Structural visitor basic', () => {
|
||||
- 25.3
|
||||
- test
|
||||
servers:
|
||||
- url: 'http://example.com'
|
||||
- url: 'http://redocly-example.com'
|
||||
variables:
|
||||
a:
|
||||
default: test
|
||||
|
||||
@@ -3,9 +3,10 @@ import { Oas3Rule } from '../../visitors';
|
||||
export const NoServerExample: Oas3Rule = () => {
|
||||
return {
|
||||
Server(server, { report, location }) {
|
||||
if (['example.com', 'localhost'].indexOf(server.url) !== -1) {
|
||||
const pattern = /^(.*[\/.])?(example\.com|localhost)([\/:?].*|$)/;
|
||||
if (server.url && pattern.test(server.url)) {
|
||||
report({
|
||||
message: 'Server `url` should not point at example.com.',
|
||||
message: 'Server `url` should not point to example.com or localhost.',
|
||||
location: location.child(['url']),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user