Skip to content

Commit 280095b

Browse files
Add schema structure docs
Co-authored-by: Seth Michael Larson <seth.larson@elastic.co>
1 parent 498e050 commit 280095b

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ Finally open a pull request with your changes.
210210
- [Documenting the API specification](./docs/doc-comments-guide.md)
211211
- [Known issues](./docs/known-issues.md)
212212
- [Modeling Guide](./docs/modeling-guide.md)
213+
- [Schema structure](./docs/schema-structure.md)
213214
- [Specification structure](./docs/specification-structure.md)
214215
- [Style Guide](./docs/style-guide.md)
215216
- [Fixing a defintion, a complete story](./docs/validation-example.md)

docs/schema-structure.md

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Schema structure
2+
3+
The goal of the specification is to be used by different languages, from dynamically typed to statically typed.
4+
To achieve this goal the specification contains a series of custom structures that may not have a meaning
5+
for the target language, but they should be translated to the most appropriate construct.
6+
7+
The specification is written in [TypeScript](https://www.typescriptlang.org/), you can find all
8+
the basic types [here](https://www.typescriptlang.org/docs/handbook/basic-types.html),
9+
while in [behaviors](./behaviors.md) you can find the list of special interfaces used
10+
for describing APIs that can't be represented in the specification.
11+
12+
Refer to the [documentation guide](doc-comments-guide.md) to add documentation to types and fields,
13+
and to the [modeling guide](modeling-guide.md) to learn how to model the different types.
14+
15+
You can find the schema representing all APIs and types in the [output folder](output/schema/schema.json).
16+
The schema is structured as follows:
17+
18+
```jsonc
19+
{
20+
"_info": {
21+
"license": {
22+
"name": "Apache 2.0",
23+
"url": "https://github.com/elastic/elasticsearch-specification/blob/main/LICENSE"
24+
},
25+
"title": "Elasticsearch Request & Response Specification"
26+
},
27+
"endpoints": [...],
28+
"types": [...]
29+
}
30+
```
31+
32+
The `endpoints` array contains the list of every endpoint supported by Elasticsearch,
33+
while the `types` array contains the list of every type present in the specification
34+
to model the various endpoints.
35+
36+
## Specification format
37+
38+
The specification's specification can be found [here](compiler/src/model/metamodel.ts).
39+
40+
## Identify a type by name
41+
42+
Each type can be uniquely identified by its type name, which is an object with two keys:
43+
- `name`
44+
- `namespace`
45+
46+
The `name` is the same name given to the type in the specification, while the `namespace`
47+
is the formatted path where the type is stored. For example:
48+
49+
```ts
50+
// file: specification/security/_types/User.ts
51+
export class User {
52+
email?: string | null
53+
full_name?: Name | null
54+
metadata: Metadata
55+
roles: string[]
56+
username: Username
57+
enabled: boolean
58+
}
59+
```
60+
61+
The type name will be:
62+
```json
63+
{
64+
"name": "User",
65+
"namespace": "security._types"
66+
}
67+
```
68+
69+
## Identify a type by kind
70+
71+
Each type in the specification has a `kind` property, which can be used to detect
72+
what type you are dealing with, for example:
73+
74+
```jsonc
75+
{
76+
"kind": "interface",
77+
"name": {
78+
"name": "User",
79+
"namespace": "security._types"
80+
},
81+
"properties": [...],
82+
"specLocation": "security/_types/User.ts#L22-L29"
83+
}
84+
```
85+
86+
## The `_builtins` namespace
87+
88+
In the `schema.json` you will find a namespace that is not present in the `specification` folder named `_builtins`.
89+
This namespace houses all the primitive types that you might need.
90+
91+
- `string`
92+
- `boolean`
93+
- `number`
94+
- `null`
95+
- `void`
96+
- `binary`
97+
98+

0 commit comments

Comments
 (0)