-
Notifications
You must be signed in to change notification settings - Fork 37
/
.spectral.yml
1453 lines (1173 loc) · 37.9 KB
/
.spectral.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
extends: spectral:oas
rules:
cache-control-parameter-undocumented:
description: >-
Cache usage SHOULD be extensively detailed in the `description` property
to avoid data leaks or the usage of stale data.
This rule should ensure in some way that the api provider
documented extensively the cache usage to avoid data leaks
or usage of stale data.
For now this ruleset tests:
* the presence of following keywords
in the `description`: `max-age`, `private`, `no-store`, `no-cache`.
* that one and only one between Expires and Cache-Control is used.
`Cache-Control` and `Expires` should not be used in conjuction,
because `Cache-Control` overrides `Expires` when `max-age` is set.
Instead if neither `Cache-Control` or `Expires` are set, clients MAY use euristic cache
like described in RFC7234.
message: Cache usage SHOULD be documented when used.
formats:
&a1
- oas3
severity: warn
recommended: true
given: $..[parameters][?(@.in == "header" && @.name.match(/Cache-Control/i))]
then:
&a2
- field: description
function: truthy
- field: description
function: pattern
functionOptions:
match: .*(max-age|private|no-store|no-cache).*
cache-responses-undocumented:
description: >-
Cache usage SHOULD be extensively detailed in the `description` property
to avoid data leaks or the usage of stale data.
This rule should ensure in some way that the api provider
documented extensively the cache usage to avoid data leaks
or usage of stale data.
For now this ruleset tests:
* the presence of following keywords
in the `description`: `max-age`, `private`, `no-store`, `no-cache`.
* that one and only one between Expires and Cache-Control is used.
`Cache-Control` and `Expires` should not be used in conjuction,
because `Cache-Control` overrides `Expires` when `max-age` is set.
Instead if neither `Cache-Control` or `Expires` are set, clients MAY use euristic cache
like described in RFC7234.
message: Cache usage in responses SHOULD be documented in Cache-Control and/or
Expires. {{error}}
formats: *a1
severity: info
recommended: true
given: $.[responses][?(@property[0] == "2"
)][headers].[?(@property.match(/Cache-Control|Expires/i))]]
then: *a2
cache-responses-indeterminate-behavior:
description: >-
Cache usage SHOULD be extensively detailed in the `description` property
to avoid data leaks or the usage of stale data.
This rule should ensure in some way that the api provider
documented extensively the cache usage to avoid data leaks
or usage of stale data.
For now this ruleset tests:
* the presence of following keywords
in the `description`: `max-age`, `private`, `no-store`, `no-cache`.
* that one and only one between Expires and Cache-Control is used.
`Cache-Control` and `Expires` should not be used in conjuction,
because `Cache-Control` overrides `Expires` when `max-age` is set.
Instead if neither `Cache-Control` or `Expires` are set, clients MAY use euristic cache
like described in RFC7234.
message: "{{error}}"
formats: *a1
severity: info
recommended: true
given: $.[responses][?(@property[0] == "2" )][headers]
then:
- function: xor
functionOptions:
properties:
- Expires
- Cache-Control
paths-kebab-case:
x-tags:
- it
description: |
Paths should be kebab-case.
See Italian recommendation RAC_REST_NAME_002.
message: "{{property}} is not kebab-case: {{error}}"
severity: warn
recommended: true
given: $.paths[*]~
then:
function: pattern
functionOptions:
match: ^(/[a-z0-9-.]+|/{[a-zA-Z0-9_]+})+$
request-headers-pascal-case:
x-tags:
- it
description: |
Headers should be pascal-case.
See Italian recommendation RAC_REST_NAME_003.
message: "{{value}} {{error}} in {{path}}"
severity: hint
recommended: true
given:
- $.[parameters][?(@.in=="header")].name
then:
function: casing
functionOptions:
type: pascal
separator:
char: "-"
response-headers-pascal-case:
x-tags:
- it
description: |
Headers should be pascal-case.
See Italian recommendation RAC_REST_NAME_003.
message: "Header {{error}}: {{path}}"
severity: hint
recommended: true
given:
- $.[responses][*].headers.*~
then:
function: casing
functionOptions:
type: pascal
separator:
char: "-"
no-forbidden-headers:
x-tags:
- standards
description: |-
OAS do not allow using the following HTTP headers in a specification
file: Authorization, Content-Type and Accept.
You MUST use the associate functionalities provided by OAS, instead.
message: "{{error}} in {{path}} {{value}}"
severity: error
given:
- $..parameters[?(@.in == 'header')].name
- $.[responses][*].headers.*~
then:
function: pattern
functionOptions:
notMatch: /^(accept|content-type|authorization)$/i
no-x-headers-request:
x-tags:
- standards
description: "'HTTP' headers SHOULD NOT start with 'X-' RFC6648."
severity: warn
given:
- $..parameters[?(@.in == 'header')].name
message: HTTP header '{{value}}' SHOULD NOT start with 'X-' in {{path}}
recommended: true
type: style
then:
function: pattern
functionOptions:
match: /^([^x]|.[^-])|RateLimit-/i
no-x-headers-response:
x-tags:
- standards
description: "'HTTP' headers SHOULD NOT start with 'X-' RFC6648."
severity: warn
given:
- $.[responses][*].headers.*~
message: HTTP response header SHOULD NOT start with 'X-' in {{path}}
recommended: true
type: style
then:
function: pattern
functionOptions:
match: /^([^x]|.[^-])|RateLimit-/i
servers-description:
x-tags:
- metadata
- it
description: Servers must have a description.
message: Server {{path}} must have a description.
given:
- $.servers[*]
- $.paths..servers
severity: error
recommended: true
then:
field: description
function: truthy
servers-use-https:
x-tags:
- security
description: |-
Servers must use https to ensure the origin of the responses
and protect the integrity and the confidentiality of the communication.
You can use `http://` only on sandboxes environment.
Use `x-sandbox: true` to skip this kind of check.
message: "Non-sandbox url {{value}} {{error}}. Add `x-sandbox: true` to skip
this check on a specific server."
given:
- $.servers[?(@["x-sandbox"] != true)]
- $.paths..servers[?(@["x-sandbox"] != true)]
severity: error
recommended: true
then:
field: url
function: pattern
functionOptions:
match: ^https://.*
has-x-summary:
x-tags:
- it
- metadata
message: "API MUST have an one-liner #/info/x-summary field containing a brief
description."
description: >-
The `#/info/x-summary` can be used to specify a brief, one-liner
description of your API: this is very useful for catalog purposes (eg.
this can be shown as your API subtitle in catalogs and developer portals).
In OAS3.1 you can use the standard `#/info/summary` field.
given: $
severity: error
recommended: true
type: style
formats:
- oas3
then:
field: info.x-summary
function: truthy
has-termsOfService:
x-tags:
- metadata
message: "API MUST reference the URL of the Terms of Service in
#/info/termsOfService."
description: API MUST reference the URL of the Terms of Service in
`#/info/termsOfService`
given: $
severity: error
recommended: true
type: style
formats:
- oas3
then:
field: info.termsOfService
function: truthy
has-contact:
x-tags:
- metadata
description: "API MUST reference a contact, either url or email in #/info/contact"
given: $
severity: error
recommended: true
type: style
formats:
- oas3
then:
field: info.contact
function: truthy
has-x-api-id:
x-tags:
- it
- metadata
message: "API must have an unique identifier in x-api-id in #/info/x-api-id."
description: |-
The `#/info/x-api-id` field can be used to associate an identifier
to an API.
This is useful to track an API even when its `#/info/title` changes.
given: $
severity: error
recommended: true
type: style
then:
field: info.x-api-id
function: truthy
use-semver:
description: >-
The API version field should follow
[semantic versioning](https://semver.org/#semantic-versioning-specification-semver).
severity: error
recommended: true
message: Specs should follow semantic versioning. {{value}} is not a valid version.
given: $.info.version
then:
function: pattern
functionOptions:
match: ^[0-9]+.[0-9]+.[0-9]+(-[a-z0-9+.-]+)?
number-format:
x-tags:
- it
- RAC_REST_FORMAT_004
description: >-
Schema of type number or integer must specify a format
to express the associated datatype, eg. `int32`, `int64`, ...
You can express similar requirements using the `minimum` and `maximum` properties.
See recommendation RAC_REST_FORMAT_004.
message: Schema of type number or integer must specify a format. {{path}}
formats:
- oas3
severity: error
recommended: true
given: $.[?(@.type=="number")]
then:
field: format
function: truthy
integer-format:
x-tags:
- it
- RAC_REST_FORMAT_004
description: >-
Schema of type number or integer must specify a format
to express the associated datatype, eg. `int32`, `int64`, ...
You can express similar requirements using the `minimum` and `maximum` properties.
See recommendation RAC_REST_FORMAT_004.
message: Schema of type number or integer must specify a format. {{path}}
formats:
- oas3
severity: error
recommended: true
given: |
$.[?(@.type=="integer")]
then:
field: format
function: truthy
allowed-integer-format:
x-tags:
- it
- RAC_REST_FORMAT_004
description: |-
To improve interoperability, integer and number formats are constrained
to a shared subset.
See recommendation RAC_REST_FORMAT_004.
message: Type format is "{{value}}", expected one of [int32, int64]. {{path}}
formats:
- oas3
severity: hint
recommended: true
given: |
$.[?(@.type=="integer")]
then:
field: format
function: enumeration
functionOptions:
values:
- int32
- int64
allowed-number-format:
x-tags:
- it
- RAC_REST_FORMAT_004
description: |-
To improve interoperability, integer and number formats are constrained
to a shared subset.
See recommendation RAC_REST_FORMAT_004.
message: Type format is "{{value}}", expected one of [decimal32, decimal64,
decimal128, float, double]. {{path}}
formats:
- oas3
severity: hint
recommended: true
given: |
$.[?(@.type=="number")]
then:
field: format
function: enumeration
functionOptions:
values:
- decimal32
- decimal64
- float
- double
- decimal128
oas2: false
no-swagger-2:
description: Swagger 2 files are not allowed. Use OpenAPI >= 3.0
given: $
severity: error
recommended: true
type: style
formats:
- oas2
then:
field: swagger
function: falsy
patch-media-type:
x-tags:
- standards
description: >-
The PATCH specification explicits that the request body contains
a "patch document" describing the changes to be applied
to the target resource.
To avoid confusion, [this errata](https://www.rfc-editor.org/errata/eid3169)
explains that `application/json` is not an appropriate media-type for `PATCH`.
A correct example of PATCH using eg. `application/json-patch+json` media-type
defined in RFC6902.
```
paths:
/books/{book_id}:
patch:
requestBody:
content:
application/json-patch+json:
schema:
type: object
example: [{ "op": "add", "path": "/baz", "value": "qux" }]
```
message: application/json is not an appropriate media-type for PATCH. {{path}}
formats:
- oas3
severity: error
recommended: true
given: $.[patch][requestBody][content]
then:
field: application/json
function: falsy
paths-status:
x-tags:
- it
description: >-
You must define a `/status` path that can be used to health-check the API.
Using this path avoids the arbitrary usage of a server URL for health-check
scope.
The `/status` endpoint should return a `application/problem+json` response
containing a successful status code if the service is working correctly.
The service provider is free to define the implementation logic for this path.
message: The "/status" path used to health-check the API must be defined. {{error}}
severity: error
recommended: true
given: $
then:
field: paths./status.get.responses.200
function: truthy
paths-status-return-problem:
x-tags:
- it
description: '"/status" must return a Problem object.'
message: "{{error}}"
severity: error
recommended: true
given: $.paths.'/status'.get.responses.200.content.*~
then:
function: enumeration
functionOptions:
values:
- application/problem+xml
- application/problem+json
paths-status-problem-schema:
x-tags:
- it
description: '"/status" schema is not a Problem object.'
message: "{{error}} {{path}}"
severity: warn
recommended: true
given: $.paths.'/status'.get.responses.200.content.[[schema]]
then:
- function: truthy
field: properties.status
- function: truthy
field: properties.title
- function: truthy
field: properties.detail
paths-http-method:
x-tags:
- it
description: >-
When you design a REST API, you don't usually need to mention terms like
`get`, `delete` and so on in your `paths`, because this information is
conveyed by the HTTP method.
Instead of using
```
POST /books/1234/delete HTTP/1.1
Host: api.example
```
You can simply call
```
DELETE /books/1234 HTTP/1.1
Host: api.example
```
Similarly you don't need verbs like `list` or `create` because
the HTTP Semantics RFC7231 supports this kind of actions natively
with proper methods and status code.
Instead of
```
POST /create/user HTTP/1.1
Host: api.example
Content-Type: application/json
{"given_name": "Mario"}
```
You can use
```
POST /create/user HTTP/1.1
Host: api.example
Content-Type: application/json
{"given_name": "Mario"}
```
returning a proper response
```
HTTP/1.1 201 Created
Location: /users/1234
```
This simplifies securing your API as you know beforehand the kind of action
which is going to be performed.
message: API "path" contains a name of an http method. {{error}}
severity: hint
recommended: true
given:
- $.paths[?(@property.match( /\/(get|post|put|delete|patch)[\/A-Z_\-]?/
))]~
- $.paths[?(@property.match( /\/(create|remove|list)[\/A-Z_\-]?/ ))]~
then:
field: "@key"
function: undefined
use-problem-json-for-errors:
description: |-
Error management is a key enabler of a resilient API ecosystem.
Enforcing a consistent schema for errors between different APIs,
enables client to properly implement an error management strategy,
with positive impacts for users.
Error responses should return one of the media-type
defined in RFC7807:
- `application/problem+json`
- `application/problem+xml`
An example of a valid response:
```
responses:
"503":
content:
application/problem+json:
schema:
...
```
message: Error responses should support RFC7807 in {{path}}.
formats:
- oas3
severity: error
given: $.paths.[*].responses[?(@property.match(/^(4|5|default)/))].content.*~
then:
function: enumeration
functionOptions:
values:
- application/problem+xml
- application/problem+json
use-problem-schema:
description: |-
WARN: This rule is under implementation and just provides an hint.
Error management is a key enabler of a resilient API ecosystem.
Enforcing a consistent schema for errors between different APIs,
enables client to properly implement an error management strategy,
with positive impacts for users.
This rule inspects the schema returned by an error response and
verifies whether it contains the main properties defined in RFC7807:
`status`, `title` and `detail`.
An example of a valid payload is
```
{
"title": "Not Found",
"status": 404,
"detail": "Book does not exist; id: 123"
}
```
See recommendation RAC_REST_NAME_007.
message: Your schema doesn't seem to match RFC7807. Are you sure it is ok? {{path}}
formats:
- oas3
severity: hint
recommended: false
given: $.paths.[*].responses[?(@property.match(/^(4|5|default)/))][[schema]]
then:
function: schema
functionOptions:
schema:
type: object
properties:
status:
type: integer
title:
type: string
detail:
type: string
hint-problem-schema:
description: |-
WARN: This rule is under implementation and just provides an hint.
Error management is a key enabler of a resilient API ecosystem.
Enforcing a consistent schema for errors between different APIs,
enables client to properly implement an error management strategy,
with positive impacts for users.
Errors should return RFC7807 objects. Instead, this schema
seems to use non standard properties such as:
`message`, `msg` and `code`.
An error of the following form
```
{
"msg": "Book with id: 123 does not exist.",
"code": 6063
}
```
can be expressed in RFC7807 with
```
{
"detail": "Book with id: 123 does not exist.",
"type": "https://api.example/v1/errors/6063",
"status": 404,
"title": "Not Found"
}
```
Returning an URI in `type`, instead of an opaque `code` can help
the client in better identifying the error; moreover the URI
though it should not be dereferenced automatically, can return
an actual resource providing guidance in addressing the issue.
See recommendation RAC_REST_NAME_007.
message: Error response doesn't seem to match RFC7807. Are you sure it is ok?
{{path}}
formats:
- oas3
severity: hint
recommended: true
given: $.[responses][?(@property.match(/^(4|5|default)/))][[schema]][properties].*~
then:
field: "@key"
function: pattern
functionOptions:
notMatch: message|code|msg
missing-retry-after:
description: |-
When a client is either:
* throttled out with a 429 status code;
* warned about a temporary server issue with a 503 status code;
the server should explicitly communicate how long to wait
before issuing further requests using the Retry-After header.
Retry-After is defined in RFC7231.
message: "Missing ratelimit header: {{property}} in {{path}}"
formats:
- oas3
severity: warn
recommended: true
given: $.[responses][?(@property == "429" || @property == "503" )][headers]
then:
field: Retry-After
function: truthy
missing-ratelimit:
x-tags:
- it
description: >-
Ratelimiting API preserves a service and limits attack scenario
[see API4:2019 Lack of Resources & Rate Limiting](https://owasp.org/www-project-api-security).
APIs should use the following headers at least on successful responses:
- `X-RateLimit-Limit`: number of total requests in a give time window
- `X-RateLimit-Remaining`: remaining requests in the current window
- `X-RateLimit-Reset`: number of seconds before the window resets
An example set of headers is the following
```
X-Ratelimit-Limit: 100
X-Ratelimit-Remaining: 40
X-Ratelimit-Reset: 12
```
A standardization proposal for ratelimit headers is ongoning
inside the IETF HTTPAPI Workgroup.
See [the draft](https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers/)
message: Missing ratelimit headers. {{property}} {{error}} {{path}}
formats:
- oas3
severity: warn
recommended: true
given: $.[responses][?(@property[0] == "2" )][headers]
then:
- functionOptions:
properties:
- X-RateLimit-Limit
- RateLimit-Limit
function: xor
- functionOptions:
properties:
- X-RateLimit-Remaining
- RateLimit-Remaining
function: xor
- functionOptions:
properties:
- X-RateLimit-Reset
- RateLimit-Reset
function: xor
response-with-json-object:
description: |-
JSON responses MUST use JSON objects, in order to be extensible.
For example, instead of a list `[1, 2, 3]` you should return
an object `{"items": [1, 2, 3]}`.
This allows the schema to evolve in a backward compatible ways.
message: JSON responses must use json objects (eg "{}"), not {{value}}. {{path}}
severity: warn
recommended: true
given: $.[responses][*][content][?(@property.match("json$"))][schema]
then:
field: type
function: pattern
functionOptions:
match: object
array-boundaries:
description: >-
Array size should be limited to mitigate resource exhaustion attacks.
This can be done using `maxItems` and `minItems`, like in the example
below.
```
Limited:
type: array
maxItems: 10
items:
type: string
format: date
```
You should ensure that the schema referenced in `items` is constrained too.
If you delegate input validation to a library or framework,
be sure to test it thoroughly and ensure that it verifies `maxItems`.
message: Schema of type array must specify maxItems and minItems. {{path}} {{error}}
formats:
- oas3
severity: warn
recommended: true
given:
- $.[?(@.type=="array")]
then:
- field: maxItems
function: defined
- field: minItems
function: defined
number-boundaries:
description: |-
Numeric values should be limited in size to mitigate resource exhaustion
using `maximum` and `minimum`.
If you delegate input validation to a library or framework,
be sure to test it thoroughly.
message: Schema of type number or integer must specify a maximum and a minimum.
{{path}} {{error}}
formats:
- oas3
severity: warn
recommended: true
given:
- $.[?(@.type=="number")]
- $.[?(@.type=="integer")]
then:
- field: maximum
function: defined
- field: minimum
function: defined
no-additionalProperties:
description: |-
By default, jsonschema allows additionalProperties. This means
that schema validators can be bypassed using further, unspecified
fields.
While forbidding additionalProperties can create rigidity and hinder
the evolution of an API - eg making it hard to accept new parameters
or fields - it is possible that this flexibility can be used
to bypass the schema validator and force the application to process
unwanted information.
Disable `additionalProperties` with `false`
```
Person:
type: object
additionalProperties: false
properties:
given_name:
type: string
pattern: [a-zA-Z ]{24}
```
Or constraint them using `maxProperties`
```
Person:
type: object
additionalProperties:
type: string
pattern: /+39[0-9]{,14}/
maxProperties: 3
properties:
given_name:
type: string
pattern: [a-zA-Z ]{24}
```
- no additionalProperties
- constrained additionalProperties
message: "Objects should not allow additionalProperties. Disable them with
`additionalProperties: false` or constraint them."
formats:
- oas3
severity: warn
recommended: true
given:
- $.[?(@.type=="object" && @.additionalProperties==true)]
then:
- field: additionalProperties
function: falsy
no-default-additionalProperties:
description: |-
By default, jsonschema allows additionalProperties. This means
that schema validators can be bypassed using further, unspecified
fields.
While forbidding additionalProperties can create rigidity and hinder
the evolution of an API - eg making it hard to accept new parameters
or fields - it is possible that this flexibility can be used
to bypass the schema validator and force the application to process
unwanted information.
Disable `additionalProperties` with `false`
```
Person:
type: object
additionalProperties: false
properties:
given_name:
type: string
pattern: [a-zA-Z ]{24}
```
Or constraint them using `maxProperties`
```
Person:
type: object
additionalProperties:
type: string
pattern: /+39[0-9]{,14}/
maxProperties: 3
properties:
given_name: