File: Type.hpp

package info (click to toggle)
reflect-cpp 0.18.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 12,524 kB
  • sloc: cpp: 44,484; python: 131; makefile: 30; sh: 3
file content (153 lines) | stat: -rw-r--r-- 3,617 bytes parent folder | download | duplicates (2)
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
#ifndef RFL_JSON_SCHEMA_TYPE_HPP_
#define RFL_JSON_SCHEMA_TYPE_HPP_

#include <map>
#include <memory>
#include <optional>
#include <string>

#include "../../Literal.hpp"
#include "../../Object.hpp"
#include "../../Rename.hpp"
#include "../../Variant.hpp"

namespace rfl::json::schema {

/// The JSON representation of internal::schema::Type.
struct Type {
  struct Boolean {
    std::optional<std::string> description;
    Literal<"boolean"> type;
  };

  struct Integer {
    Literal<"integer"> type;
    std::optional<std::string> description;
  };

  struct Number {
    Literal<"number"> type;
    std::optional<std::string> description;
  };

  struct String {
    Literal<"string"> type;
    std::optional<std::string> description;
    rfl::Rename<"minLength", std::optional<size_t>> minSize;
    rfl::Rename<"maxLength", std::optional<size_t>> maxSize;
  };

  using NumericType = rfl::Variant<Integer, Number>;

  struct AllOf {
    std::optional<std::string> description;
    std::vector<Type> allOf;
  };

  struct AnyOf {
    std::optional<std::string> description;
    std::vector<Type> anyOf;
  };

  struct ExclusiveMaximum {
    std::optional<std::string> description;
    rfl::Variant<double, int> exclusiveMaximum;
    std::string type;
  };

  struct ExclusiveMinimum {
    std::optional<std::string> description;
    rfl::Variant<double, int> exclusiveMinimum;
    std::string type;
  };

  struct FixedSizeTypedArray {
    Literal<"array"> type;
    std::optional<std::string> description;
    rfl::Ref<Type> items;
    size_t minItems;
    size_t maxItems;
  };

  struct Maximum {
    std::optional<std::string> description;
    rfl::Variant<double, int> maximum;
    std::string type;
  };

  struct Minimum {
    std::optional<std::string> description;
    rfl::Variant<double, int> minimum;
    std::string type;
  };

  struct Null {
    Literal<"null"> type;
    std::optional<std::string> description;
  };

  struct Object {
    Literal<"object"> type;
    std::optional<std::string> description;
    rfl::Object<Type> properties;
    std::vector<std::string> required;
    std::shared_ptr<Type> additionalProperties;
  };

  struct OneOf {
    std::optional<std::string> description;
    std::vector<Type> oneOf;
  };

  struct Reference {
    Rename<"$ref", std::optional<std::string>> ref;
    std::optional<std::string> description;
  };

  struct Regex {
    Literal<"string"> type;
    std::optional<std::string> description;
    std::string pattern;
  };

  struct StringEnum {
    Literal<"string"> type;
    std::optional<std::string> description;
    rfl::Rename<"enum", std::vector<std::string>> values;
  };

  struct StringMap {
    Literal<"object"> type;
    std::optional<std::string> description;
    rfl::Ref<Type> additionalProperties;
  };

  struct Tuple {
    Literal<"array"> type;
    std::optional<std::string> description;
    std::vector<Type> prefixItems;
    bool items = false;
  };

  struct TypedArray {
    Literal<"array"> type;
    std::optional<std::string> description;
    rfl::Ref<Type> items;
    rfl::Rename<"minItems", std::optional<size_t>> minSize;
    rfl::Rename<"maxItems", std::optional<size_t>> maxSize;
  };

  using ReflectionType =
      rfl::Variant<AllOf, AnyOf, Boolean, ExclusiveMaximum, ExclusiveMinimum,
                   FixedSizeTypedArray, Integer, Maximum, Minimum, Number, Null,
                   Object, OneOf, Reference, Regex, String, StringEnum,
                   StringMap, Tuple, TypedArray>;

  const auto& reflection() const { return value; }

  ReflectionType value;
};

}  // namespace rfl::json::schema

#endif