Add a GKB extension schema#

Let a pack define the structure of its own findings inside canonical knowledge artifacts.

A GKB artifact carries an extensions map. Each key is a namespaced schema name such as geonemo.ship-detection/v4. The server checks the value of every registered namespace against its JSON Schema when an artifact is published. A namespace that no schema names is kept as it is and reported as unverified. The maritime pack’s Ship schemas (packs/maritime/schemas/) are the worked example.

Prerequisites#

  • A pack that registers on the server. See Write a pack.

  • A JSON Schema (Draft 2020-12) for the extension value.

Steps#

  1. Put the schema in the pack, for example packs/mypack/schemas/example.finding-v1.schema.json. Name the namespace <owner>.<name>/v<major>, with the major version in the name.

  2. Pin it in packs/mypack/schemas/manifest.yaml:

    schema_registry: '1.0'
    extensions:
    - namespace: example.finding/v1
      version: 1.0.0
      schema: example.finding-v1.schema.json
      sha256: <digest>
    

    The digest is the SHA-256 of the schema’s canonical compact JSON:

    python3 -c "import hashlib, json, sys; d = json.load(open(sys.argv[1])); \
    print(hashlib.sha256(json.dumps(d, sort_keys=True, separators=(',', ':')) \
    .encode()).hexdigest())" packs/mypack/schemas/example.finding-v1.schema.json
    

    A wrong digest stops the server from registering the schema.

  3. Ship the files with the pack. In packs/mypack/pyproject.toml, add schemas/manifest.yaml and schemas/*.schema.json to [tool.setuptools.package-data] for the pack’s package.

  4. Register the folder in part.py:

    from pathlib import Path
    
    SCHEMAS = Path(__file__).resolve().parent / "schemas"
    
    def register(registry) -> None:
        registry.add_gkb_extensions(SCHEMAS)
    

    The server image lists every part’s manifest in its extension registry folder, next to the toolkit’s own (knowledge/gkb/extensions/, which pins gkb.review/v1).

  5. Optional: check rules a schema cannot express. Register a validator for the namespaces. It raises ValueError, TypeError or KeyError for an invalid value:

    registry.add_extension_validator({"example.finding/v1"}, validate_findings)
    
  6. Optional: give large, validated extensions their own size budget in the typed client. The client bounds artifact metadata; a pack can register a (label, namespaces, validate) tuple under the geonemo.client.gkb_extensions entry point group of its client distribution (see packs/maritime/pyproject.toml).

  7. Test: assert the manifest digests match the files (see packs/maritime/tests/test_ship_extension_manifest.py) and that a valid and an invalid value publish and fail as expected.

Result#

Publishing an artifact with extensions: {"example.finding/v1": {...}} validates the value. An invalid value is refused, and a value in an unregistered namespace is stored and reported as unverified. See Knowledge base (GKB) for the publishing path.