@withgateway/sdk 0.3.1 → 0.4.0
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.
- package/README.md +8 -6
- package/dist/cli.js +4372 -2265
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +4362 -2256
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.d.mts +1 -1
- package/dist/files/index.d.ts +1 -1
- package/dist/files/index.js +259 -58
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +249 -50
- package/dist/files/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +124 -11
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +124 -11
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-C3UzD0G3.d.mts → index-CDPQBsU5.d.mts} +19 -3
- package/dist/{index-C3UzD0G3.d.ts → index-CDPQBsU5.d.ts} +19 -3
- package/dist/{index-CBqbB_0J.d.ts → index-DUHmS74p.d.ts} +1 -1
- package/dist/{index-D-AMnAMa.d.mts → index-mJhG3vZU.d.mts} +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2240 -789
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2150 -739
- package/dist/index.mjs.map +1 -1
- package/dist/{media-CbcAfQvd.d.mts → media-BIApiPzS.d.mts} +21 -2
- package/dist/{media-CbcAfQvd.d.ts → media-BIApiPzS.d.ts} +21 -2
- package/dist/traces/index.d.mts +1 -1
- package/dist/traces/index.d.ts +1 -1
- package/dist/traces/index.js +253 -52
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +243 -44
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +2 -2
- package/dist/tracing/index.d.ts +2 -2
- package/dist/tracing/index.js +75 -13
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +75 -13
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +893 -482
- package/dist/worlds/index.d.ts +893 -482
- package/dist/worlds/index.js +1968 -669
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1960 -662
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/_bundle.py +2 -27
- package/runtime/gatewaysdk/environment/_materialize.py +48 -88
- package/runtime/gatewaysdk/environment/_world.py +155 -237
- package/runtime/gatewaysdk/environment/backing.py +133 -0
- package/runtime/gatewaysdk/environment/core.py +2 -17
- package/runtime/gatewaysdk/environment/legacy_sqlite.py +288 -0
- package/runtime/gatewaysdk/environment/reward_keys.py +25 -0
- package/runtime/gatewaysdk/environment/runtime.py +8 -13
- package/runtime/gatewaysdk/environment/schema/__init__.py +4 -4
- package/runtime/gatewaysdk/environment/schema/admin_routes.py +86 -0
- package/runtime/gatewaysdk/environment/schema/admission.py +174 -0
- package/runtime/gatewaysdk/environment/schema/api.py +347 -892
- package/runtime/gatewaysdk/environment/schema/assertions.py +458 -0
- package/runtime/gatewaysdk/environment/schema/batch.py +44 -39
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +17 -5
- package/runtime/gatewaysdk/environment/schema/cache_layout.py +5 -0
- package/runtime/gatewaysdk/environment/schema/call_capture.py +309 -0
- package/runtime/gatewaysdk/environment/schema/call_log.py +503 -0
- package/runtime/gatewaysdk/environment/schema/call_redaction.py +526 -0
- package/runtime/gatewaysdk/environment/schema/cast.py +15 -35
- package/runtime/gatewaysdk/environment/schema/compiler.py +334 -158
- package/runtime/gatewaysdk/environment/schema/conform.py +14 -39
- package/runtime/gatewaysdk/environment/schema/connector.py +113 -211
- package/runtime/gatewaysdk/environment/schema/connectors/confluence/connector.toml +1 -12
- package/runtime/gatewaysdk/environment/schema/connectors/github/connector.toml +1 -0
- package/runtime/gatewaysdk/environment/schema/connectors/servicenow/connector.toml +2 -5
- package/runtime/gatewaysdk/environment/schema/cors.py +54 -0
- package/runtime/gatewaysdk/environment/schema/credentials.py +313 -8
- package/runtime/gatewaysdk/environment/schema/data.py +60 -216
- package/runtime/gatewaysdk/environment/schema/database/__init__.py +24 -0
- package/runtime/gatewaysdk/environment/schema/database/audit.py +121 -0
- package/runtime/gatewaysdk/environment/schema/database/base.py +936 -0
- package/runtime/gatewaysdk/environment/schema/database/budget.py +33 -0
- package/runtime/gatewaysdk/environment/schema/database/connections.py +101 -0
- package/runtime/gatewaysdk/environment/schema/database/engines.py +8 -0
- package/runtime/gatewaysdk/environment/schema/database/guard.py +215 -0
- package/runtime/gatewaysdk/environment/schema/database/ingest.py +154 -0
- package/runtime/gatewaysdk/environment/schema/database/matching.py +58 -0
- package/runtime/gatewaysdk/environment/schema/database/provenance.py +30 -0
- package/runtime/gatewaysdk/environment/schema/database/reads.py +169 -0
- package/runtime/gatewaysdk/environment/schema/database/rows.py +53 -0
- package/runtime/gatewaysdk/environment/schema/database/runtime_rows.py +39 -0
- package/runtime/gatewaysdk/environment/schema/database/sqlite.py +393 -0
- package/runtime/gatewaysdk/environment/schema/declared_routes.py +210 -0
- package/runtime/gatewaysdk/environment/schema/domain_migration.py +236 -0
- package/runtime/gatewaysdk/environment/schema/door.py +899 -0
- package/runtime/gatewaysdk/environment/schema/envelope.py +227 -0
- package/runtime/gatewaysdk/environment/schema/extract.py +6 -13
- package/runtime/gatewaysdk/environment/schema/grading.py +90 -103
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +163 -12
- package/runtime/gatewaysdk/environment/schema/host.py +237 -1795
- package/runtime/gatewaysdk/environment/schema/host_control.py +144 -0
- package/runtime/gatewaysdk/environment/schema/host_handoff.py +370 -0
- package/runtime/gatewaysdk/environment/schema/host_loops.py +97 -0
- package/runtime/gatewaysdk/environment/schema/host_owners.py +121 -0
- package/runtime/gatewaysdk/environment/schema/host_proxy.py +111 -0
- package/runtime/gatewaysdk/environment/schema/host_requests.py +6 -0
- package/runtime/gatewaysdk/environment/schema/host_session.py +126 -0
- package/runtime/gatewaysdk/environment/schema/host_surfaces.py +79 -21
- package/runtime/gatewaysdk/environment/schema/host_transfers.py +127 -0
- package/runtime/gatewaysdk/environment/schema/host_versions.py +242 -0
- package/runtime/gatewaysdk/environment/schema/host_workers.py +577 -0
- package/runtime/gatewaysdk/environment/schema/journal.py +437 -0
- package/runtime/gatewaysdk/environment/schema/lanes.py +53 -0
- package/runtime/gatewaysdk/environment/schema/ledger_spill.py +828 -0
- package/runtime/gatewaysdk/environment/schema/local.py +58 -170
- package/runtime/gatewaysdk/environment/schema/mapping.py +5 -25
- package/runtime/gatewaysdk/environment/schema/openapi_import.py +112 -73
- package/runtime/gatewaysdk/environment/schema/openapi_paging.py +147 -0
- package/runtime/gatewaysdk/environment/schema/openapi_payloads.py +288 -0
- package/runtime/gatewaysdk/environment/schema/openapi_routes.py +97 -102
- package/runtime/gatewaysdk/environment/schema/openapi_schemas.py +113 -30
- package/runtime/gatewaysdk/environment/schema/platform.py +137 -187
- package/runtime/gatewaysdk/environment/schema/platform_import.py +2 -3
- package/runtime/gatewaysdk/environment/schema/platform_query.py +61 -5
- package/runtime/gatewaysdk/environment/schema/primary_key.py +61 -0
- package/runtime/gatewaysdk/environment/schema/proof.py +19 -12
- package/runtime/gatewaysdk/environment/schema/request_body.py +238 -0
- package/runtime/gatewaysdk/environment/schema/request_ledger.py +958 -0
- package/runtime/gatewaysdk/environment/schema/route_bindings.py +25 -3
- package/runtime/gatewaysdk/environment/schema/route_miss.py +54 -0
- package/runtime/gatewaysdk/environment/schema/runtime.py +178 -308
- package/runtime/gatewaysdk/environment/schema/served_names.py +58 -0
- package/runtime/gatewaysdk/environment/schema/session_files.py +275 -0
- package/runtime/gatewaysdk/environment/schema/session_move.py +275 -0
- package/runtime/gatewaysdk/environment/schema/skills/agents/connector-template-author.md +5 -1
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +10 -11
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +49 -16
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +39 -9
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +27 -27
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +33 -33
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +13 -7
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +49 -1
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/journal-checks.md +182 -0
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/openapi-import.md +50 -21
- package/runtime/gatewaysdk/environment/schema/slack.py +4 -8
- package/runtime/gatewaysdk/environment/schema/snapshot.py +516 -140
- package/runtime/gatewaysdk/environment/schema/spill_files.py +228 -0
- package/runtime/gatewaysdk/environment/schema/store_contract.py +8 -14
- package/runtime/gatewaysdk/environment/schema/tasks.py +267 -276
- package/runtime/gatewaysdk/environment/schema/tools_world.py +146 -242
- package/runtime/gatewaysdk/environment/schema/ui.py +24 -5
- package/runtime/gatewaysdk/environment/schema/ui_static/app.js +100 -130
- package/runtime/gatewaysdk/environment/schema/ui_static/index.html +1 -8
- package/runtime/gatewaysdk/environment/schema/validation.py +235 -41
- package/runtime/gatewaysdk/environment/schema/verbs.py +32 -36
- package/runtime/gatewaysdk/environment/schema/worker.py +6 -4
- package/runtime/gatewaysdk/environment/schema/workers.py +345 -96
- package/runtime/gatewaysdk/environment/schema/world_host.py +953 -0
- package/runtime/gatewaysdk/environment/schema/world_sql.py +81 -0
- package/runtime/gatewaysdk/environment/schema/world_tests.py +80 -50
- package/runtime/gatewaysdk/environment/score.py +57 -0
- package/runtime/gatewaysdk/environment/secret_values.py +36 -0
- package/runtime/gatewaysdk/environment/world.py +43 -4
- package/runtime/gatewaysdk/environment/world_session_contract.py +46 -5
- package/skills/agents/connector-template-author.md +5 -1
- package/skills/benchmarks-getting-started/SKILL.md +10 -11
- package/skills/connector-schema-authoring/SKILL.md +49 -16
- package/skills/connector-schema-authoring/connector-worlds.md +142 -11
- package/skills/connector-schema-authoring/world-schema.md +103 -51
- package/skills/world-data-ingestion/ROWS.md +39 -9
- package/skills/world-data-ingestion/SKILL.md +27 -27
- package/skills/worlds-getting-started/SKILL.md +33 -33
- package/skills/worlds-getting-started/references/cli-mcp-map.md +13 -7
- package/skills/worlds-getting-started/references/gotchas.md +49 -1
- package/skills/worlds-getting-started/references/journal-checks.md +182 -0
- package/skills/worlds-getting-started/references/openapi-import.md +50 -21
- package/runtime/gatewaysdk/environment/schema/store.py +0 -1013
|
@@ -22,15 +22,15 @@ from __future__ import annotations
|
|
|
22
22
|
|
|
23
23
|
import re
|
|
24
24
|
from collections import Counter, deque
|
|
25
|
+
from collections.abc import Iterator
|
|
25
26
|
from dataclasses import dataclass, field
|
|
27
|
+
from itertools import islice
|
|
26
28
|
from typing import Any
|
|
27
29
|
|
|
28
30
|
from .compiler import FIELD_RESERVED, RESERVED, RESERVED_STATE_KEYS
|
|
29
|
-
from .openapi_document import OpenApiDocument
|
|
30
|
-
from .validation import fail, pointer
|
|
31
|
+
from .openapi_document import OpenApiDocument, unescape
|
|
32
|
+
from .validation import FIELD_NAME, fail, pointer
|
|
31
33
|
|
|
32
|
-
IDENTIFIER = re.compile(r"^[A-Za-z][A-Za-z0-9_]*$")
|
|
33
|
-
FIELD_IDENTIFIER = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
|
|
34
34
|
RESERVED_FIELDS = frozenset({"_key", "payload"})
|
|
35
35
|
#: A ``$def`` for a value the vendor leaves untyped (``{}``, ``additionalProperties: true``
|
|
36
36
|
#: at the top). Not recursive on purpose: the validator wants recursive targets typed.
|
|
@@ -103,10 +103,10 @@ class Names:
|
|
|
103
103
|
@staticmethod
|
|
104
104
|
def field(source: str) -> str:
|
|
105
105
|
"""A property name the compiler accepts; the source name when it already is one."""
|
|
106
|
-
name = re.sub(r"[^A-Za-z0-9_]", "_", source)
|
|
107
|
-
if not name or not
|
|
106
|
+
name = re.sub(r"[^A-Za-z0-9_-]", "_", source)
|
|
107
|
+
if not name or not FIELD_NAME.match(name):
|
|
108
108
|
name = "f_" + name
|
|
109
|
-
if name in RESERVED_FIELDS or name.startswith(FIELD_RESERVED):
|
|
109
|
+
if name.lower() in RESERVED_FIELDS or name.lower().startswith(FIELD_RESERVED):
|
|
110
110
|
name = "f_" + name
|
|
111
111
|
return name
|
|
112
112
|
|
|
@@ -149,6 +149,8 @@ class EntityKey:
|
|
|
149
149
|
"""Which property is a schema's primary key, and whether it is fit to be one."""
|
|
150
150
|
|
|
151
151
|
UNIQUE_EXTENSIONS = ("x-unique", "x-primary-key", "x-primaryKey", "x-identifier")
|
|
152
|
+
NESTED_DEPTH = 4
|
|
153
|
+
NESTED_VISITS = 10_000
|
|
152
154
|
|
|
153
155
|
def __init__(self, document: OpenApiDocument, source: str, properties: dict[str, Any], required: set[str]):
|
|
154
156
|
self.document = document
|
|
@@ -156,9 +158,8 @@ class EntityKey:
|
|
|
156
158
|
self.properties = properties
|
|
157
159
|
self.required = required
|
|
158
160
|
|
|
159
|
-
def
|
|
160
|
-
"""``id``, ``<name>Id``/``<name>_id``, a ``readOnly`` property marked unique by an
|
|
161
|
-
``x-`` extension, else (when ``fallback``) the first required scalar."""
|
|
161
|
+
def declared(self) -> str | None:
|
|
162
|
+
"""``id``, ``<name>Id``/``<name>_id``, or a ``readOnly`` property marked unique by an ``x-`` extension."""
|
|
162
163
|
for name in self._id_like():
|
|
163
164
|
if self._keyable(name):
|
|
164
165
|
return name
|
|
@@ -170,13 +171,74 @@ class EntityKey:
|
|
|
170
171
|
and self._keyable(name)
|
|
171
172
|
):
|
|
172
173
|
return name
|
|
174
|
+
return None
|
|
175
|
+
|
|
176
|
+
def detect(self, *, lookups: tuple[str, ...] = (), fallback: bool = True) -> str | None:
|
|
177
|
+
""":meth:`declared`, else the field a route's own ``{segment}`` looks the row up by
|
|
178
|
+
(``/works/{doi}`` → ``DOI``; nested, ``/studies/{nctId}`` → a JSON Pointer), else
|
|
179
|
+
(when ``fallback``) the first required scalar."""
|
|
180
|
+
declared = self.declared()
|
|
181
|
+
if declared is not None:
|
|
182
|
+
return declared
|
|
183
|
+
for own in sorted(lookups):
|
|
184
|
+
found = self.top_level(own) or self.nested(own)
|
|
185
|
+
if found is not None:
|
|
186
|
+
return found
|
|
173
187
|
if not fallback:
|
|
174
188
|
return None
|
|
175
|
-
for name in self.properties
|
|
176
|
-
|
|
177
|
-
|
|
189
|
+
return next((name for name in self.properties if name in self.required and self._keyable(name)), None)
|
|
190
|
+
|
|
191
|
+
def top_level(self, argument: str) -> str | None:
|
|
192
|
+
"""The keyable property ``argument`` names, spelled however the vendor spells it."""
|
|
193
|
+
wanted = Names.snake(argument)
|
|
194
|
+
return next((n for n in self.properties if Names.snake(n) == wanted and self._keyable(n)), None)
|
|
195
|
+
|
|
196
|
+
def nested(self, argument: str) -> str | None:
|
|
197
|
+
"""The JSON Pointer of the one keyable scalar ``argument`` names inside the
|
|
198
|
+
schema's objects (never inside an array or a nullable object), the shallowest
|
|
199
|
+
when several depths match; None when nothing does, one depth holds two, or the
|
|
200
|
+
search would read more than ``NESTED_VISITS`` properties (objects that share one
|
|
201
|
+
another many times over)."""
|
|
202
|
+
wanted = Names.snake(argument)
|
|
203
|
+
level: list[tuple[str, dict]] = [("", self.properties)]
|
|
204
|
+
left = self.NESTED_VISITS
|
|
205
|
+
for depth in range(self.NESTED_DEPTH):
|
|
206
|
+
members = list(islice(_members(level), left + 1))
|
|
207
|
+
if len(members) > left:
|
|
208
|
+
return None
|
|
209
|
+
left -= len(members)
|
|
210
|
+
nodes = [(here, name, raw, self._resolved(raw)) for here, name, raw in members]
|
|
211
|
+
found = [
|
|
212
|
+
here
|
|
213
|
+
for here, name, _, node in nodes
|
|
214
|
+
if depth > 0 and Names.snake(name) == wanted and self._scalar_key(node)
|
|
215
|
+
]
|
|
216
|
+
if found:
|
|
217
|
+
return found[0] if len(found) == 1 else None
|
|
218
|
+
level = [(here, node["properties"]) for here, _, raw, node in nodes if self._step(raw, node)]
|
|
178
219
|
return None
|
|
179
220
|
|
|
221
|
+
def leaf(self, key: str) -> dict:
|
|
222
|
+
"""The schema of the scalar ``key`` (a property name or a JSON Pointer) names."""
|
|
223
|
+
properties, resolved = self.properties, {}
|
|
224
|
+
for part in key_parts(key):
|
|
225
|
+
resolved = self._resolved(properties.get(part, {}))
|
|
226
|
+
properties = resolved.get("properties") if isinstance(resolved.get("properties"), dict) else {}
|
|
227
|
+
return resolved
|
|
228
|
+
|
|
229
|
+
@staticmethod
|
|
230
|
+
def _scalar_key(resolved: dict) -> bool:
|
|
231
|
+
return type_list(resolved.get("type")) in (["string"], ["integer"]) and not _nullable(resolved)
|
|
232
|
+
|
|
233
|
+
@staticmethod
|
|
234
|
+
def _step(raw: Any, resolved: dict) -> bool:
|
|
235
|
+
"""An object a nested key may pass through: never null (where it is used or where it
|
|
236
|
+
is defined), never a list."""
|
|
237
|
+
nullable = (isinstance(raw, dict) and _nullable(raw)) or _nullable(resolved)
|
|
238
|
+
return (
|
|
239
|
+
not nullable and isinstance(resolved.get("properties"), dict) and resolved.get("type") in (None, "object")
|
|
240
|
+
)
|
|
241
|
+
|
|
180
242
|
def scalars(self) -> frozenset[str]:
|
|
181
243
|
"""Properties a filter can compare: string, integer, number or boolean."""
|
|
182
244
|
return frozenset(name for name in self.properties if self._scalar_type(name) in SCALARS)
|
|
@@ -211,18 +273,21 @@ class EntityKey:
|
|
|
211
273
|
class ConvertedDef:
|
|
212
274
|
name: str
|
|
213
275
|
schema: dict
|
|
214
|
-
fields: dict[str, str]
|
|
276
|
+
fields: dict[str, str]
|
|
215
277
|
|
|
216
278
|
|
|
217
279
|
class SchemaConverter:
|
|
218
280
|
"""The document's schemas as world.json ``$defs``, converted once each."""
|
|
219
281
|
|
|
220
282
|
def __init__(self, document: OpenApiDocument, roots: dict[str, str]):
|
|
221
|
-
"""``roots`` maps the source names that become entities to their key property
|
|
283
|
+
"""``roots`` maps the source names that become entities to their key: a property
|
|
284
|
+
name, or a JSON Pointer (source spelling) to a scalar nested in the root."""
|
|
222
285
|
self.document = document
|
|
223
286
|
self.roots = roots
|
|
224
287
|
self.defs: dict[str, dict] = {}
|
|
225
288
|
self.fields: dict[str, dict[str, str]] = {}
|
|
289
|
+
self.keys: dict[str, str] = {}
|
|
290
|
+
self._nested: dict[str, list[str]] = {}
|
|
226
291
|
self.dropped: Counter[str] = Counter()
|
|
227
292
|
self.renamed: list[tuple[str, str, str]] = []
|
|
228
293
|
self.warnings: list[str] = []
|
|
@@ -236,8 +301,6 @@ class SchemaConverter:
|
|
|
236
301
|
for name in self.document.schemas:
|
|
237
302
|
self._names.claim(name)
|
|
238
303
|
|
|
239
|
-
# ------------------------------------------------------------- public
|
|
240
|
-
|
|
241
304
|
def convert_all(self, wanted: set[str]) -> dict[str, dict]:
|
|
242
305
|
"""Convert ``wanted`` and everything they reference, in order of discovery."""
|
|
243
306
|
for name in sorted(wanted):
|
|
@@ -247,8 +310,20 @@ class SchemaConverter:
|
|
|
247
310
|
if name in self.defs:
|
|
248
311
|
continue
|
|
249
312
|
self.defs[name] = self._convert_def(name)
|
|
313
|
+
for root, parts in self._nested.items():
|
|
314
|
+
self._require_along(self.defs[root], parts)
|
|
250
315
|
return dict(sorted(self.defs.items()))
|
|
251
316
|
|
|
317
|
+
def _require_along(self, node: dict, parts: list[str]) -> None:
|
|
318
|
+
"""Every object on a nested key's path requires the next step, so every row carries the key."""
|
|
319
|
+
for part in parts:
|
|
320
|
+
while isinstance(node.get("$ref"), str):
|
|
321
|
+
node = self.defs[unescape(node["$ref"][len("#/$defs/") :])]
|
|
322
|
+
listed = node.setdefault("required", [])
|
|
323
|
+
if part not in listed:
|
|
324
|
+
listed.append(part)
|
|
325
|
+
node = node["properties"][part]
|
|
326
|
+
|
|
252
327
|
def reference(self, name: str) -> str:
|
|
253
328
|
"""The ``$ref`` a world.json node uses for a top-level schema."""
|
|
254
329
|
self._want(name)
|
|
@@ -264,8 +339,6 @@ class SchemaConverter:
|
|
|
264
339
|
if name not in self.defs and name not in self._queue:
|
|
265
340
|
self._queue.append(name)
|
|
266
341
|
|
|
267
|
-
# ------------------------------------------------------------- one top-level schema
|
|
268
|
-
|
|
269
342
|
def _convert_def(self, name: str) -> dict:
|
|
270
343
|
at = f"{self.document.schemas_pointer}/{pointer(name)}"
|
|
271
344
|
raw = self.document.schemas[name]
|
|
@@ -285,7 +358,7 @@ class SchemaConverter:
|
|
|
285
358
|
def _entity_root(self, name: str, merged: dict, at: str, key: str) -> dict:
|
|
286
359
|
converted = self.convert(merged, at, (name,), resolve_root=False)
|
|
287
360
|
properties = converted.get("properties")
|
|
288
|
-
if "object" not in
|
|
361
|
+
if "object" not in type_list(converted.get("type")) or not isinstance(properties, dict):
|
|
289
362
|
fail("spec", f"Schema {name} is not an object schema, so it cannot be an entity", at)
|
|
290
363
|
converted["type"] = "object"
|
|
291
364
|
converted.setdefault("title", name)
|
|
@@ -293,10 +366,14 @@ class SchemaConverter:
|
|
|
293
366
|
renamed = Names.fields(properties)
|
|
294
367
|
self.renamed.extend((f"{at}/properties/{pointer(src)}", src, dst) for src, dst in renamed.items() if src != dst)
|
|
295
368
|
converted["properties"] = {renamed[k]: v for k, v in properties.items()}
|
|
369
|
+
head, *rest = key_parts(key)
|
|
296
370
|
required = [renamed[r] for r in converted.get("required", []) if r in renamed]
|
|
297
|
-
if renamed[
|
|
298
|
-
required.append(renamed[
|
|
371
|
+
if renamed[head] not in required:
|
|
372
|
+
required.append(renamed[head])
|
|
299
373
|
converted["required"] = required
|
|
374
|
+
self.keys[name] = "/".join(["", *(pointer(p) for p in (renamed[head], *rest))]) if rest else renamed[head]
|
|
375
|
+
if rest:
|
|
376
|
+
self._nested[name] = [renamed[head], *rest]
|
|
300
377
|
converted["additionalProperties"] = False
|
|
301
378
|
converted.pop("anyOf", None)
|
|
302
379
|
converted.pop("oneOf", None)
|
|
@@ -320,8 +397,6 @@ class SchemaConverter:
|
|
|
320
397
|
out[key] = raw[key]
|
|
321
398
|
return {"anyOf": [out, {"type": "null"}]} if _nullable(raw) else out
|
|
322
399
|
|
|
323
|
-
# ------------------------------------------------------------- allOf
|
|
324
|
-
|
|
325
400
|
def merged(self, resolved: dict, at: str, chain: tuple[str, ...]) -> dict:
|
|
326
401
|
""":meth:`merge` of a named schema, computed once: a diamond of ``allOf``
|
|
327
402
|
members (``A → B, C → D``) costs one merge of ``D``, not one per path."""
|
|
@@ -399,8 +474,6 @@ class SchemaConverter:
|
|
|
399
474
|
at,
|
|
400
475
|
)
|
|
401
476
|
|
|
402
|
-
# ------------------------------------------------------------- one schema node
|
|
403
|
-
|
|
404
477
|
def convert(self, raw: Any, at: str, stack: tuple[str, ...], *, resolve_root: bool = True) -> dict:
|
|
405
478
|
if raw is True or raw == {}:
|
|
406
479
|
return self.any_json()
|
|
@@ -463,7 +536,7 @@ class SchemaConverter:
|
|
|
463
536
|
|
|
464
537
|
def _types(self, raw: dict, at: str) -> tuple[list[str], bool]:
|
|
465
538
|
declared = raw.get("type")
|
|
466
|
-
types = ["string" if t == "file" else t for t in
|
|
539
|
+
types = ["string" if t == "file" else t for t in type_list(declared)]
|
|
467
540
|
unknown = [t for t in types if t not in _TYPES]
|
|
468
541
|
if unknown:
|
|
469
542
|
fail("spec", f"Unknown type {unknown[0]!r}", f"{at}/type")
|
|
@@ -501,8 +574,6 @@ class SchemaConverter:
|
|
|
501
574
|
return out
|
|
502
575
|
return self.any_json()
|
|
503
576
|
|
|
504
|
-
# ------------------------------------------------------------- per type
|
|
505
|
-
|
|
506
577
|
def _convert_object(self, raw: dict, out: dict, at: str, stack: tuple[str, ...]) -> None:
|
|
507
578
|
self._object_properties(raw, out, at, stack)
|
|
508
579
|
extra = raw.get("additionalProperties")
|
|
@@ -588,10 +659,22 @@ class SchemaConverter:
|
|
|
588
659
|
self.dropped[key] += 1
|
|
589
660
|
|
|
590
661
|
|
|
662
|
+
def key_parts(key: str) -> list[str]:
|
|
663
|
+
"""A key's steps: ``[name]`` for a property, each unescaped segment of a JSON Pointer."""
|
|
664
|
+
return [unescape(part) for part in key[1:].split("/")] if key.startswith("/") else [key]
|
|
665
|
+
|
|
666
|
+
|
|
591
667
|
def _nullable(raw: dict) -> bool:
|
|
592
668
|
return raw.get("nullable") is True or raw.get("x-nullable") is True
|
|
593
669
|
|
|
594
670
|
|
|
671
|
+
def _members(level: list[tuple[str, dict]]) -> Iterator[tuple[str, str, Any]]:
|
|
672
|
+
"""Every property of every object at one depth of a nested-key search, with its pointer."""
|
|
673
|
+
return (
|
|
674
|
+
(f"{prefix}/{pointer(name)}", name, raw) for prefix, properties in level for name, raw in properties.items()
|
|
675
|
+
)
|
|
676
|
+
|
|
677
|
+
|
|
595
678
|
def _object_like(schema: dict) -> bool:
|
|
596
679
|
declared = schema.get("type")
|
|
597
680
|
if declared not in (None, "object"):
|
|
@@ -603,7 +686,7 @@ def _object_like(schema: dict) -> bool:
|
|
|
603
686
|
)
|
|
604
687
|
|
|
605
688
|
|
|
606
|
-
def
|
|
689
|
+
def type_list(declared: Any) -> list[str]:
|
|
607
690
|
if isinstance(declared, str):
|
|
608
691
|
return [declared]
|
|
609
692
|
return [t for t in declared if isinstance(t, str)] if isinstance(declared, list) else []
|