diff --git a/src/static/.local.spectral.yaml b/src/static/.local.spectral.yaml index 0631b1c..732a628 100644 --- a/src/static/.local.spectral.yaml +++ b/src/static/.local.spectral.yaml @@ -30,7 +30,7 @@ rules: then: function: pattern functionOptions: - match: "^([0-9]+.[0-9]+.[0-9]+)$" + match: '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' pathsSummary: description: There needs to be a summary field for every method. message: "There needs to be a summary property for every method." @@ -63,11 +63,12 @@ rules: componentsRequestBodiesExists: description: There should be a requestBodies section within components. message: "Components is missing the '{{property}}' section" - given: "$.components" + given: "$.paths.[*][put, patch, post].requestBody.ref" severity: warn then: - - field: "requestBodies" - function: truthy + function: pattern + functionOptions: + match: "#\/components\/requestBodies\/" camelCaseOperationId: description: All operationIds should be written in camelCase. message: "'{{value}}' needs to be written in camelCase." @@ -78,21 +79,41 @@ rules: function: casing functionOptions: type: camel - camelCaseParameterName: - description: All parameter names should be written in camelCase. + camelCaseComponentNames: + description: All component names should be written in camelCase. + message: "'{{value}}' needs to be written in camelCase." + type: style + given: "$.components..names" + severity: warn + then: + function: casing + functionOptions: + type: camel + camelCaseComponents: + description: All components (schemas, parameters, etc) should be named in camelCase. message: "'{{value}}' needs to be written in camelCase." type: style - given: "$.components.parameters.*.name" + given: "$.components.[callbacks,schemas,parameters,examples,requestBodies,responses][*]~" severity: warn then: function: casing functionOptions: type: camel + sentenceCaseDescriptions: + description: Descriptions should be written in a normal sentence case. + message: "'{{value}}' needs to be written in sentence case." + type: style + given: "$.*.[paths,schemas,securitySchemes]..description" + severity: warn + then: + function: pattern + functionOptions: + match: "(^[A-Z]|(?<=[.?!]))*[A-Z][-_`)(A-Za-z0-9,;'\"\\s]*[.?!]" macroCaseEnum: description: Enums should be in MACRO case. message: "Enum value '{{value}}' should be written in MACRO case" type: style - given: "$.components.*.*.enum.[*]" + given: "$.components..enum.[*]" severity: warn then: function: casing @@ -101,7 +122,7 @@ rules: badRequestError: description: "Responses should define a HTTP 400 Bad Request error" message: "Responses should define a 400 Bad Request Error." - given: "$.paths.[*][*].responses" + given: "$.*.paths..responses" severity: warn then: field: "400" @@ -109,7 +130,7 @@ rules: unauthorizedError: description: "Resources must declare a response for a HTTP 401 Unauthorized error" message: "Responses should define a 401 Unauthorized Error." - given: "$.paths.[*][*].responses" + given: "$.*.paths..responses" severity: warn then: field: "401" @@ -117,7 +138,7 @@ rules: forbiddenError: description: "Resources must declare a response for a HTTP 403 Forbidden error" message: "Responses should define a 403 Forbidden Error." - given: "$.paths.[*][*].responses" + given: "$.*.paths..responses" severity: warn then: field: "403" @@ -125,7 +146,7 @@ rules: notFoundError: description: "Resources must declare a response for a HTTP 404 Not Found error" message: "Responses should define a 404 Not Found Error." - given: "$.paths.[*][get, put, patch, delete].responses" + given: "$.*.paths.[*][get, put, patch, delete].responses" severity: warn then: field: "404" @@ -133,7 +154,7 @@ rules: methodNotAllowedError: description: "Resources must declare a response for a HTTP 405 Method Not Allowed error" message: "Responses should define a 405 Method Not Allowed Error." - given: "$.paths.[*][*].responses" + given: "$.*.paths..responses" severity: warn then: field: "405" @@ -141,23 +162,24 @@ rules: tooManyRequestsError: description: "Resources must declare a response for a HTTP 429 Too Many Requests error" message: "Responses should define a 429 Too Many Requests Error." - given: "$.paths.[*][*].responses" + given: "$.*.paths..responses" severity: warn then: field: "429" function: truthy internalServerError: description: "Resources must declare a response for a HTTP 500 Internal Server error" - message: "Responses should define a 500 Internal Server Error." - given: "$.paths.[*][*].responses" + message: "Responses should define either a 500 or 5XX Internal Server Error. Note that 5XX must be capitalized." + given: "$.*.paths..responses" severity: warn then: - field: "500" - function: truthy + function: pattern + functionOptions: + match: "(^[500|5XX]$" globallyDefinedResponses: description: "Responses should be defined globally and referenced elsewhere." message: "All responses should be defined globally and only referenced everywhere else." - given: "$.paths.[*][*].responses.*[*]" + given: "$.*.paths..responses" resolved: false severity: error then: @@ -166,7 +188,7 @@ rules: globallyDefinedRequestBodies: description: "RequestBodies should be defined globally and referenced elsewhere." message: "Every requestBody should be defined globally and only referenced everywhere else." - given: "$.paths.[*][*].requestBody[*]" + given: "$.paths.[*][post, put, patch].requestBody[*]" resolved: false severity: error then: