diff --git a/.spectral.yaml b/.spectral.yaml index ec8ee4a..639d7a8 100644 --- a/.spectral.yaml +++ b/.spectral.yaml @@ -102,3 +102,11 @@ rules: function: pattern functionOptions: notMatch: 'string' + + schema-name-length-must-be-short: + 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 + functionOptions: + max: 95 \ No newline at end of file diff --git a/TestSpecs/schema-name-length-must-be-short-invalid.yaml b/TestSpecs/schema-name-length-must-be-short-invalid.yaml new file mode 100644 index 0000000..134292a --- /dev/null +++ b/TestSpecs/schema-name-length-must-be-short-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-must-be-short-valid.yaml b/TestSpecs/schema-name-length-must-be-short-valid.yaml new file mode 100644 index 0000000..91bc9bf --- /dev/null +++ b/TestSpecs/schema-name-length-must-be-short-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..efdd810 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-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