Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Produce OpenAPI document describing CCF's endpoints #1612

Merged
merged 64 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
6f7df55
Add to_upper and to_lower to nonstd.h
eddyashton Jun 24, 2020
af0ef44
Use nonstd::to_lower
eddyashton Jun 24, 2020
78e5e78
WIP: Add types for OpenAPI doc
eddyashton Jun 24, 2020
94d3779
Merge branch 'master' of github.com:microsoft/CCF into openapi_genera…
eddyashton Jun 25, 2020
2f1a965
WIP: "api" returns openapi, not method list
eddyashton Jun 25, 2020
1510aaf
Prefer openapi to openapi_schema
eddyashton Jun 25, 2020
fb3466a
WIP: Maybe a deadend...
eddyashton Jun 25, 2020
ed846b7
WIP: 3 cheers for operator[]
eddyashton Jun 25, 2020
32b9d46
Is this what a helpful modifier looks like?
eddyashton Jun 25, 2020
325a59c
WIP: Helper method for adding response schema
eddyashton Jun 25, 2020
8ad27d2
Add schema_name to generate sensible components fieldname
eddyashton Jun 26, 2020
bd1eb15
WIP
eddyashton Jun 26, 2020
0ef2951
WIP: add_request_body_schema
eddyashton Jun 26, 2020
964f863
WIP: Forgive me father for I have sinned
eddyashton Jun 29, 2020
b508e87
WIP: Support optional fields
eddyashton Jun 29, 2020
89340ce
Fix for optional fields
eddyashton Jun 29, 2020
da7039e
WIP: Add support for renames
eddyashton Jun 29, 2020
016c7df
WIP: Fix duplicate-required and missing-base-elements
eddyashton Jun 29, 2020
7a8ebd3
Support for vectors, fancy types
eddyashton Jun 30, 2020
1b9fc33
Remove some fixed TODOs
eddyashton Jun 30, 2020
e92bb37
Separate simple and complex test cases
eddyashton Jun 30, 2020
593005d
Steps towards pure JSON doc
eddyashton Jun 30, 2020
a01d2c5
Partial compile fixes
eddyashton Sep 9, 2020
d4b3a6e
Merge branch 'master' of github.com:microsoft/CCF into openapi_genera…
eddyashton Sep 9, 2020
b7e75ea
Get to compilation
eddyashton Sep 9, 2020
55a4f73
Update schema.py to just validate that the result is a valid OpenAPI doc
eddyashton Sep 9, 2020
9c6adcc
Remove separate schema. Oh no
eddyashton Sep 9, 2020
8f736e3
Progress: schema_test dumps OpenAPI docs to file, initial files
eddyashton Sep 10, 2020
0296f09
Produce schema that the online validator is happy with
eddyashton Sep 10, 2020
1b24113
Drop an element the spec validator isn't happy with
eddyashton Sep 10, 2020
55d9402
Use freeform JSON manipulators everywhere, fix nested add_to_components
eddyashton Sep 10, 2020
d439221
Schema.py should continue to retrieve individual schema
eddyashton Sep 11, 2020
39de645
And here's those schemas again
eddyashton Sep 11, 2020
7314eb2
Strip out some uninteresting TODOs
eddyashton Sep 11, 2020
afc0999
Add schema for templated endpoints too
eddyashton Sep 11, 2020
45dc53d
WIO
eddyashton Sep 11, 2020
f74258d
Compile fixes
eddyashton Sep 14, 2020
669c1f6
Safe capture
eddyashton Sep 15, 2020
a4dcb9d
Prefix OpenAPI paths
eddyashton Sep 15, 2020
2ee7336
Get things in-sync
eddyashton Sep 15, 2020
6cdeab9
Progress
eddyashton Sep 15, 2020
ddf38bd
Split out params on all endpoints
eddyashton Sep 15, 2020
0970c09
Merge branch 'master' of github.com:microsoft/CCF into openapi_genera…
eddyashton Sep 15, 2020
ff405dd
Merge branch 'master' of github.com:microsoft/CCF into openapi_genera…
eddyashton Sep 15, 2020
57c214a
Format
eddyashton Sep 15, 2020
0701c77
Merge branch 'master' of github.com:microsoft/CCF into openapi_genera…
eddyashton Sep 16, 2020
c28ace5
Delete
eddyashton Sep 16, 2020
7596241
Oops - these lines restore result schema
eddyashton Sep 16, 2020
8d5a1b8
Add restored result schema
eddyashton Sep 16, 2020
78905b5
Document (minimum) JS endpoints
eddyashton Sep 17, 2020
08fe5a6
Hey we can do that in lua too
eddyashton Sep 17, 2020
890c9d7
Shout about TODOs again
eddyashton Sep 17, 2020
89d4d73
Merge branch 'master' of github.com:microsoft/CCF into openapi_genera…
eddyashton Sep 17, 2020
86889e8
Merge branch 'master' of github.com:microsoft/CCF into openapi_genera…
eddyashton Sep 21, 2020
c31c300
Fixups
eddyashton Sep 21, 2020
90c0c08
Merge branch 'master' of github.com:microsoft/CCF into openapi_genera…
eddyashton Sep 22, 2020
2132beb
Merge branch 'openapi_generation2' of github.com:eddyashton/CCF into …
eddyashton Sep 22, 2020
7e63db4
Make OpenAPI info customisable
eddyashton Sep 23, 2020
7c9b986
Update supports_method
eddyashton Sep 23, 2020
9241b61
Format
eddyashton Sep 23, 2020
c3353fa
Merge branch 'master' of github.com:microsoft/CCF into openapi_genera…
eddyashton Sep 24, 2020
56cf98b
Use is_arithmetic
eddyashton Sep 24, 2020
54c2c6c
Don't print in test
eddyashton Sep 24, 2020
4142618
Merge branch 'master' into openapi_generation2
eddyashton Sep 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Make OpenAPI info customisable
  • Loading branch information
