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# Schema validation
You can use API Star to validate your API Schema. When errors occur it'll
give you a full breakdown of exactly where the schema is incorrect.
```shell
$ apistar validate --path schema.json --format openapi
โ Valid OpenAPI schema.
```
## Configuration
Configure the defaults for `apistar validate` using an `apistar.yml` file.
```yaml
schema:
path: schema.json
format: openapi
```
You can now run the validation like so:
```shell
$ apistar validate
โ Valid OpenAPI schema.
```
## Programmatic interface
You can also run the schema validation programmatically:
```python
import apistar
schema = """
openapi: 3.0.0
info:
title: Widget API
version: '1.0'
description: An example API for widgets
paths:
/widgets:
get:
summary: List all the widgets.
operationId: listWidgets
parameters:
- in: query
name: search
description: Filter widgets by this search term.
schema:
type: string
"""
apistar.validate(schema, format='openapi', encoding="yaml")
```
Function signature: `validate(schema, format=None, encoding=None)`
* `schema` - Either a dict representing the schema, or a string/bytestring.
* `format` - One of `openapi`, `swagger`, `jsonschema` or `config`.
If unset, one of either `openapi` or `swagger` will be inferred from the content if possible.
* `encoding` - If schema is passed as a string/bytestring then the encoding may be
specified as either "json" or "yaml". If unset, it will be inferred from the content if possible.