Add error schema to openapi definition (#4223)

This commit is contained in:
Mahati Chamarthy 2022-09-29 09:45:59 +01:00 коммит произвёл GitHub
Родитель 7eec79f41a
Коммит 22b7574685
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 365 добавлений и 6 удалений

Просмотреть файл

@ -1,6 +1,36 @@
{
"components": {
"responses": {
"default": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CCFError"
}
}
},
"description": "An error occurred"
}
},
"schemas": {
"CCFError": {
"properties": {
"error": {
"properties": {
"code": {
"description": "Response error code. CCF error codes: https://microsoft.github.io/CCF/main/operations/troubleshooting.html#error-codes",
"type": "string"
},
"message": {
"description": "Response error message",
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"CodeStatus": {
"enum": [
"AllowedToJoin"
@ -268,7 +298,7 @@
"info": {
"description": "This CCF sample app implements a simple logging application, securely recording messages at client-specified IDs. It demonstrates most of the features available to CCF apps.",
"title": "CCF Sample Logging App",
"version": "1.10.2"
"version": "1.11.5"
},
"openapi": "3.0.0",
"paths": {
@ -284,6 +314,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -303,6 +336,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -322,6 +358,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -341,6 +380,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -360,6 +402,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -389,6 +434,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -418,6 +466,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -450,6 +501,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -482,6 +536,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -516,6 +573,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -540,6 +600,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -574,6 +637,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -593,6 +659,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -627,6 +696,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -669,6 +741,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -703,6 +778,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -737,6 +815,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -764,6 +845,9 @@
"responses": {
"200": {
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -798,6 +882,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -830,6 +917,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -862,6 +952,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -886,6 +979,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -910,6 +1006,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -960,6 +1059,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -994,6 +1096,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -1018,6 +1123,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1037,6 +1145,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -1061,6 +1172,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -1102,6 +1216,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1131,6 +1248,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {

Просмотреть файл

@ -1,5 +1,17 @@
{
"components": {
"responses": {
"default": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CCFError"
}
}
},
"description": "An error occurred"
}
},
"schemas": {
"Action": {
"properties": {
@ -33,6 +45,24 @@
],
"type": "object"
},
"CCFError": {
"properties": {
"error": {
"properties": {
"code": {
"description": "Response error code. CCF error codes: https://microsoft.github.io/CCF/main/operations/troubleshooting.html#error-codes",
"type": "string"
},
"message": {
"description": "Response error message",
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"CodeStatus": {
"enum": [
"AllowedToJoin"
@ -430,7 +460,7 @@
"info": {
"description": "This API is used to submit and query proposals which affect CCF's public governance tables.",
"title": "CCF Governance API",
"version": "2.8.1"
"version": "2.9.5"
},
"openapi": "3.0.0",
"paths": {
@ -449,6 +479,9 @@
"responses": {
"204": {
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -473,6 +506,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -497,6 +533,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -516,6 +555,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -535,6 +577,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -554,6 +599,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -573,6 +621,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -602,6 +653,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -621,6 +675,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -650,6 +707,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -674,6 +734,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -708,6 +771,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -762,6 +828,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -786,6 +855,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -838,6 +910,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -872,6 +947,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -891,6 +969,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -923,6 +1004,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"security": [
@ -957,6 +1041,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {

Просмотреть файл

@ -1,5 +1,17 @@
{
"components": {
"responses": {
"default": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CCFError"
}
}
},
"description": "An error occurred"
}
},
"schemas": {
"ApplicationProtocol": {
"enum": [
@ -17,6 +29,24 @@
],
"type": "string"
},
"CCFError": {
"properties": {
"error": {
"properties": {
"code": {
"description": "Response error code. CCF error codes: https://microsoft.github.io/CCF/main/operations/troubleshooting.html#error-codes",
"type": "string"
},
"message": {
"description": "Response error message",
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"CodeStatus": {
"enum": [
"AllowedToJoin"
@ -845,7 +875,7 @@
"info": {
"description": "This API provides public, uncredentialed access to service and node state.",
"title": "CCF Public Node API",
"version": "2.30.1"
"version": "2.31.5"
},
"openapi": "3.0.0",
"paths": {
@ -861,6 +891,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -880,6 +913,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -899,6 +935,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -918,6 +957,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -937,6 +979,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -956,6 +1001,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -975,6 +1023,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -994,6 +1045,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1023,6 +1077,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1042,6 +1099,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1061,6 +1121,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1080,6 +1143,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1125,6 +1191,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1137,6 +1206,9 @@
"responses": {
"200": {
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1149,6 +1221,9 @@
"responses": {
"200": {
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1168,6 +1243,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1185,6 +1263,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1214,6 +1295,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1226,6 +1310,9 @@
"responses": {
"200": {
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1245,6 +1332,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1264,6 +1354,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1293,6 +1386,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1312,6 +1408,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1331,6 +1430,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1350,6 +1452,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1369,6 +1474,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1398,6 +1506,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {
@ -1417,6 +1528,9 @@
}
},
"description": "Default response description"
},
"default": {
"$ref": "#/components/responses/default"
}
},
"x-ccf-forwarding": {

Просмотреть файл

@ -131,6 +131,15 @@ namespace ds
return response;
}
static inline nlohmann::json& error_response_default(
nlohmann::json& path_operation)
{
auto& all_responses = responses(path_operation);
auto& response = access::get_object(all_responses, "default");
response["$ref"] = "#/components/responses/default";
return response;
}
static inline nlohmann::json& request_body(nlohmann::json& path_operation)
{
auto& request_body = access::get_object(path_operation, "requestBody");

Просмотреть файл

@ -247,7 +247,7 @@ namespace loggingapp
"This CCF sample app implements a simple logging application, securely "
"recording messages at client-specified IDs. It demonstrates most of "
"the features available to CCF apps.";
openapi_info.document_version = "1.10.2";
openapi_info.document_version = "1.11.5";
index_per_public_key = std::make_shared<RecordsIndexingStrategy>(
PUBLIC_RECORDS, context, 10000, 20);

Просмотреть файл

@ -41,6 +41,9 @@ namespace ccf::endpoints
ds::openapi::response(path_op, endpoint->success_status);
}
// Add a default error response
ds::openapi::error_response_default(path_op);
if (!endpoint->authn_policies.empty())
{
for (const auto& auth_policy : endpoint->authn_policies)
@ -247,6 +250,32 @@ namespace ccf::endpoints
"receiving node, potentially breaking session consistency. If this "
"attempts to write on a backup, this will fail.";
// Add ccf OData error response schema
auto& schemas = document["components"]["schemas"];
schemas["CCFError"]["type"] = "object";
schemas["CCFError"]["properties"] = nlohmann::json::object();
schemas["CCFError"]["properties"]["error"] = nlohmann::json::object();
schemas["CCFError"]["properties"]["error"]["type"] = "object";
schemas["CCFError"]["properties"]["error"]["properties"] =
nlohmann::json::object();
auto& error_properties =
schemas["CCFError"]["properties"]["error"]["properties"];
error_properties["code"]["description"] =
"Response error code. CCF error codes: "
"https://microsoft.github.io/CCF/main/operations/"
"troubleshooting.html#error-codes";
error_properties["code"]["type"] = "string";
error_properties["message"]["description"] = "Response error message";
error_properties["message"]["type"] = "string";
// Add a default error response definition
auto& responses = document["components"]["responses"];
auto& default_error = responses["default"];
ds::openapi::schema(
ds::openapi::media_type(default_error, "application/json"))["$ref"] =
"#/components/schemas/CCFError";
default_error["description"] = "An error occurred";
for (const auto& [path, verb_endpoints] : fully_qualified_endpoints)
{
for (const auto& [verb, endpoint] : verb_endpoints)

Просмотреть файл

@ -489,7 +489,7 @@ namespace ccf
openapi_info.description =
"This API is used to submit and query proposals which affect CCF's "
"public governance tables.";
openapi_info.document_version = "2.8.1";
openapi_info.document_version = "2.9.5";
}
static std::optional<MemberId> get_caller_member_id(

Просмотреть файл

@ -367,7 +367,7 @@ namespace ccf
openapi_info.description =
"This API provides public, uncredentialed access to service and node "
"state.";
openapi_info.document_version = "2.30.1";
openapi_info.document_version = "2.31.5";
}
void init_handlers() override