-
-
Notifications
You must be signed in to change notification settings - Fork 240
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
Returning multiple rule violations on same path #1299
Labels
t/bug
Something isn't working
Comments
Another Example: .spectral.yml extends: spectral:oas
functions:
- deprecatedHeader
rules:
deprecated-header:
description: If request, parameters or response contains deprecated elements, a Warning-Header should be sent with the response.
message: "Missing Warning header on {{error}}."
recommended: true
severity: 1
given: $.paths
then:
function: deprecatedHeader functions/deprecatedHeader.js module.exports = (paths, opts) => {
return [
{
message: "paths./all-deprecated-only-one-msg.put.200",
path: ["paths","/all-deprecated-only-one-msg","put","200"]
},{
message: "paths./all-deprecated-only-one-msg.put.201",
path: ["paths","/all-deprecated-only-one-msg","put","201"]
}];
} openapi.yml openapi: 3.0.2
info:
title: Raumbuchungs-API
version: ${project.version}
description: API für das Buchen und Verwalten von Besprechungsräumen.
contact:
name: API-Team
email: [email protected]
servers:
- url: https://api.gateway.de
tags:
- name: MyTag
paths:
/all-deprecated-only-one-msg:
put:
description: "Deprecated: Operation an der Request, Params, und Response deprecated sind. Jede Response soll aber nur einmal bemängelt werden."
deprecated: true
operationId: putAllDeprecatedOnlyOneMsg
tags:
- MyTag
parameters:
- name: veraltet
in: query
schema:
type: string
deprecated: true
description: deprecated
- name: inuse
in: query
schema:
type: string
deprecated: true
description: deprecated
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/DeprecatedExample'
responses:
"200":
description: Erfolgreicher Zugriff.
content:
application/json:
schema:
$ref: '#/components/schemas/DeprecatedExample'
"201":
description: Erfolgreicher Zugriff.
content:
application/json:
schema:
$ref: '#/components/schemas/DeprecatedExample'
components:
schemas:
DeprecatedExample:
type: object
properties:
data:
type: array
items:
type: object
properties:
roomId:
type: string
capacity:
type: integer
deprecated: true
description: Deprecated, da künftig Attribute Fassungsvermögen verwenden. I would expect to receive two warnings, but spectral returns only one and for some reason I don't understand the last path segment was removed OpenAPI 3.x detected
[
{
"code": "deprecated-header",
"path": [
"paths",
"/all-deprecated-only-one-msg",
"put"
],
"message": "Missing Warning header on paths./all-deprecated-only-one-msg.put.200.",
"severity": 1,
"range": {
"start": {
"line": 18,
"character": 8
},
"end": {
"line": 54,
"character": 62
}
},
"source": "...openapi.yml"
}
] |
still exists in 5.5.0 |
My mistake: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
We have a custom rule checking the naming convention in paths. The function checks if a path segment is
We implemented a custom function and not just a complex regex to provide the developer with a exact error message. In Spectral 4.5.0 we could return the following messages for the path
/total_invalid/Path/{WithInvalid}/{pathPARAMS}
:total_invalid
must be in lower-kebab-case.Path
must be in lower-kebab-case.{WithInvalid}
must be in lowerCamelCase.{pathPARAMS}
must be in lowerCamelCase.With 5.4.0 we get only the first message because of the elemination of violations of the same type on the same element.
I read Issue #1030 and #920 and also read https://github.com/stoplightio/spectral/blob/develop/docs/guides/5-custom-functions.md#returning-multiple-results, but could not getting it work.
The problem I have, is that rule and path (
/total_invalid/Path/{WithInvalid}/{pathPARAMS}
) is always the same, only the message changes. I tried to use only partial parts likepaths./total_invalid/
,paths./total_invalid/Path/
,paths./total_invalid/Path/{WithInvalid}
andpaths./total_invalid/Path/{WithInvalid}/{pathPARAMS}
. When I do this, I get the first and the forth expected message.I also tried random paths, but in this case I get only the first message. Looks like the path i proivde in the result of the function must exists in the oas document? Could not find anything about that in the documentation.
To Reproduce
.spectral.yml
funtions/pathNaming.js
openapi.yml
The text was updated successfully, but these errors were encountered: