Skip to content
Merged
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
29 changes: 21 additions & 8 deletions src/hydra/parseHydraDocumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
ExpandedClass,
ExpandedDoc,
Entrypoint,
ExpandedOperation,
ExpandedRdfProperty,
RequestInitExtended,
} from "./types.js";
Expand All @@ -24,6 +25,19 @@ function guessNameFromUrl(url: string, entrypointUrl: string): string {
return url.substr(entrypointUrl.length + 1);
}

function getTitleOrLabel(obj: ExpandedOperation): string {
const a =
obj["http://www.w3.org/2000/01/rdf-schema#label"] ??
obj["http://www.w3.org/ns/hydra/core#title"] ??
null;

if (a === null) {
throw new Error("No title nor label defined on this operation.");
}

return a[0]["@value"];
}

/**
* Finds the description of the class with the given id.
*/
Expand Down Expand Up @@ -279,9 +293,12 @@ export default function parseHydraDocumentation(
) as unknown as string;

const field = new Field(
supportedProperty["http://www.w3.org/2000/01/rdf-schema#label"][0][
supportedProperties["http://www.w3.org/ns/hydra/core#title"][0][
"@value"
],
] ??
supportedProperty[
"http://www.w3.org/2000/01/rdf-schema#label"
][0]["@value"],
{
id,
range,
Expand Down Expand Up @@ -369,9 +386,7 @@ export default function parseHydraDocumentation(
type = "create";
}
const operation = new Operation(
entrypointOperation[
"http://www.w3.org/2000/01/rdf-schema#label"
][0]["@value"],
getTitleOrLabel(entrypointOperation),
type,
{
method,
Expand Down Expand Up @@ -424,9 +439,7 @@ export default function parseHydraDocumentation(
type = "delete";
}
const operation = new Operation(
supportedOperation["http://www.w3.org/2000/01/rdf-schema#label"][0][
"@value"
],
getTitleOrLabel(supportedOperation),
type,
{
method,
Expand Down