aboutsummaryrefslogtreecommitdiff
path: root/docs/refman/jsonschema.py
blob: 283d3a2d9808eee85236b64813d718ae3dc22c71 (plain)
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
# SPDX-License-Identifer: Apache-2.0
# Copyright 2021 The Meson development team

import typing as T

# The following variables define the current version of
# the JSON documentation format. This is different from
# the Meson version

VERSION_MAJOR = 1  # Changes here indicate breaking format changes (changes to existing keys)
VERSION_MINOR = 1  # Changes here indicate non-breaking changes (only new keys are added to the existing structure)

if T.TYPE_CHECKING:
    from typing_extensions import TypedDict

    class BaseObject(TypedDict):
        '''
            Base object for most dicts in the JSON doc.

            All objects inheriting from BaseObject will support
            the keys specified here:
        '''
        name:        str
        description: str
        since:       T.Optional[str]
        deprecated:  T.Optional[str]
        notes:       T.List[str]
        warnings:    T.List[str]

    class Type(TypedDict):
        obj:   str                 # References an object from `root.objects`
        holds: T.Sequence[object]  # Mypy does not support recursive dicts, but this should be T.List[Type]...

    class Argument(BaseObject):
        '''
            Object that represents any type of a single function or method argument.
        '''
        type:        T.List[Type]  # A non-empty list of types that are supported.
        type_str:    str           # Formatted version of `type`. Is guaranteed to not contain any whitespaces.
        required:    bool
        default:     T.Optional[str]
        min_varargs: T.Optional[int]  # Only relevant for varargs, must be `null` for all other types of arguments
        max_varargs: T.Optional[int]  # Only relevant for varargs, must be `null` for all other types of arguments

    class Function(BaseObject):
        '''
            Represents a function or method.
        '''
        returns:        T.List[Type]  # A non-empty list of types that are supported.
        returns_str:    str           # Formatted version of `returns`. Is guaranteed to not contain any whitespaces.
        example:        T.Optional[str]
        posargs:        T.Dict[str, Argument]
        optargs:        T.Dict[str, Argument]
        kwargs:         T.Dict[str, Argument]
        varargs:        T.Optional[Argument]
        arg_flattening: bool

    class Object(BaseObject):
        '''
            Represents all types of Meson objects. The specific object type is stored in the `object_type` field.
        '''
        example:           T.Optional[str]
        object_type:       str                    # Defines the object type: Must be one of: ELEMENTARY, BUILTIN, MODULE, RETURNED
        methods:           T.Dict[str, Function]
        is_container:      bool
        extends:           T.Optional[str]
        returned_by:       T.List[str]
        extended_by:       T.List[str]
        defined_by_module: T.Optional[str]

    class ObjectsByType(TypedDict):
        '''
            References to other objects are stored here for ease of navigation / filtering
        '''
        elementary: T.List[str]
        builtins:   T.List[str]
        returned:   T.List[str]
        modules:    T.Dict[str, T.List[str]]



    class Root(TypedDict):
        '''
            The root object of the JSON reference manual
        '''
        version_major:   int # See the description above for
        version_minor:   int # VERSION_MAJOR and VERSION_MINOR
        meson_version:   str
        functions:       T.Dict[str, Function]  # A mapping of <name> to a `Function` object for *all* Meson functions
        objects:         T.Dict[str, Object]    # A mapping of <name> to a `Object`   object for *all* Meson objects (including modules, elementary, etc.)
        objects_by_type: ObjectsByType