Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a2efb06

Browse files
authored
fix: prefer hydra title when available (#144)
1 parent 3000d61 commit a2efb06

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

‎src/hydra/parseHydraDocumentation.ts‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
ExpandedClass,
1414
ExpandedDoc,
1515
Entrypoint,
16+
ExpandedOperation,
1617
ExpandedRdfProperty,
1718
RequestInitExtended,
1819
} from "./types.js";
@@ -24,6 +25,19 @@ function guessNameFromUrl(url: string, entrypointUrl: string): string {
2425
return url.substr(entrypointUrl.length + 1);
2526
}
2627

28+
function getTitleOrLabel(obj: ExpandedOperation): string {
29+
const a =
30+
obj["http://www.w3.org/2000/01/rdf-schema#label"] ??
31+
obj["http://www.w3.org/ns/hydra/core#title"] ??
32+
null;
33+
34+
if (a === null) {
35+
throw new Error("No title nor label defined on this operation.");
36+
}
37+
38+
return a[0]["@value"];
39+
}
40+
2741
/**
2842
* Finds the description of the class with the given id.
2943
*/
@@ -279,9 +293,12 @@ export default function parseHydraDocumentation(
279293
) as unknown as string;
280294

281295
const field = new Field(
282-
supportedProperty["http://www.w3.org/2000/01/rdf-schema#label"][0][
296+
supportedProperties["http://www.w3.org/ns/hydra/core#title"][0][
283297
"@value"
284-
],
298+
] ??
299+
supportedProperty[
300+
"http://www.w3.org/2000/01/rdf-schema#label"
301+
][0]["@value"],
285302
{
286303
id,
287304
range,
@@ -369,9 +386,7 @@ export default function parseHydraDocumentation(
369386
type = "create";
370387
}
371388
const operation = new Operation(
372-
entrypointOperation[
373-
"http://www.w3.org/2000/01/rdf-schema#label"
374-
][0]["@value"],
389+
getTitleOrLabel(entrypointOperation),
375390
type,
376391
{
377392
method,
@@ -424,9 +439,7 @@ export default function parseHydraDocumentation(
424439
type = "delete";
425440
}
426441
const operation = new Operation(
427-
supportedOperation["http://www.w3.org/2000/01/rdf-schema#label"][0][
428-
"@value"
429-
],
442+
getTitleOrLabel(supportedOperation),
430443
type,
431444
{
432445
method,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /