@dropsh/plugin-jsonapi-schema 0.5.7 → 0.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,24 +34,36 @@ export async function fetchJsonapiSchema(deps) {
34
34
  return JSON.parse(res.body);
35
35
  }
36
36
  const ABSOLUTE_REF = /^https?:\/\//;
37
+ /**
38
+ * Keys whose *values* are maps of user-defined field names, not schema
39
+ * keywords. A key literally named `links` (etc.) living inside one of these is
40
+ * an entity field — e.g. gaia_ticket's `links` base field — and must survive.
41
+ */
42
+ const FIELD_NAME_MAPS = new Set(["properties", "definitions", "patternProperties"]);
37
43
  /**
38
44
  * Strip hyper-schema noise that Ajv either ignores or cannot compile:
39
45
  * `links` (JSON hyper-schema; carries absolute `$ref`s to related routes),
40
46
  * document identity keywords (`$schema`, `$id`), and any leftover absolute
41
47
  * `$ref` (neutralised to an always-true `{}` so compilation never fails).
48
+ *
49
+ * The strip is context-aware: `links`/`$schema`/`$id` are only removed at
50
+ * schema-keyword positions, never as keys inside a `properties` /
51
+ * `definitions` / `patternProperties` map (those keys are user field names).
52
+ * Without this, an entity field literally named `links` would be dropped and
53
+ * then rejected by the sibling `additionalProperties: false` — see GAIA-184.
42
54
  */
43
- function sanitize(node) {
55
+ function sanitize(node, inFieldNameMap = false) {
44
56
  if (Array.isArray(node))
45
- return node.map(sanitize);
57
+ return node.map((n) => sanitize(n, false));
46
58
  if (node === null || typeof node !== "object")
47
59
  return node;
48
60
  if (typeof node.$ref === "string" && ABSOLUTE_REF.test(node.$ref))
49
61
  return {};
50
62
  const out = {};
51
63
  for (const [key, value] of Object.entries(node)) {
52
- if (key === "links" || key === "$schema" || key === "$id")
64
+ if (!inFieldNameMap && (key === "links" || key === "$schema" || key === "$id"))
53
65
  continue;
54
- out[key] = sanitize(value);
66
+ out[key] = sanitize(value, FIELD_NAME_MAPS.has(key));
55
67
  }
56
68
  return out;
57
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dropsh/plugin-jsonapi-schema",
3
- "version": "0.5.7",
3
+ "version": "0.5.8",
4
4
  "type": "module",
5
5
  "main": "./dist/plugins/jsonapi-schema/src/index.js",
6
6
  "types": "./dist/plugins/jsonapi-schema/src/index.d.ts",
@@ -21,9 +21,10 @@
21
21
  "dropsh": "*"
22
22
  },
23
23
  "devDependencies": {
24
+ "ajv": "^8.18.0",
24
25
  "typescript": "^5.6.0",
25
26
  "vitest": "^4.1.8",
26
- "dropsh": "0.5.7"
27
+ "dropsh": "0.5.8"
27
28
  },
28
29
  "scripts": {
29
30
  "build": "tsc",