eddyashton committed Sep 23, 2020
commit 7e63db4f8f1d4de98095454915db7353e6cc4efd
6 changes: 3 additions & 3 deletions doc/schemas/app_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@
}
},
"info": {
"description": "Placeholder description",
"title": "Placeholder title",
"version": "1.0.0"
"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": "0.0.1"
},
"openapi": "3.0.0",
"paths": {
Expand Down
6 changes: 3 additions & 3 deletions doc/schemas/gov_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,9 @@
}
},
"info": {
"description": "Placeholder description",
"title": "Placeholder title",
"version": "1.0.0"
"description": "This API is used to submit and query proposals which affect CCF's public governance tables.",
"title": "CCF Governance API",
"version": "0.0.1"
},
"openapi": "3.0.0",
"paths": {
Expand Down
6 changes: 3 additions & 3 deletions doc/schemas/node_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,9 @@
}
},
"info": {
"description": "Placeholder description",
"title": "Placeholder title",
"version": "1.0.0"
"description": "This API provides public, uncredentialed access to service and node state.",
"title": "CCF Public Node API",
"version": "0.0.1"
},
"openapi": "3.0.0",
"paths": {
Expand Down
6 changes: 6 additions & 0 deletions src/apps/logging/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ namespace loggingapp
get_public_params_schema(nlohmann::json::parse(j_get_public_in)),
get_public_result_schema(nlohmann::json::parse(j_get_public_out))
{
openapi_info.title = "CCF Sample Logging App";
openapi_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.";

// SNIPPET_START: record
auto record = [this](kv::Tx& tx, nlohmann::json&& params) {
// SNIPPET_START: macro_validation_record
Expand Down
8 changes: 4 additions & 4 deletions src/node/rpc/common_endpoint_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,10 @@ namespace ccf
.install();

auto openapi = [this](kv::Tx& tx, nlohmann::json&&) {
// TODO: Update these
auto document = ds::openapi::create_document(
"Placeholder title", "Placeholder description", "1.0.0");
openapi_info.title,
openapi_info.description,
openapi_info.document_version);
build_api(document, tx);
return make_success(document);
};
Expand Down Expand Up @@ -258,8 +259,7 @@ namespace ccf

return make_success(j);
};
make_endpoint(
"api/schema", HTTP_GET, json_adapter(get_schema))
make_endpoint("api/schema", HTTP_GET, json_adapter(get_schema))
.set_auto_schema<GetSchema>()
.install();

Expand Down
9 changes: 7 additions & 2 deletions src/node/rpc/endpoint_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ namespace ccf

const std::string method_prefix;

struct OpenApiInfo
{
std::string title = "Empty title";
std::string description = "Empty description";
std::string document_version = "0.0.1";
} openapi_info;

struct Metrics
{
size_t calls = 0;
Expand Down Expand Up @@ -435,8 +442,6 @@ namespace ccf
return templated;
}

// TODO: Don't re-parse this here, set the parameters explicitly and
// individually
static void add_query_parameters(
nlohmann::json& document,
const std::string& uri,
Expand Down
7 changes: 6 additions & 1 deletion src/node/rpc/member_frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,12 @@ namespace ccf
node(node),
share_manager(share_manager),
tsr(network)
{}
{
openapi_info.title = "CCF Governance API";
openapi_info.description =
"This API is used to submit and query proposals which affect CCF's "
"public governance tables.";
}

void init_handlers(kv::Store& tables_) override
{
Expand Down
7 changes: 6 additions & 1 deletion src/node/rpc/node_frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ namespace ccf
get_actor_prefix(ActorsType::nodes), *network.tables),
network(network),
node(node)
{}
{
openapi_info.title = "CCF Public Node API";
openapi_info.description =
"This API provides public, uncredentialed access to service and node "
"state.";
}

void init_handlers(kv::Store& tables_) override
{
Expand Down
4 changes: 3 additions & 1 deletion src/node/rpc/user_frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ namespace ccf
h,
tables.get<ClientSignatures>(Tables::USER_CLIENT_SIGNATURES)),
users(tables.get<Users>(Tables::USERS))
{}
{
h.openapi_info.title = "CCF Application API";
}

void open() override
{
Expand Down