Skip to content

Commit

Permalink
[IDP-1496] Add rules to enforce short schema name to support ruby cli…
Browse files Browse the repository at this point in the history
…ent generation (#19)

* Add rules for short-ish schema name

Co-authored-by: heqianwang <158102624+heqianwang@users.noreply.github.com>
  • Loading branch information
PrincessMadMath and heqianwang authored May 21, 2024
1 parent 64de1d7 commit b359f52
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .spectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,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
7 changes: 7 additions & 0 deletions TestSpecs/schema-name-length-must-be-short-invalid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
openapi: 3.0.1
info:
title: dummy
components:
schemas:
VeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongName:
type: object
7 changes: 7 additions & 0 deletions TestSpecs/schema-name-length-must-be-short-valid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
openapi: 3.0.1
info:
title: dummy
components:
schemas:
ShortName:
type: object
4 changes: 3 additions & 1 deletion test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b359f52

Please sign in to comment.