Skip to content

Commit 8652f9b

Browse files
J3m5JH
and
JH
authored
Hydra: Skip resource property without GET collection operation instead of throwing (#134)
* refactor(parseHydraDocumentation): skip ressource property without GET collection operation * chore(config): add yarn.lock, adjust .gitignore, fix tsconfig.eslint.json, formatting --------- Co-authored-by: JH <[email protected]>
1 parent f9d53bf commit 8652f9b

File tree

6 files changed

+3986
-24
lines changed

6 files changed

+3986
-24
lines changed

.eslintrc.cjs

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ module.exports = {
66
commonjs: true,
77
es6: true,
88
jest: true,
9-
node: true
9+
node: true,
1010
},
1111
parser: "@typescript-eslint/parser",
1212
parserOptions: {
1313
ecmaVersion: 7,
1414
sourceType: "module",
15-
project: ["./tsconfig.eslint.json"]
15+
project: ["./tsconfig.eslint.json"],
1616
},
1717
plugins: ["@typescript-eslint"],
1818

@@ -23,15 +23,15 @@ module.exports = {
2323
"plugin:import/recommended",
2424
"plugin:import/typescript",
2525
"prettier",
26-
"plugin:prettier/recommended"
26+
"plugin:prettier/recommended",
2727
],
2828

2929
rules: {
3030
"prettier/prettier": "error",
3131
"@typescript-eslint/consistent-type-imports": "error",
3232
"@typescript-eslint/no-empty-interface": [
3333
"error",
34-
{ allowSingleExtends: true }
34+
{ allowSingleExtends: true },
3535
],
3636
"@typescript-eslint/no-use-before-define": ["error", { functions: false }],
3737
"@typescript-eslint/no-explicit-any": [0],
@@ -43,7 +43,7 @@ module.exports = {
4343
settings: {
4444
"import/resolver": {
4545
typescript: true,
46-
node: true
47-
}
48-
}
46+
node: true,
47+
},
48+
},
4949
};

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
/lib/
22
/node_modules/
3-
/yarn.lock
43
/yarn-error.log

jest.config.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import type { Config } from '@jest/types';
1+
import type { Config } from "@jest/types";
22

33
const config: Config.InitialOptions = {
4-
extensionsToTreatAsEsm: ['.ts'],
5-
setupFilesAfterEnv: ['./jest.setup.ts'],
4+
extensionsToTreatAsEsm: [".ts"],
5+
setupFilesAfterEnv: ["./jest.setup.ts"],
66
moduleNameMapper: {
7-
'^(\\.{1,2}/.*)\\.js$': '$1',
7+
"^(\\.{1,2}/.*)\\.js$": "$1",
88
},
99
transform: {
10-
'^.+\\.ts$': [
11-
'ts-jest',
10+
"^.+\\.ts$": [
11+
"ts-jest",
1212
{
13-
useESM: true
13+
useESM: true,
1414
},
1515
],
1616
},

src/hydra/parseHydraDocumentation.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,24 @@ export default function parseHydraDocumentation(
244244
properties,
245245
'["http://www.w3.org/ns/hydra/core#property"][0]'
246246
) as ExpandedRdfProperty | undefined;
247+
247248
if (!property) {
248249
continue;
249250
}
250251

252+
const url = get(entrypoint, `[0]["${property["@id"]}"][0]["@id"]`) as
253+
| string
254+
| undefined;
255+
256+
if (!url) {
257+
console.error(
258+
new Error(
259+
`Unable to find the URL for "${property["@id"]}" in the entrypoint, make sure your API resource has at least one GET collection operation declared.`
260+
)
261+
);
262+
continue;
263+
}
264+
251265
// Add fields
252266
const relatedClass = findRelatedClass(docs, property);
253267
for (const supportedProperties of relatedClass[
@@ -435,15 +449,6 @@ export default function parseHydraDocumentation(
435449
operations.push(operation);
436450
}
437451

438-
const url = get(entrypoint, `[0]["${property["@id"]}"][0]["@id"]`) as
439-
| string
440-
| undefined;
441-
if (!url) {
442-
throw new Error(
443-
`Unable to find the URL for "${property["@id"]}" in the entrypoint, make sure your API resource has at least one GET collection operation declared.`
444-
);
445-
}
446-
447452
const resource = new Resource(
448453
guessNameFromUrl(url, entrypointUrl),
449454
url,

tsconfig.eslint.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"extends": "./tsconfig.json",
3+
"include": ["jest.config.ts", ".eslintrc.cjs", "./src"],
34
"exclude": []
45
}

0 commit comments

Comments
 (0)