Sonde
v1.1.0
Embeddable Model Context Protocol server for Qt applications
Toggle main menu visibility
Loading...
Searching...
No Matches
schema.h
Go to the documentation of this file.
1
#pragma once
2
15
16
#include <
sonde/global.h
>
17
18
#include <QtCore/QJsonArray>
19
#include <QtCore/QJsonObject>
20
#include <QtCore/QStringList>
21
22
namespace
Sonde
{
23
25
enum class
JsonType
{
26
String
,
27
Integer
,
28
Number
,
29
Boolean
,
30
Array
,
31
Object
,
32
};
33
35
inline
QString
jsonTypeName
(
JsonType
type)
36
{
37
switch
(type) {
38
case
JsonType::String
:
39
return
QStringLiteral(
"string"
);
40
case
JsonType::Integer
:
41
return
QStringLiteral(
"integer"
);
42
case
JsonType::Number
:
43
return
QStringLiteral(
"number"
);
44
case
JsonType::Boolean
:
45
return
QStringLiteral(
"boolean"
);
46
case
JsonType::Array
:
47
return
QStringLiteral(
"array"
);
48
case
JsonType::Object
:
49
return
QStringLiteral(
"object"
);
50
}
51
Q_UNREACHABLE_RETURN(QString());
52
}
53
54
}
// namespace Sonde
55
58
namespace
Sonde::Schema
{
59
62
inline
QJsonObject
described
(QJsonObject schema,
const
QString &description)
63
{
64
if
(!description.isEmpty())
65
schema.insert(QStringLiteral(
"description"
), description);
66
return
schema;
67
}
68
71
inline
QJsonObject
property
(
JsonType
type,
const
QString &description)
72
{
73
return
described
({ { QStringLiteral(
"type"
),
jsonTypeName
(type) } }, description);
74
}
75
77
inline
QJsonObject
anyProperty
(
const
QString &description)
78
{
79
return
described
({ }, description);
80
}
81
83
inline
QJsonObject
enumProperty
(
const
QStringList &values,
const
QString &description)
84
{
85
return
described
({ { QStringLiteral(
"type"
), QStringLiteral(
"string"
) },
86
{ QStringLiteral(
"enum"
), QJsonArray::fromStringList(values) } },
87
description);
88
}
89
91
inline
QJsonObject
arrayProperty
(
const
QJsonObject &items,
const
QString &description)
92
{
93
QJsonObject p =
described
({ { QStringLiteral(
"type"
), QStringLiteral(
"array"
) } }, description);
94
if
(!items.isEmpty())
95
p.insert(QStringLiteral(
"items"
), items);
96
return
p;
97
}
98
103
inline
QJsonObject
object
(
const
QJsonObject &properties,
const
QStringList &required = { })
104
{
105
QJsonObject s{ { QStringLiteral(
"type"
), QStringLiteral(
"object"
) },
106
{ QStringLiteral(
"properties"
), properties } };
107
if
(!required.isEmpty())
108
s.insert(QStringLiteral(
"required"
), QJsonArray::fromStringList(required));
109
return
s;
110
}
111
112
}
// namespace Sonde::Schema
global.h
What every Sonde header includes: the version, and the deprecation macros (design 0031).
Sonde::Schema
Builders for tool argument schemas (JSON Schema subsets that the server's argument check understands:...
Definition
schema.h:58
Sonde::Schema::arrayProperty
QJsonObject arrayProperty(const QJsonObject &items, const QString &description)
An array property whose elements match items (an empty object allows anything).
Definition
schema.h:91
Sonde::Schema::enumProperty
QJsonObject enumProperty(const QStringList &values, const QString &description)
A string property restricted to values.
Definition
schema.h:83
Sonde::Schema::anyProperty
QJsonObject anyProperty(const QString &description)
A property of any JSON type.
Definition
schema.h:77
Sonde::Schema::property
QJsonObject property(JsonType type, const QString &description)
A property of a JSON type.
Definition
schema.h:71
Sonde::Schema::object
QJsonObject object(const QJsonObject &properties, const QStringList &required={ })
The schema of a tool's arguments: an object with properties, of which required must be given.
Definition
schema.h:103
Sonde::Schema::described
QJsonObject described(QJsonObject schema, const QString &description)
schema with "description" set to description, unless that is empty: a description that says nothing (...
Definition
schema.h:62
Sonde
Embeddable Model Context Protocol server for Qt applications.
Definition
dispatch.cpp:10
Sonde::JsonType
JsonType
The JSON Schema types a property may have.
Definition
schema.h:25
Sonde::JsonType::String
@ String
"string"
Definition
schema.h:26
Sonde::JsonType::Boolean
@ Boolean
"boolean"
Definition
schema.h:29
Sonde::JsonType::Array
@ Array
"array"
Definition
schema.h:30
Sonde::JsonType::Object
@ Object
"object"
Definition
schema.h:31
Sonde::JsonType::Integer
@ Integer
"integer"
Definition
schema.h:27
Sonde::JsonType::Number
@ Number
"number"
Definition
schema.h:28
Sonde::jsonTypeName
QString jsonTypeName(JsonType type)
The JSON Schema name of type, such as "string".
Definition
schema.h:35
src
core
sonde
schema.h
Generated by
1.18.0