Skip to content

Commit

Permalink
Merge branch 'develop' into fix/ruleset-asyncapi-schema-example-valid…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
mnaumanali94 authored Jul 22, 2024
2 parents 726774e + 048924d commit e68d211
Show file tree
Hide file tree
Showing 16 changed files with 421 additions and 44 deletions.
4 changes: 1 addition & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ about: Create a report to help us improve
labels: bug
---

> For support questions, please use the [Stoplight Discord Community](https://discord.com/invite/stoplight). This repository's issues are reserved for feature requests and bug reports. If you are unsure if you are experiencing a bug, our Discord is a great place to start.
>
> **Please delete this section, any any sections below that you don't use, before creating the issue.**
> **Please delete this section, and any sections below that you don't use, before creating the issue.**
**Describe the bug**
A clear and concise description of what the bug is.
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/*
18.18.2
31 changes: 31 additions & 0 deletions docs/reference/openapi-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,37 @@ TheBadModel:
- 8
```

### array-items

Schemas with `type: array`, require a sibling `items` field.

**Recommended:** Yes

**Good Example**

```yaml
TheGoodModel:
type: object
properties:
favoriteColorSets:
type: array
items:
type: array
items: {}
```

**Bad Example**

```yaml
TheBadModel:
type: object
properties:
favoriteColorSets:
type: array
items:
type: array
```

## OpenAPI v2.0-only

These rules will only apply to OpenAPI v2.0 documents.
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@types/yargs": "^17.0.8",
"@yao-pkg/pkg": "^5.11.1",
"es-aggregate-error": "^1.0.7",
"nock": "^13.1.3",
"nock": "^13.5.4",
"xml2js": "^0.5.0"
},
"pkg": {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@stoplight/json": "~3.21.0",
"@stoplight/path": "1.3.2",
"@stoplight/spectral-parsers": "^1.0.0",
"@stoplight/spectral-ref-resolver": "^1.0.0",
"@stoplight/spectral-ref-resolver": "^1.0.4",
"@stoplight/spectral-runtime": "^1.0.0",
"@stoplight/types": "~13.6.0",
"@types/es-aggregate-error": "^1.0.2",
Expand All @@ -63,7 +63,7 @@
"@stoplight/yaml": "^4.2.2",
"@types/minimatch": "^3.0.5",
"@types/treeify": "^1.0.0",
"nock": "^13.1.0",
"nock": "^13.5.4",
"treeify": "^1.1.0"
}
}
7 changes: 7 additions & 0 deletions packages/functions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# @stoplight/spectral-functions [1.8.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-functions-v1.7.2...@stoplight/spectral-functions-1.8.0) (2024-06-07)


### Features

* **rulesets:** add multiple xor ([#2614](https://github.com/stoplightio/spectral/issues/2614)) ([af9c742](https://github.com/stoplightio/spectral/commit/af9c742ef8a9e0749031f41ecf9466e15be9acdd))

# [@stoplight/spectral-functions-v1.7.2](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-functions-v1.7.1...@stoplight/spectral-functions-v1.7.2) (2022-12-13)


Expand Down
2 changes: 1 addition & 1 deletion packages/functions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/spectral-functions",
"version": "1.7.2",
"version": "1.8.0",
"sideEffects": false,
"homepage": "https://github.com/stoplightio/spectral",
"bugs": "https://github.com/stoplightio/spectral/issues",
Expand Down
2 changes: 1 addition & 1 deletion packages/ruleset-bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@stoplight/spectral-formats": ">=1",
"@stoplight/spectral-functions": ">=1",
"@stoplight/spectral-parsers": ">=1",
"@stoplight/spectral-ref-resolver": ">=1",
"@stoplight/spectral-ref-resolver": "^1.0.4",
"@stoplight/spectral-ruleset-migrator": "^1.7.4",
"@stoplight/spectral-rulesets": ">=1",
"@stoplight/spectral-runtime": "^1.1.0",
Expand Down
21 changes: 21 additions & 0 deletions packages/rulesets/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## @stoplight/spectral-rulesets [1.19.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-rulesets-1.19.0...@stoplight/spectral-rulesets-1.19.1) (2024-06-10)


### Bug Fixes

* **rulesets:** fixed array-items type property selector ([#2638](https://github.com/stoplightio/spectral/issues/2638)) ([0845fb5](https://github.com/stoplightio/spectral/commit/0845fb5b27e372161c9dd0454e8176263b042e08))

# @stoplight/spectral-rulesets [1.19.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-rulesets-1.18.1...@stoplight/spectral-rulesets-1.19.0) (2024-06-07)


### Bug Fixes

* **rulesets:** example validation for required readOnly and writeOnly properties ([#2573](https://github.com/stoplightio/spectral/issues/2573)) ([ae1fea5](https://github.com/stoplightio/spectral/commit/ae1fea50bc37faf7bb230e58158c5d490fc8fb42))


### Features

* **rulesets:** add new rule that requires sibling items field for type array ([#2632](https://github.com/stoplightio/spectral/issues/2632)) ([24198bc](https://github.com/stoplightio/spectral/commit/24198bcb32eafdeb119ee2432d8488d7a5af14aa))
* **rulesets:** add oas3_1-servers-in-webhook and oas3_1-callbacks-in… ([#2581](https://github.com/stoplightio/spectral/issues/2581)) ([7a8cc0e](https://github.com/stoplightio/spectral/commit/7a8cc0e62c09aca2d579bb81a2602c17028efb49))
* **rulesets:** improve {oas2,oas3}-valid-schema rule ([#2574](https://github.com/stoplightio/spectral/issues/2574)) ([8df2c36](https://github.com/stoplightio/spectral/commit/8df2c36d7461a86b3f6fb77fcd1759ed0c3750a0))

## @stoplight/spectral-rulesets [1.18.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-rulesets-1.18.0...@stoplight/spectral-rulesets-1.18.1) (2023-12-13)


Expand Down
4 changes: 2 additions & 2 deletions packages/rulesets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/spectral-rulesets",
"version": "1.18.1",
"version": "1.19.1",
"homepage": "https://github.com/stoplightio/spectral",
"bugs": "https://github.com/stoplightio/spectral/issues",
"author": "Stoplight <[email protected]>",
Expand Down Expand Up @@ -37,7 +37,7 @@
"devDependencies": {
"@stoplight/path": "^1.3.2",
"@stoplight/spectral-parsers": "*",
"@stoplight/spectral-ref-resolver": "*",
"@stoplight/spectral-ref-resolver": "^1.0.4",
"gzip-size": "^6.0.0",
"immer": "^9.0.6",
"terser": "^5.26.0"
Expand Down
234 changes: 234 additions & 0 deletions packages/rulesets/src/oas/__tests__/array-items.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
import { DiagnosticSeverity } from '@stoplight/types';

import testRule from '../../__tests__/__helpers__/tester';

testRule('array-items', [
{
name: 'valid case',
document: {
swagger: '2.0',
securityDefinitions: {
apikey: {},
},
paths: {
'/path': {
get: {
security: [
{
apikey: [],
},
],
},
},
},
},
errors: [],
},

{
name: 'array items sibling is present in a oas2 document',
document: {
swagger: '2.0',
securityDefinitions: {
apikey: {},
$ref: '#/securityDefinitions/apikey',
},
paths: {
$ref: '#/securityDefinitions/apikey',
'/path': {
get: {
'200': {
schema: {
type: 'array',
items: {},
},
},
},
post: {
'201': {
type: 'array',
items: {
type: 'array',
items: {},
},
},
},
},
},
},
errors: [],
},

{
name: 'array items sibling is present in oas3 document',
document: {
$ref: '#/',
responses: {
200: {
type: 'array',
items: {},
},
201: {
type: 'array',
items: {
type: 'array',
items: {},
},
},
},
openapi: '3.0.0',
},
errors: [],
},

{
name: 'array items sibling is present in oas3.1 document',
document: {
openapi: '3.1.0',
paths: {
'/path': {
get: {
responses: {
'200': {
type: 'array',
items: {},
},
},
},
post: {
responses: {
'201': {
type: 'array',
items: {
type: 'array',
items: {},
},
},
},
},
},
},
},
errors: [],
},

{
name: 'array items sibling is missing in a oas2 document',
document: {
swagger: '2.0',
securityDefinitions: {
apikey: {},
$ref: '#/securityDefinitions/apikey',
},
paths: {
$ref: '#/securityDefinitions/apikey',
'/path': {
get: {
'200': {
schema: {
type: 'array',
},
},
},
post: {
'201': {
type: 'array',
items: {
type: 'array',
},
},
},
},
},
},
errors: [
{
code: 'array-items',
message: 'Schemas with "type: array", require a sibling "items" field',
path: ['paths', '/path', 'get', '200', 'schema'],
severity: DiagnosticSeverity.Error,
},
{
code: 'array-items',
message: 'Schemas with "type: array", require a sibling "items" field',
path: ['paths', '/path', 'post', '201', 'items'],
severity: DiagnosticSeverity.Error,
},
],
},

{
name: 'array items sibling is missing in oas3 document',
document: {
$ref: '#/',
responses: {
200: {
type: 'array',
},
201: {
type: 'array',
items: {
type: 'array',
},
},
},
openapi: '3.0.0',
},
errors: [
{
code: 'array-items',
message: 'Schemas with "type: array", require a sibling "items" field',
path: ['responses', '200'],
severity: DiagnosticSeverity.Error,
},
{
code: 'array-items',
message: 'Schemas with "type: array", require a sibling "items" field',
path: ['responses', '201', 'items'],
severity: DiagnosticSeverity.Error,
},
],
},

{
name: 'array items sibling is missing in oas3.1 document',
document: {
openapi: '3.1.0',
paths: {
'/path': {
get: {
responses: {
'200': {
type: 'array',
},
},
},
post: {
responses: {
'201': {
type: 'array',
items: {
type: 'array',
},
},
},
},
},
},
},
errors: [
{
code: 'array-items',
message: 'Schemas with "type: array", require a sibling "items" field',
path: ['paths', '/path', 'get', 'responses', '200'],
severity: DiagnosticSeverity.Error,
},
{
code: 'array-items',
message: 'Schemas with "type: array", require a sibling "items" field',
path: ['paths', '/path', 'post', 'responses', '201', 'items'],
severity: DiagnosticSeverity.Error,
},
],
},
]);
Loading

0 comments on commit e68d211

Please sign in to comment.