mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-06 12:47:48 +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
|
openapi: 3.1.0
|
||||||
servers:
|
servers:
|
||||||
- url: http://localhost
|
- url: http://redocly-example.com
|
||||||
info:
|
info:
|
||||||
title: Sample API
|
title: Sample API
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
openapi: 3.1.0
|
openapi: 3.1.0
|
||||||
servers:
|
servers:
|
||||||
- url: https://api.example.com/v1
|
- url: https://api.redocly-example.com/v1
|
||||||
security: []
|
security: []
|
||||||
info:
|
info:
|
||||||
title: Title
|
title: Title
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
openapi: 3.1.0
|
openapi: 3.1.0
|
||||||
servers:
|
servers:
|
||||||
- url: https://api.example.com/v1
|
- url: https://api.redocly-example.com/v1
|
||||||
security: []
|
security: []
|
||||||
|
|
||||||
info:
|
info:
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ info:
|
|||||||
description: Description
|
description: Description
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
servers:
|
servers:
|
||||||
- url: https://api.example.com/v1
|
- url: https://api.redocly-example.com/v1
|
||||||
security: []
|
security: []
|
||||||
paths:
|
paths:
|
||||||
/my_post:
|
/my_post:
|
||||||
|
|||||||
@@ -397,7 +397,7 @@ describe('E2E', () => {
|
|||||||
(<any>expect(result)).toMatchSpecificSnapshot(join(testPath, 'snapshot.js'));
|
(<any>expect(result)).toMatchSpecificSnapshot(join(testPath, 'snapshot.js'));
|
||||||
|
|
||||||
expect(fs.existsSync(join(testPath, 'nested/redoc-static.html'))).toEqual(true);
|
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.
|
description: This is an example API.
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
servers:
|
servers:
|
||||||
- url: https://example.com/api
|
- url: https://redocly-example.com/api
|
||||||
paths:
|
paths:
|
||||||
/users/{userId}:
|
/users/{userId}:
|
||||||
parameters:
|
parameters:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ info:
|
|||||||
description: This is an example API.
|
description: This is an example API.
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
servers:
|
servers:
|
||||||
- url: https://example.com/api
|
- url: https://redocly-example.com/api
|
||||||
paths:
|
paths:
|
||||||
/users/{userId}/orders/{orderId}:
|
/users/{userId}/orders/{orderId}:
|
||||||
parameters:
|
parameters:
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ info:
|
|||||||
description: This is an example API.
|
description: This is an example API.
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
servers:
|
servers:
|
||||||
- url: https://example.com/api
|
- url: https://redocly-example.com/api
|
||||||
tags:
|
tags:
|
||||||
- name: bar_other
|
- name: bar_other
|
||||||
x-displayName: other
|
x-displayName: other
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ info:
|
|||||||
description: This is an example API.
|
description: This is an example API.
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
servers:
|
servers:
|
||||||
- url: https://example.com/api
|
- url: https://redocly-example.com/api
|
||||||
paths:
|
paths:
|
||||||
/users/{userId}:
|
/users/{userId}:
|
||||||
parameters:
|
parameters:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ info:
|
|||||||
description: This is an example API.
|
description: This is an example API.
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
servers:
|
servers:
|
||||||
- url: https://example.com/api
|
- url: https://redocly-example.com/api
|
||||||
paths:
|
paths:
|
||||||
/users/{userId}/orders/{orderId}:
|
/users/{userId}/orders/{orderId}:
|
||||||
parameters:
|
parameters:
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ info:
|
|||||||
description: This is an example API.
|
description: This is an example API.
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
servers:
|
servers:
|
||||||
- url: https://example.com/api
|
- url: https://redocly-example.com/api
|
||||||
tags:
|
tags:
|
||||||
- name: foo_other
|
- name: foo_other
|
||||||
x-displayName: other
|
x-displayName: other
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ info:
|
|||||||
description: This is an example API.
|
description: This is an example API.
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
servers:
|
servers:
|
||||||
- url: https://example.com/api
|
- url: https://redocly-example.com/api
|
||||||
paths:
|
paths:
|
||||||
/users/{userId}/orders/{orderId}:
|
/users/{userId}/orders/{orderId}:
|
||||||
parameters:
|
parameters:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ info:
|
|||||||
description: This is an example API.
|
description: This is an example API.
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
servers:
|
servers:
|
||||||
- url: https://example.com/api
|
- url: https://redocly-example.com/api
|
||||||
paths:
|
paths:
|
||||||
/users/{userId}/products/{productId}:
|
/users/{userId}/products/{productId}:
|
||||||
parameters:
|
parameters:
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ info:
|
|||||||
description: This is an example API.
|
description: This is an example API.
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
servers:
|
servers:
|
||||||
- url: https://example.com/api
|
- url: https://redocly-example.com/api
|
||||||
tags:
|
tags:
|
||||||
- name: foo_other
|
- name: foo_other
|
||||||
x-displayName: other
|
x-displayName: other
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
openapi: 3.0.0
|
openapi: 3.0.0
|
||||||
servers:
|
servers:
|
||||||
- url: http://localhost:8080
|
- url: http://redocly-example.com:8080
|
||||||
info:
|
info:
|
||||||
description: example test
|
description: example test
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ info:
|
|||||||
name: Apache 2.0
|
name: Apache 2.0
|
||||||
url: http://www.apache.org/licenses/LICENSE-2.0.html
|
url: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
servers:
|
servers:
|
||||||
- url: http://localhost:8081
|
- url: http://redocly-example.com:8081
|
||||||
- url: http://localhost:8080
|
- url: http://redocly-example.com:8080
|
||||||
tags:
|
tags:
|
||||||
- name: user
|
- name: user
|
||||||
x-displayName: user
|
x-displayName: user
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
openapi: 3.0.0
|
openapi: 3.0.0
|
||||||
servers:
|
servers:
|
||||||
- url: http://localhost:8081
|
- url: http://redocly-example.com:8081
|
||||||
info:
|
info:
|
||||||
description: test
|
description: test
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ tags:
|
|||||||
- name: sometag
|
- name: sometag
|
||||||
description: sometag
|
description: sometag
|
||||||
servers:
|
servers:
|
||||||
- url: https://example.com
|
- url: https://redocly-example.com
|
||||||
security: []
|
security: []
|
||||||
paths:
|
paths:
|
||||||
/someGet:
|
/someGet:
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ paths:
|
|||||||
description: summary example
|
description: summary example
|
||||||
externalDocs:
|
externalDocs:
|
||||||
description: 'Find more info here'
|
description: 'Find more info here'
|
||||||
url: 'https://example.com'
|
url: 'https://redocly-example.com'
|
||||||
requestBody:
|
requestBody:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ rule/anyType failed because the any description didn't meet the assertions: Shou
|
|||||||
28 | externalDocs:
|
28 | externalDocs:
|
||||||
29 | description: 'Find more info here'
|
29 | description: 'Find more info here'
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
30 | url: 'https://example.com'
|
30 | url: 'https://redocly-example.com'
|
||||||
31 | requestBody:
|
31 | requestBody:
|
||||||
|
|
||||||
Error was generated by the rule/anyType rule.
|
Error was generated by the rule/anyType rule.
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ paths:
|
|||||||
summary: My resource
|
summary: My resource
|
||||||
externalDocs:
|
externalDocs:
|
||||||
description: 'Find more info here'
|
description: 'Find more info here'
|
||||||
url: 'https://example.com'
|
url: 'https://redocly-example.com'
|
||||||
requestBody:
|
requestBody:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ info:
|
|||||||
title: Example OpenAPI 3 definition. Valid.
|
title: Example OpenAPI 3 definition. Valid.
|
||||||
version: 1.0
|
version: 1.0
|
||||||
servers:
|
servers:
|
||||||
- url: https://example.com/user/{id}/place/{placeId}
|
- url: https://redocly-example.com/user/{id}/place/{placeId}
|
||||||
variables:
|
variables:
|
||||||
id:
|
id:
|
||||||
enum: []
|
enum: []
|
||||||
placeId:
|
placeId:
|
||||||
enum: [b]
|
enum: [b]
|
||||||
default: a
|
default: a
|
||||||
- url: https://example.com/{var}
|
- url: https://redocly-example.com/{var}
|
||||||
variables: {}
|
variables: {}
|
||||||
|
|
||||||
paths:
|
paths:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ Server variable with \`enum\` must be a non-empty array.
|
|||||||
4 | version: 1.0
|
4 | version: 1.0
|
||||||
5 | servers:
|
5 | servers:
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
6 | - url: https://example.com/user/{id}/place/{placeId}
|
6 | - url: https://redocly-example.com/user/{id}/place/{placeId}
|
||||||
7 | variables:
|
7 | variables:
|
||||||
|
|
||||||
Error was generated by the no-server-variables-empty-enum rule.
|
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
|
4 | version: 1.0
|
||||||
5 | servers:
|
5 | servers:
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
6 | - url: https://example.com/user/{id}/place/{placeId}
|
6 | - url: https://redocly-example.com/user/{id}/place/{placeId}
|
||||||
7 | variables:
|
7 | variables:
|
||||||
|
|
||||||
Error was generated by the no-server-variables-empty-enum rule.
|
Error was generated by the no-server-variables-empty-enum rule.
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ info:
|
|||||||
title: Example OpenAPI 3 definition. Valid.
|
title: Example OpenAPI 3 definition. Valid.
|
||||||
version: 1.0
|
version: 1.0
|
||||||
servers:
|
servers:
|
||||||
- url: https://example.com/user/{id}/place/{placeId}
|
- url: https://redocly-example.com/user/{id}/place/{placeId}
|
||||||
variables:
|
variables:
|
||||||
id:
|
id:
|
||||||
enum: [c]
|
enum: [c]
|
||||||
placeId:
|
placeId:
|
||||||
enum: [b, a]
|
enum: [b, a]
|
||||||
default: a
|
default: a
|
||||||
- url: https://example.com/{var}
|
- url: https://redocly-example.com/{var}
|
||||||
variables: {}
|
variables: {}
|
||||||
|
|
||||||
paths:
|
paths:
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ tags:
|
|||||||
- name: Gameplay
|
- name: Gameplay
|
||||||
description: gameplay tag
|
description: gameplay tag
|
||||||
servers:
|
servers:
|
||||||
- url: https://example.com/{var}
|
- url: https://redocly-example.com/{var}
|
||||||
variables:
|
variables:
|
||||||
var:
|
var:
|
||||||
enum:
|
enum:
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ tags:
|
|||||||
- name: Gameplay
|
- name: Gameplay
|
||||||
description: gameplay tag
|
description: gameplay tag
|
||||||
servers:
|
servers:
|
||||||
- url: https://example.com/{var}
|
- url: https://redocly-example.com/{var}
|
||||||
variables:
|
variables:
|
||||||
var:
|
var:
|
||||||
enum:
|
enum:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
openapi: 3.0.1
|
openapi: 3.0.1
|
||||||
servers:
|
servers:
|
||||||
- url: http://localhost:8080
|
- url: http://redocly-example.com:8080
|
||||||
info:
|
info:
|
||||||
title: Test
|
title: Test
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ info:
|
|||||||
title: Test
|
title: Test
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
servers:
|
servers:
|
||||||
- url: http://localhost:8080
|
- url: http://redocly-example.com:8080
|
||||||
security: []
|
security: []
|
||||||
paths:
|
paths:
|
||||||
/items:
|
/items:
|
||||||
@@ -57,7 +57,7 @@ components:
|
|||||||
Info object should contain \`license\` field.
|
Info object should contain \`license\` field.
|
||||||
|
|
||||||
2 | servers:
|
2 | servers:
|
||||||
3 | - url: http://localhost:8080
|
3 | - url: http://redocly-example.com:8080
|
||||||
4 | info:
|
4 | info:
|
||||||
| ^^^^
|
| ^^^^
|
||||||
5 | title: Test
|
5 | title: Test
|
||||||
@@ -82,7 +82,7 @@ validating openapi.yaml...
|
|||||||
Info object should contain \`license\` field.
|
Info object should contain \`license\` field.
|
||||||
|
|
||||||
2 | servers:
|
2 | servers:
|
||||||
3 | - url: http://localhost:8080
|
3 | - url: http://redocly-example.com:8080
|
||||||
4 | info:
|
4 | info:
|
||||||
| ^^^^
|
| ^^^^
|
||||||
5 | title: Test
|
5 | title: Test
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
openapi: 3.1.0
|
openapi: 3.1.0
|
||||||
servers:
|
servers:
|
||||||
- url: http://localhost
|
- url: http://redocly-example.com
|
||||||
info:
|
info:
|
||||||
title: Sample API
|
title: Sample API
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ describe('lint', () => {
|
|||||||
license: Fail
|
license: Fail
|
||||||
|
|
||||||
servers:
|
servers:
|
||||||
- url: http://example.com
|
- url: http://redocly-example.com
|
||||||
paths: {}
|
paths: {}
|
||||||
`,
|
`,
|
||||||
config: await loadConfig(),
|
config: await loadConfig(),
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ describe('Oas3 oas3-no-server-example.com', () => {
|
|||||||
"source": "foobar.yaml",
|
"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",
|
"ruleId": "no-server-example.com",
|
||||||
"severity": "error",
|
"severity": "error",
|
||||||
"suggest": Array [],
|
"suggest": Array [],
|
||||||
@@ -57,4 +57,39 @@ describe('Oas3 oas3-no-server-example.com', () => {
|
|||||||
|
|
||||||
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
|
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
|
- 25.3
|
||||||
- test
|
- test
|
||||||
servers:
|
servers:
|
||||||
- url: 'http://example.com'
|
- url: 'http://redocly-example.com'
|
||||||
variables:
|
variables:
|
||||||
a:
|
a:
|
||||||
default: test
|
default: test
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ import { Oas3Rule } from '../../visitors';
|
|||||||
export const NoServerExample: Oas3Rule = () => {
|
export const NoServerExample: Oas3Rule = () => {
|
||||||
return {
|
return {
|
||||||
Server(server, { report, location }) {
|
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({
|
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']),
|
location: location.child(['url']),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user