forked from Azure/azure-openapi-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
40 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import collectionObjectPropertiesNaming from "./functions/collection-object-prop | |
import { consistentPatchProperties } from "./functions/consistent-patch-properties" | ||
import { DeleteResponseCodes } from "./functions/delete-response-codes" | ||
import { longRunningResponseStatusCodeArm } from "./functions/Extensions/long-running-response-status-code" | ||
import { getCollectionOnlyHasValueAndNextLink } from "./functions/get-collection-only-has-value-nextlink" | ||
import { getCollectionResponseSchema } from "./functions/get-collection-response-schema" | ||
import hasApiVersionParameter from "./functions/has-api-version-parameter" | ||
import hasheader from "./functions/has-header" | ||
import httpsSupportedScheme from "./functions/https-supported-scheme" | ||
|
@@ -290,15 +290,16 @@ const ruleset: any = { | |
}, | ||
}, | ||
// RPC Codes: RPC-Get-V1-09, RPC-Arg-V1-01, RPC-Get-V1-06 | ||
GetCollectionOnlyHasValueAndNextLink: { | ||
GetCollectionResponseSchema: { | ||
description: "Get endpoints for collections of resources must only have the `value` and `nextLink` properties in their model.", | ||
message: "{{description}}", | ||
severity: "error", | ||
resolved: true, | ||
formats: [oas2], | ||
given: "$[paths,'x-ms-paths'][?([email protected]('}') && [email protected]('operations'))][get].responses.200.schema.properties", | ||
given: | ||
"$[paths,'x-ms-paths'][?([email protected]('}') && @property.endsWith('s') && [email protected]('operations'))][get].responses.200.schema.properties", | ||
then: { | ||
function: getCollectionOnlyHasValueAndNextLink, | ||
function: getCollectionResponseSchema, | ||
}, | ||
}, | ||
|
||
|
17 changes: 0 additions & 17 deletions
17
packages/rulesets/src/spectral/functions/get-collection-only-has-value-nextlink.ts
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
packages/rulesets/src/spectral/functions/get-collection-response-schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Verifies that collection get schemas have only the `value` and `nextLink` properties in their models. | ||
|
||
const ALLOWED_KEYS = ["value", "nextLink"] | ||
const ERROR_MESSAGE = "Get endpoints for collections of resources must only have the `value` and `nextLink` properties in their model." | ||
|
||
// TODO: might need to use something like getCollectionApiInfo() in arm-helper.ts | ||
// TODO: can't call it this. there already is a rule fo this GetCollectionResponseSchema.ts | ||
|
||
export const getCollectionResponseSchema = (properties: any, _opts: any, ctx: any) => { | ||
if (!properties || typeof properties !== "object") { | ||
return [] | ||
} | ||
const keys = Object.keys(properties) | ||
|
||
if (keys.length > 2 || keys.some((key) => !ALLOWED_KEYS.includes(key))) { | ||
return [ | ||
{ | ||
message: ERROR_MESSAGE, | ||
}, | ||
] | ||
} | ||
return [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters