fix: add separate node type for patternProperties (#1644)

* fix: add PatternProperties type to target patternProperties separately from properties

* add changeset

* remove redundancy

* commit redocly.yaml and update .gitignore to only target root redocly.yaml

* Update .changeset/sour-pandas-wave.md

Co-authored-by: JLekawa <164185257+JLekawa@users.noreply.github.com>

---------

Co-authored-by: JLekawa <164185257+JLekawa@users.noreply.github.com>
This commit is contained in:
Andrew Tatomyr
2024-07-25 13:46:33 +03:00
committed by GitHub
parent 76669ca2ab
commit 9855904b3e
10 changed files with 79 additions and 7 deletions

View File

@@ -0,0 +1,6 @@
---
"@redocly/openapi-core": patch
"@redocly/cli": patch
---
Fixed an issue where `patternProperties` incorrectly caused linting errors due to a missing `PatternProperties` node.

8
.gitignore vendored
View File

@@ -13,7 +13,7 @@ output/
*.tgz
redoc-static.html
packages/cli/README.md
redocly.yaml
.redocly.yaml
redocly.yml
.redocly.yml
/redocly.yaml
/.redocly.yaml
/redocly.yml
/.redocly.yml

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,12 @@
openapi: 3.1.0
info: {}
paths:
/test:
get:
responses:
default:
description: test
content:
application/json:
schema:
$ref: schema.json

View File

@@ -0,0 +1,10 @@
apis:
main:
root: ./openapi.yaml
rules:
rule/response-in-snake_case:
subject:
type: SchemaProperties
assertions:
casing: snake_case

View File

@@ -0,0 +1,16 @@
{
"type": "object",
"properties": {
"incorrectlyNamedProperty": {
"type": "string"
},
"a_property_in_snake_case": {
"type": "string"
}
},
"patternProperties": {
"^.+$": {
"type": "string"
}
}
}

View File

@@ -0,0 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`E2E lint assertions-patternProperties 1`] = `
validating /openapi.yaml...
[1] schema.json:4:5 at #/properties/incorrectlyNamedProperty
rule/response-in-snake_case failed because the SchemaProperties didn't meet the assertions: "incorrectlyNamedProperty" should use snake_case
2 | "type": "object",
3 | "properties": {
4 | "incorrectlyNamedProperty": {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
5 | "type": "string"
6 | },
Error was generated by the rule/response-in-snake_case rule.
/openapi.yaml: validated in <test>ms
❌ Validation failed with 1 error.
run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file.
`;

View File

@@ -139,7 +139,7 @@ const Schema: NodeType = {
contains: 'Schema',
minContains: { type: 'integer', minimum: 0 },
maxContains: { type: 'integer', minimum: 0 },
patternProperties: 'SchemaProperties',
patternProperties: 'PatternProperties',
propertyNames: 'Schema',
unevaluatedItems: (value: unknown) => {
if (typeof value === 'boolean') {
@@ -278,6 +278,7 @@ export const Oas3_1Types: Record<Oas3_1NodeType, NodeType> = {
Root,
Schema,
SchemaProperties,
PatternProperties: SchemaProperties,
License,
Components,
NamedPathItems: mapOf('PathItem'),

View File

@@ -234,6 +234,7 @@ const oas3_1NodeTypesList = [
'Root',
'Schema',
'SchemaProperties',
'PatternProperties',
'Info',
'License',
'Components',