From 09ba44444c9c4e43f5657c07db6717fe1c679681 Mon Sep 17 00:00:00 2001 From: Mathieu Gamache Date: Tue, 21 May 2024 14:57:06 -0400 Subject: [PATCH 1/3] Add rules for short-ish schema name --- .spectral.yaml | 8 ++++++++ TestSpecs/schema-name-length-invalid.yaml | 7 +++++++ TestSpecs/schema-name-length-valid.yaml | 7 +++++++ test.ps1 | 4 +++- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 TestSpecs/schema-name-length-invalid.yaml create mode 100644 TestSpecs/schema-name-length-valid.yaml diff --git a/.spectral.yaml b/.spectral.yaml index ec8ee4a..b96b874 100644 --- a/.spectral.yaml +++ b/.spectral.yaml @@ -102,3 +102,11 @@ rules: function: pattern functionOptions: notMatch: 'string' + + schema-name-length: + description: "Schema name must not be too long to support client generation. Current limitation come from the Ruby using tar which have a limit of 100 characters." + given: $.components.schemas[*]~ + then: + function: length + functionOptions: + max: 95 \ No newline at end of file diff --git a/TestSpecs/schema-name-length-invalid.yaml b/TestSpecs/schema-name-length-invalid.yaml new file mode 100644 index 0000000..134292a --- /dev/null +++ b/TestSpecs/schema-name-length-invalid.yaml @@ -0,0 +1,7 @@ +openapi: 3.0.1 +info: + title: dummy +components: + schemas: + VeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongName: + type: object \ No newline at end of file diff --git a/TestSpecs/schema-name-length-valid.yaml b/TestSpecs/schema-name-length-valid.yaml new file mode 100644 index 0000000..91bc9bf --- /dev/null +++ b/TestSpecs/schema-name-length-valid.yaml @@ -0,0 +1,7 @@ +openapi: 3.0.1 +info: + title: dummy +components: + schemas: + ShortName: + type: object \ No newline at end of file diff --git a/test.ps1 b/test.ps1 index 8a10e66..83f7617 100644 --- a/test.ps1 +++ b/test.ps1 @@ -25,7 +25,9 @@ $tests = @( @{ rule = "schema-ids-must-have-alphanumeric-characters-only"; expectError = $false; filename = "schema-ids-must-have-alphanumeric-characters-only-valid.yaml" }, @{ rule = "schema-ids-must-have-alphanumeric-characters-only"; expectError = $true; filename = "schema-ids-must-have-alphanumeric-characters-only-invalid.yaml" }, @{ rule = "schema-object-must-have-a-type"; expectError = $false; filename = "schema-object-must-have-a-type-valid.yaml" }, - @{ rule = "schema-object-must-have-a-type"; expectError = $true; filename = "schema-object-must-have-a-type-invalid.yaml" } + @{ rule = "schema-object-must-have-a-type"; expectError = $true; filename = "schema-object-must-have-a-type-invalid.yaml" }, + @{ rule = "schema-name-length"; expectError = $false; filename = "schema-name-length-valid.yaml" }, + @{ rule = "schema-name-length"; expectError = $true; filename = "schema-name-length-invalid.yaml" } ) $fileCount = Get-ChildItem (Join-Path $PSScriptRoot "TestSpecs") | Measure-Object | Select-Object -ExpandProperty Count From be4d11dc9a00a0b93abd764ac3706afb3aaa619a Mon Sep 17 00:00:00 2001 From: Mathieu Gamache Date: Tue, 21 May 2024 15:19:37 -0400 Subject: [PATCH 2/3] PR fixes --- .spectral.yaml | 2 +- ...lid.yaml => schema-name-length-must-be-short-invalid.yaml} | 0 ...valid.yaml => schema-name-length-must-be-short-valid.yaml} | 0 test.ps1 | 4 ++-- 4 files changed, 3 insertions(+), 3 deletions(-) rename TestSpecs/{schema-name-length-invalid.yaml => schema-name-length-must-be-short-invalid.yaml} (100%) rename TestSpecs/{schema-name-length-valid.yaml => schema-name-length-must-be-short-valid.yaml} (100%) diff --git a/.spectral.yaml b/.spectral.yaml index b96b874..cc0e86a 100644 --- a/.spectral.yaml +++ b/.spectral.yaml @@ -103,7 +103,7 @@ rules: functionOptions: notMatch: 'string' - schema-name-length: + schema-name-length-must-be-short: description: "Schema name must not be too long to support client generation. Current limitation come from the Ruby using tar which have a limit of 100 characters." given: $.components.schemas[*]~ then: diff --git a/TestSpecs/schema-name-length-invalid.yaml b/TestSpecs/schema-name-length-must-be-short-invalid.yaml similarity index 100% rename from TestSpecs/schema-name-length-invalid.yaml rename to TestSpecs/schema-name-length-must-be-short-invalid.yaml diff --git a/TestSpecs/schema-name-length-valid.yaml b/TestSpecs/schema-name-length-must-be-short-valid.yaml similarity index 100% rename from TestSpecs/schema-name-length-valid.yaml rename to TestSpecs/schema-name-length-must-be-short-valid.yaml diff --git a/test.ps1 b/test.ps1 index 83f7617..efdd810 100644 --- a/test.ps1 +++ b/test.ps1 @@ -26,8 +26,8 @@ $tests = @( @{ rule = "schema-ids-must-have-alphanumeric-characters-only"; expectError = $true; filename = "schema-ids-must-have-alphanumeric-characters-only-invalid.yaml" }, @{ rule = "schema-object-must-have-a-type"; expectError = $false; filename = "schema-object-must-have-a-type-valid.yaml" }, @{ rule = "schema-object-must-have-a-type"; expectError = $true; filename = "schema-object-must-have-a-type-invalid.yaml" }, - @{ rule = "schema-name-length"; expectError = $false; filename = "schema-name-length-valid.yaml" }, - @{ rule = "schema-name-length"; expectError = $true; filename = "schema-name-length-invalid.yaml" } + @{ rule = "schema-name-length-must-be-short"; expectError = $false; filename = "schema-name-length-must-be-short-valid.yaml" }, + @{ rule = "schema-name-length-must-be-short"; expectError = $true; filename = "schema-name-length-must-be-short-invalid.yaml" } ) $fileCount = Get-ChildItem (Join-Path $PSScriptRoot "TestSpecs") | Measure-Object | Select-Object -ExpandProperty Count From 388f626413c49b69e8854ab6188b011bb42afc56 Mon Sep 17 00:00:00 2001 From: Mathieu Gamache Date: Tue, 21 May 2024 16:06:10 -0400 Subject: [PATCH 3/3] Update .spectral.yaml Co-authored-by: heqianwang <158102624+heqianwang@users.noreply.github.com> --- .spectral.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.spectral.yaml b/.spectral.yaml index cc0e86a..639d7a8 100644 --- a/.spectral.yaml +++ b/.spectral.yaml @@ -104,7 +104,7 @@ rules: notMatch: 'string' schema-name-length-must-be-short: - description: "Schema name must not be too long to support client generation. Current limitation come from the Ruby using tar which have a limit of 100 characters." + description: "Schema name must not be too long to support client generation. Current limitation comes from Ruby packages which uses tar and has a limit of 100 characters." given: $.components.schemas[*]~ then: function: length