Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions collections/self/v1/schemas/api/list/response.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"examples": [
{
"health": 100,
"schemas": 42,
"entries": [],
"path": "/schemas",
"url": "https://example.com/schemas",
Expand All @@ -17,7 +18,7 @@
}
],
"type": "object",
"required": [ "health", "entries", "path", "url", "breadcrumb" ],
"required": [ "health", "schemas", "entries", "path", "url", "breadcrumb" ],
"properties": {
"title": {
"type": "string"
Expand Down Expand Up @@ -50,7 +51,7 @@
"anyOf": [
{
"type": "object",
"required": [ "health", "name", "type", "path" ],
"required": [ "health", "schemas", "name", "type", "path" ],
"properties": {
"title": {
"type": "string"
Expand All @@ -72,6 +73,10 @@
"maximum": 100,
"minimum": 0
},
"schemas": {
"type": "integer",
"minimum": 0
},
"name": {
"type": "string"
},
Expand Down Expand Up @@ -108,6 +113,10 @@
"maximum": 100,
"minimum": 0
},
"schemas": {
"type": "integer",
"minimum": 0
},
"path": {
"$ref": "https://schemas.sourcemeta.com/sourcemeta/std/v0/ietf/uri/uri-relative"
},
Expand Down
2 changes: 2 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ navigation and discovery purposes.
| `/email` | String | No | The e-mail address associated with the directory |
| `/github` | String | No | The GitHub organisation or repository associated with the directory |
| `/website` | String | No | The external URL associated with the directory |
| `/schemas` | Integer | Yes | The recursive count of schemas in this directory |
| `/entries` | Array | Yes | The entries inside the directory |
| `/entries/*/type` | String | Yes | The type of the entry (`schema` or `directory`) |
| `/entries/*/name` | String | Yes | The last URL path segment of the entry |
| `/entries/*/path` | String | Yes | The relative URL of the entry |
| `/entries/*/health` | Integer | No | The aggregated health of the entry |
| `/entries/*/schemas` | Integer | No | For `directory` entries, the recursive count of schemas in the directory |
| `/entries/*/title` | String | No | The title associated with the entry |
| `/entries/*/description` | String | No | The description associated with the entry |
| `/entries/*/email` | String | No | For `directory` entries, the e-mail address associated with the entry |
Expand Down
3 changes: 3 additions & 0 deletions enterprise/e2e/html/hurl/list.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ header "Last-Modified" exists
jsonpath "$.path" == "/"
jsonpath "$.url" == "{{base}}"
jsonpath "$.breadcrumb" count == 0
jsonpath "$.schemas" == 32
jsonpath "$.entries" count == 2
jsonpath "$.entries[0].name" == "self"
jsonpath "$.entries[0].type" == "directory"
jsonpath "$.entries[0].health" == 100
jsonpath "$.entries[0].schemas" == 31
jsonpath "$.entries[0].path" == "/self/"
jsonpath "$.entries[1].name" == "test"
jsonpath "$.entries[1].type" == "directory"
jsonpath "$.entries[1].health" == 67
jsonpath "$.entries[1].schemas" == 1
jsonpath "$.entries[1].path" == "/test/"

POST {{base}}/self/v1/api/schemas/evaluate{{schema_path}}
Expand Down
31 changes: 26 additions & 5 deletions src/index/explorer.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct MetapackExplorerSchemaExtension {
struct MetapackDirectoryExtension {
MetapackVersionInfo version;
std::int64_t health;
std::int64_t schemas;
std::uint16_t path_length;
std::uint16_t title_length;
std::uint16_t description_length;
Expand Down Expand Up @@ -157,10 +158,10 @@ inline auto directory_extension_string(const MetapackDirectoryExtension *,

static auto make_directory_extension(
const MetapackVersionInfo &version, const std::int64_t health,
const std::string_view path, const std::string_view title,
const std::string_view description, const std::string_view email,
const std::string_view github, const std::string_view website)
-> std::vector<std::uint8_t> {
const std::int64_t schemas, const std::string_view path,
const std::string_view title, const std::string_view description,
const std::string_view email, const std::string_view github,
const std::string_view website) -> std::vector<std::uint8_t> {
assert(path.size() <= std::numeric_limits<std::uint16_t>::max());
assert(title.size() <= std::numeric_limits<std::uint16_t>::max());
assert(description.size() <= std::numeric_limits<std::uint16_t>::max());
Expand All @@ -176,6 +177,7 @@ static auto make_directory_extension(
MetapackDirectoryExtension header{};
header.version = version;
header.health = health;
header.schemas = schemas;
header.path_length = static_cast<std::uint16_t>(path.size());
header.title_length = static_cast<std::uint16_t>(title.size());
header.description_length = static_cast<std::uint16_t>(description.size());
Expand Down Expand Up @@ -573,6 +575,7 @@ struct GENERATE_EXPLORER_DIRECTORY_LIST {
const auto timestamp_start{std::chrono::steady_clock::now()};
auto entries{sourcemeta::core::JSON::make_array()};
std::vector<sourcemeta::core::JSON::Integer> scores;
std::int64_t child_schemas_total{0};

const auto directory_path{action.destination.parent_path().parent_path()};
std::filesystem::path relative_path;
Expand Down Expand Up @@ -630,6 +633,10 @@ struct GENERATE_EXPLORER_DIRECTORY_LIST {
if (old_entry.defines("health")) {
scores.emplace_back(old_entry.at("health").to_integer());
}
if (old_entry.defines("schemas")) {
assert(old_entry.at("schemas").is_positive());
child_schemas_total += old_entry.at("schemas").to_integer();
}
directory_entries.push_back(
{old_entry, parse_version_info(child_name), child_name});
continue;
Expand All @@ -656,6 +663,10 @@ struct GENERATE_EXPLORER_DIRECTORY_LIST {
entry_json.assign(
"health", sourcemeta::core::JSON{directory_extension->health});
scores.emplace_back(directory_extension->health);
assert(directory_extension->schemas >= 0);
entry_json.assign(
"schemas", sourcemeta::core::JSON{directory_extension->schemas});
child_schemas_total += directory_extension->schemas;

const auto directory_path_string{
directory_extension_string(directory_extension, directory_base, 0,
Expand Down Expand Up @@ -725,6 +736,11 @@ struct GENERATE_EXPLORER_DIRECTORY_LIST {
scores.emplace_back(directory_json.at("health").to_integer());

entry_json.assign("health", directory_json.at("health"));
assert(directory_json.defines("schemas"));
assert(directory_json.at("schemas").is_integer());
assert(directory_json.at("schemas").is_positive());
entry_json.assign("schemas", directory_json.at("schemas"));
child_schemas_total += directory_json.at("schemas").to_integer();
assert(directory_json.defines("path"));
entry_json.assign("path",
sourcemeta::core::JSON{
Expand Down Expand Up @@ -880,6 +896,11 @@ struct GENERATE_EXPLORER_DIRECTORY_LIST {
meta.assign("health", sourcemeta::core::JSON{0});
}

const auto total_schemas{static_cast<std::int64_t>(schema_entries.size()) +
child_schemas_total};
assert(total_schemas >= 0);
meta.assign("schemas", sourcemeta::core::JSON{total_schemas});

meta.assign("entries", std::move(entries));

if (relative_path == ".") {
Expand All @@ -898,7 +919,7 @@ struct GENERATE_EXPLORER_DIRECTORY_LIST {
action.destination.parent_path().parent_path().filename().string()};
const auto directory_extension_bytes{make_directory_extension(
parse_version_info(directory_name), meta.at("health").to_integer(),
meta.at("path").to_string(),
meta.at("schemas").to_integer(), meta.at("path").to_string(),
meta.defines("title") ? meta.at("title").to_string() : "",
meta.defines("description") ? meta.at("description").to_string() : "",
meta.defines("email") ? meta.at("email").to_string() : "",
Expand Down
10 changes: 10 additions & 0 deletions src/web/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ inline auto make_file_manager_row(sourcemeta::core::HTMLWriter &writer,
entry.defines("description") ? entry.at("description").to_string() : "-");
writer.close();

// Schemas column
writer.td();
writer.small(entry.defines("schemas")
? std::to_string(entry.at("schemas").to_integer())
: "-");
writer.close();

// Dependencies column
writer.td();
writer.small(entry.defines("dependencies")
Expand Down Expand Up @@ -287,6 +294,9 @@ inline auto make_file_manager_table_header(sourcemeta::core::HTMLWriter &writer)
writer.text("Description");
writer.close();
writer.th().attribute("scope", "col");
writer.text("Schemas");
writer.close();
writer.th().attribute("scope", "col");
writer.text("Dependencies");
writer.close();
writer.th().attribute("scope", "col").attribute("style", "width: 150px");
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/headless/hurl/list.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ header "Last-Modified" exists
jsonpath "$.path" == "/"
jsonpath "$.url" == "{{base}}"
jsonpath "$.breadcrumb" count == 0
jsonpath "$.schemas" == 45
jsonpath "$.entries" count >= 2
jsonpath "$.entries[0].name" == "self"
jsonpath "$.entries[0].title" == "Self"
jsonpath "$.entries[0].description" == "The schemas that define the current version of this instance"
jsonpath "$.entries[0].type" == "directory"
jsonpath "$.entries[0].health" == 100
jsonpath "$.entries[0].schemas" == 31
jsonpath "$.entries[0].path" == "/self/"
jsonpath "$.entries[1].name" == "test"
jsonpath "$.entries[1].title" == "Test"
jsonpath "$.entries[1].description" == "A directory full of testing schemas"
jsonpath "$.entries[1].type" == "directory"
jsonpath "$.entries[1].schemas" == 14
jsonpath "$.entries[1].path" == "/test/"

POST {{base}}/self/v1/api/schemas/evaluate{{schema_path}}
Expand Down Expand Up @@ -52,6 +55,7 @@ jsonpath "$.breadcrumb[0].name" == "test"
jsonpath "$.breadcrumb[0].path" == "/test/"
jsonpath "$.description" == "A directory full of testing schemas"
jsonpath "$.title" == "Test"
jsonpath "$.schemas" == 14
jsonpath "$.entries" count == 3

POST {{base}}/self/v1/api/schemas/evaluate{{schema_path}}
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/html/hurl/list.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ header "Last-Modified" exists
jsonpath "$.path" == "/"
jsonpath "$.url" == "{{base}}"
jsonpath "$.breadcrumb" count == 0
jsonpath "$.schemas" == 71
jsonpath "$.entries" count >= 2
jsonpath "$.entries[0].name" == "self"
jsonpath "$.entries[0].title" == "Self"
jsonpath "$.entries[0].description" == "The schemas that define the current version of this instance"
jsonpath "$.entries[0].type" == "directory"
jsonpath "$.entries[0].health" == 100
jsonpath "$.entries[0].schemas" == 31
jsonpath "$.entries[0].path" == "/self/"
jsonpath "$.entries[1].name" == "test"
jsonpath "$.entries[1].title" == "Test"
jsonpath "$.entries[1].description" == "A directory full of testing schemas"
jsonpath "$.entries[1].type" == "directory"
jsonpath "$.entries[1].health" == 14
jsonpath "$.entries[1].schemas" == 40
jsonpath "$.entries[1].path" == "/test/"

POST {{base}}/self/v1/api/schemas/evaluate{{schema_path}}
Expand Down Expand Up @@ -53,49 +56,60 @@ jsonpath "$.breadcrumb[0].name" == "test"
jsonpath "$.breadcrumb[0].path" == "/test/"
jsonpath "$.description" == "A directory full of testing schemas"
jsonpath "$.title" == "Test"
jsonpath "$.schemas" == 40
jsonpath "$.entries" count == 10
jsonpath "$.entries[0].name" == "v2.0"
jsonpath "$.entries[0].type" == "directory"
jsonpath "$.entries[0].health" == 0
jsonpath "$.entries[0].schemas" == 1
jsonpath "$.entries[0].path" == "/test/v2.0/"
jsonpath "$.entries[1].name" == "bundling"
jsonpath "$.entries[1].type" == "directory"
jsonpath "$.entries[1].health" == 59
jsonpath "$.entries[1].schemas" == 2
jsonpath "$.entries[1].path" == "/test/bundling/"
jsonpath "$.entries[2].name" == "camelcase"
jsonpath "$.entries[2].type" == "directory"
jsonpath "$.entries[2].health" == 25
jsonpath "$.entries[2].schemas" == 2
jsonpath "$.entries[2].path" == "/test/camelcase/"
jsonpath "$.entries[3].name" == "doc"
jsonpath "$.entries[3].type" == "directory"
jsonpath "$.entries[3].health" == 0
jsonpath "$.entries[3].schemas" == 2
jsonpath "$.entries[3].path" == "/test/doc/"
jsonpath "$.entries[3].title" == "A sample schema folder"
jsonpath "$.entries[3].description" == "For testing purposes"
jsonpath "$.entries[3].github" == "sourcemeta/one"
jsonpath "$.entries[4].name" == "extension"
jsonpath "$.entries[4].type" == "directory"
jsonpath "$.entries[4].health" == 17
jsonpath "$.entries[4].schemas" == 3
jsonpath "$.entries[4].path" == "/test/extension/"
jsonpath "$.entries[5].name" == "hyper"
jsonpath "$.entries[5].type" == "directory"
jsonpath "$.entries[5].health" == 34
jsonpath "$.entries[5].schemas" == 1
jsonpath "$.entries[5].path" == "/test/hyper/"
jsonpath "$.entries[6].name" == "no-base"
jsonpath "$.entries[6].type" == "directory"
jsonpath "$.entries[6].health" == 0
jsonpath "$.entries[6].schemas" == 2
jsonpath "$.entries[6].path" == "/test/no-base/"
jsonpath "$.entries[7].name" == "no-blaze"
jsonpath "$.entries[7].type" == "directory"
jsonpath "$.entries[7].health" == 0
jsonpath "$.entries[7].schemas" == 1
jsonpath "$.entries[7].path" == "/test/no-blaze/"
jsonpath "$.entries[8].name" == "same"
jsonpath "$.entries[8].type" == "directory"
jsonpath "$.entries[8].health" == 0
jsonpath "$.entries[8].schemas" == 1
jsonpath "$.entries[8].path" == "/test/same/"
jsonpath "$.entries[9].name" == "schemas"
jsonpath "$.entries[9].type" == "directory"
jsonpath "$.entries[9].health" == 7
jsonpath "$.entries[9].schemas" == 25
jsonpath "$.entries[9].path" == "/test/schemas/"

POST {{base}}/self/v1/api/schemas/evaluate{{schema_path}}
Expand All @@ -120,6 +134,7 @@ header "ETag" exists
header "Last-Modified" exists
jsonpath "$.path" == "/test/v2.0"
jsonpath "$.url" == "{{base}}/test/v2.0"
jsonpath "$.schemas" == 1
jsonpath "$.breadcrumb" count == 2
jsonpath "$.breadcrumb[0].name" == "test"
jsonpath "$.breadcrumb[0].path" == "/test/"
Expand Down Expand Up @@ -183,6 +198,7 @@ header "Last-Modified" exists
jsonpath "$.path" == "/test/schemas/versions"
jsonpath "$.url" == "{{base}}/test/schemas/versions"
jsonpath "$.health" == 0
jsonpath "$.schemas" == 1
jsonpath "$.breadcrumb" count == 3
jsonpath "$.breadcrumb[0].name" == "test"
jsonpath "$.breadcrumb[0].path" == "/test/"
Expand Down Expand Up @@ -226,6 +242,7 @@ header "Last-Modified" exists
jsonpath "$.path" == "/test/schemas/clash/foo"
jsonpath "$.url" == "{{base}}/test/schemas/clash/foo"
jsonpath "$.health" == 0
jsonpath "$.schemas" == 1
jsonpath "$.breadcrumb" count == 4
jsonpath "$.breadcrumb[0].name" == "test"
jsonpath "$.breadcrumb[0].path" == "/test/"
Expand Down Expand Up @@ -271,6 +288,7 @@ header "Last-Modified" exists
jsonpath "$.path" == "/test/schemas/clash"
jsonpath "$.url" == "{{base}}/test/schemas/clash"
jsonpath "$.health" == 0
jsonpath "$.schemas" == 2
jsonpath "$.breadcrumb" count == 3
jsonpath "$.breadcrumb[0].name" == "test"
jsonpath "$.breadcrumb[0].path" == "/test/"
Expand All @@ -282,6 +300,7 @@ jsonpath "$.entries" count == 2
jsonpath "$.entries[0].name" == "foo"
jsonpath "$.entries[0].type" == "directory"
jsonpath "$.entries[0].health" == 0
jsonpath "$.entries[0].schemas" == 1
jsonpath "$.entries[0].path" == "/test/schemas/clash/foo/"
jsonpath "$.entries[1].name" == "foo"
jsonpath "$.entries[1].type" == "schema"
Expand Down Expand Up @@ -318,6 +337,7 @@ header "Last-Modified" exists
jsonpath "$.path" == "/test/extension"
jsonpath "$.url" == "{{base}}/test/extension"
jsonpath "$.health" == 17
jsonpath "$.schemas" == 3
jsonpath "$.breadcrumb" count == 2
jsonpath "$.breadcrumb[0].name" == "test"
jsonpath "$.breadcrumb[0].path" == "/test/"
Expand Down
Loading