sbol-db-server 0.1.0

HTTP server for sbol-db.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
{
  "openapi": "3.1.0",
  "info": {
    "title": "sbol-db",
    "version": "0.1.0",
    "description": "A Postgres-backed data management system for synthetic biology data. It ingests SBOL 3 RDF, upgrades SBOL 2 RDF, and imports GenBank or FASTA into SBOL 3 before projecting designs into a typed relational schema *and* an RDF quad store inside the same Postgres instance. It then exposes the result through five composable query primitives: typed lookup by IRI, bounded graph neighborhood traversal, read-only SPARQL 1.1, nucleotide substring + reverse-complement search, and ontology-aware role expansion.\n\nSee [`docs/crate-guide.md`](https://github.com/marpaia/sbol-db/blob/master/docs/crate-guide.md) for an architectural tour.",
    "contact": {
      "name": "sbol-db",
      "url": "https://github.com/marpaia/sbol-db"
    },
    "license": {
      "name": "MIT OR Apache-2.0"
    }
  },
  "servers": [
    {
      "url": "/",
      "description": "Current server"
    }
  ],
  "tags": [
    { "name": "Documents",    "description": "Import SBOL documents and inspect what was stored." },
    { "name": "Objects",      "description": "Resolve typed SBOL objects by IRI and re-emit them as RDF." },
    { "name": "Neighborhood", "description": "Bounded recursive graph traversal across `sbol_quads`." },
    { "name": "SPARQL",       "description": "Read-only SPARQL 1.1 evaluator (SELECT / ASK / CONSTRUCT / DESCRIBE)." },
    { "name": "Sequences",    "description": "Nucleotide substring + reverse-complement search backed by the k-mer seed index." },
    { "name": "Ontology",     "description": "Load OBO ontologies (SO, SBO, ...) and resolve transitive `is_a` closure." },
    { "name": "Jobs",         "description": "Background work queue: enqueue, inspect, and cancel async jobs (e.g. document imports). Workers claim with `FOR UPDATE SKIP LOCKED`, leases auto-renew, retries are exponentially backed off." },
    { "name": "Meta",         "description": "Liveness, readiness, metrics, OpenAPI schema, and this docs page." }
  ],
  "paths": {
    "/healthz": {
      "get": {
        "tags": ["Meta"],
        "summary": "Liveness check",
        "description": "Static liveness probe. Returns `ok` if the process is running; does not touch Postgres. Wire this to Kubernetes `livenessProbe`.",
        "operationId": "healthz",
        "responses": {
          "200": {
            "description": "Server is live.",
            "content": {
              "text/plain": {
                "schema": { "type": "string" },
                "example": "ok"
              }
            }
          }
        }
      }
    },
    "/readyz": {
      "get": {
        "tags": ["Meta"],
        "summary": "Readiness check",
        "description": "Issues a short-timeout `SELECT 1` against the connection pool. Returns 200 when Postgres is reachable, 503 otherwise. Wire this to Kubernetes `readinessProbe`.",
        "operationId": "readyz",
        "responses": {
          "200": {
            "description": "Database is reachable.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["status"],
                  "properties": { "status": { "type": "string", "enum": ["ready"] } }
                },
                "example": { "status": "ready" }
              }
            }
          },
          "503": {
            "description": "Database is unreachable or slow.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["status", "reason"],
                  "properties": {
                    "status": { "type": "string", "enum": ["not_ready"] },
                    "reason": { "type": "string" }
                  }
                },
                "example": { "status": "not_ready", "reason": "database probe timed out" }
              }
            }
          }
        }
      }
    },
    "/metrics": {
      "get": {
        "tags": ["Meta"],
        "summary": "Prometheus metrics",
        "description": "Prometheus text-format exposition of HTTP request counters/histograms (keyed by templated route), `sbol_db_pool_connections` gauges, and a `sbol_db_build_info` label gauge. Intended for in-cluster scraping; not part of the public query API.",
        "operationId": "metrics",
        "responses": {
          "200": {
            "description": "Prometheus exposition.",
            "content": {
              "text/plain": {
                "schema": { "type": "string" }
              }
            }
          }
        }
      }
    },

    "/documents": {
      "post": {
        "tags": ["Documents"],
        "summary": "Import a design document",
        "description": "Parses the request body as SBOL 3 RDF, SBOL 2 RDF, GenBank, or FASTA in the format derived from the `format` query parameter or the `Content-Type` header. Non-SBOL-3 inputs are converted to SBOL 3, then persisted inside one transaction (objects + quads + typed projections + validation) and returned as an import report.",
        "operationId": "importDocument",
        "parameters": [
          { "$ref": "#/components/parameters/SerializationFormat" },
          { "name": "namespace",    "in": "query", "schema": { "type": "string", "format": "uri" }, "description": "Namespace IRI for formats that need one. SBOL 2 uses it only as an upgrade fallback; GenBank and FASTA use it for emitted SBOL 3 object identities." },
          { "name": "source_uri",   "in": "query", "schema": { "type": "string" } },
          { "name": "document_iri", "in": "query", "schema": { "type": "string", "format": "uri" } },
          { "name": "name",         "in": "query", "schema": { "type": "string" } },
          { "name": "description",  "in": "query", "schema": { "type": "string" } },
          { "name": "created_by",   "in": "query", "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "description": "The serialized import body.",
          "content": {
            "text/turtle":        { "schema": { "type": "string" } },
            "application/ld+json":{ "schema": { "type": "string" } },
            "application/rdf+xml":{ "schema": { "type": "string" } },
            "application/n-triples": { "schema": { "type": "string" } },
            "chemical/x-genbank": { "schema": { "type": "string" } },
            "chemical/x-fasta": { "schema": { "type": "string" } }
          }
        },
        "responses": {
          "200": {
            "description": "Document imported.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ImportReport" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" }
        }
      }
    },
    "/documents/{id}": {
      "get": {
        "tags": ["Documents"],
        "summary": "Fetch document metadata",
        "operationId": "getDocument",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "200": {
            "description": "Document found.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DocumentRecord" }
              }
            }
          },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },

    "/documents/bulk": {
      "post": {
        "tags": ["Documents"],
        "summary": "Atomic bulk import",
        "description": "Imports up to 100 documents inside one Postgres transaction. **Either every document commits or none do** — if any document fails to parse or persist, the entire batch is rolled back and the first error is returned unchanged. Per-document validation runs and projection events are still recorded individually, but they share the outer transaction's atomicity.",
        "operationId": "createDocumentsBulk",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/BulkImportRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "All documents committed.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/BulkImportResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" }
        }
      }
    },
    "/objects": {
      "get": {
        "tags": ["Objects"],
        "summary": "Resolve a stored SBOL object by IRI",
        "operationId": "getObjectByIri",
        "parameters": [
          { "name": "iri", "in": "query", "required": true, "schema": { "type": "string", "format": "uri" } }
        ],
        "responses": {
          "200": {
            "description": "Object found.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/SbolObjectRecord" }
              }
            }
          },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/objects/list": {
      "get": {
        "tags": ["Objects"],
        "summary": "Paginated corpus listing",
        "description": "Lists stored objects in lexicographic IRI order with a keyset cursor. Use this for whole-corpus dumps; per-page size capped at 5000. Pass the response's `next_cursor` as `after` on the next call until `next_cursor` is null.",
        "operationId": "listObjects",
        "parameters": [
          { "name": "sbol_class",  "in": "query", "schema": { "type": "string", "format": "uri" } },
          { "name": "role",        "in": "query", "schema": { "type": "string", "format": "uri" } },
          { "name": "document_id", "in": "query", "schema": { "type": "string", "format": "uuid" } },
          { "name": "after",       "in": "query", "schema": { "type": "string", "format": "uri" }, "description": "Cursor: last `iri` from the prior page." },
          { "name": "limit",       "in": "query", "schema": { "type": "integer", "default": 1000, "minimum": 1, "maximum": 5000 } }
        ],
        "responses": {
          "200": {
            "description": "Page of matching objects plus a cursor for the next page (null when exhausted).",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ListObjectsResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" }
        }
      }
    },
    "/objects/lookup": {
      "post": {
        "tags": ["Objects"],
        "summary": "Bulk resolution of objects by IRI",
        "description": "Batched form of `GET /objects?iri=…`. Resolves up to 1000 IRIs in a single round trip via `WHERE iri = ANY(...)`. The response separates the IRIs that resolved (`found`) from those that did not (`missing`).",
        "operationId": "lookupObjects",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/LookupObjectsRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lookup results.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/LookupObjectsResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" }
        }
      }
    },
    "/objects/{id}/rdf": {
      "get": {
        "tags": ["Objects"],
        "summary": "Re-emit an object subgraph as RDF",
        "operationId": "exportObjectRdf",
        "parameters": [
          { "name": "id",     "in": "path",  "required": true, "schema": { "type": "string", "format": "uuid" } },
          { "name": "format", "in": "query", "schema": { "type": "string", "enum": ["turtle","jsonld","rdfxml","ntriples"], "default": "turtle" } }
        ],
        "responses": {
          "200": {
            "description": "RDF subgraph for the object.",
            "content": {
              "text/turtle":          { "schema": { "type": "string" } },
              "application/ld+json":  { "schema": { "type": "string" } },
              "application/rdf+xml":  { "schema": { "type": "string" } },
              "application/n-triples":{ "schema": { "type": "string" } }
            }
          },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },

    "/objects/neighborhood": {
      "get": {
        "tags": ["Neighborhood"],
        "summary": "Bounded graph traversal (JSON)",
        "description": "Walks the graph outward from `iri` under explicit depth, direction, and predicate-allowlist bounds. Returns visited nodes and edges as JSON. See [`docs/neighborhood.md`](https://github.com/marpaia/sbol-db/blob/master/docs/neighborhood.md).",
        "operationId": "neighborhood",
        "parameters": [
          { "$ref": "#/components/parameters/NeighborhoodIri" },
          { "$ref": "#/components/parameters/NeighborhoodDepth" },
          { "$ref": "#/components/parameters/NeighborhoodDirection" },
          { "$ref": "#/components/parameters/NeighborhoodPredicates" },
          { "$ref": "#/components/parameters/NeighborhoodMaxNodes" },
          { "$ref": "#/components/parameters/NeighborhoodLiterals" }
        ],
        "responses": {
          "200": {
            "description": "Traversal result.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/NeighborhoodResult" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" }
        }
      }
    },
    "/objects/neighborhood.rdf": {
      "get": {
        "tags": ["Neighborhood"],
        "summary": "Bounded graph traversal (RDF subgraph)",
        "operationId": "neighborhoodRdf",
        "parameters": [
          { "$ref": "#/components/parameters/NeighborhoodIri" },
          { "$ref": "#/components/parameters/NeighborhoodDepth" },
          { "$ref": "#/components/parameters/NeighborhoodDirection" },
          { "$ref": "#/components/parameters/NeighborhoodPredicates" },
          { "$ref": "#/components/parameters/NeighborhoodMaxNodes" },
          { "$ref": "#/components/parameters/NeighborhoodLiterals" },
          { "name": "format", "in": "query", "schema": { "type": "string", "enum": ["turtle","jsonld","ntriples","rdfxml"], "default": "turtle" } }
        ],
        "responses": {
          "200": {
            "description": "Visited subgraph in the chosen format.",
            "content": {
              "text/turtle":          { "schema": { "type": "string" } },
              "application/ld+json":  { "schema": { "type": "string" } },
              "application/n-triples":{ "schema": { "type": "string" } },
              "application/rdf+xml":  { "schema": { "type": "string" } }
            }
          }
        }
      }
    },

    "/sparql": {
      "get": {
        "tags": ["SPARQL"],
        "summary": "Run a SPARQL 1.1 query (URL form)",
        "description": "Read-only SPARQL endpoint. Update queries are rejected. The result format defaults to `application/sparql-results+json` for SELECT / ASK and `text/turtle` for CONSTRUCT / DESCRIBE; override via `Accept` header or the `format` query parameter.",
        "operationId": "sparqlGet",
        "parameters": [
          { "name": "query",  "in": "query", "required": true, "schema": { "type": "string" }, "example": "PREFIX sbol: <http://sbols.org/v3#> SELECT ?s WHERE { ?s a sbol:Component } LIMIT 10" },
          { "name": "format", "in": "query", "schema": { "type": "string", "enum": ["json","xml","csv","tsv","turtle","ntriples","jsonld"] } }
        ],
        "responses": {
          "200": { "$ref": "#/components/responses/SparqlResult" },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "504": { "description": "Query exceeded the configured timeout." }
        }
      },
      "post": {
        "tags": ["SPARQL"],
        "summary": "Run a SPARQL 1.1 query (POST body)",
        "operationId": "sparqlPost",
        "requestBody": {
          "required": true,
          "content": {
            "application/sparql-query": {
              "schema": { "type": "string" },
              "example": "PREFIX sbol: <http://sbols.org/v3#> ASK { ?s sbol:hasFeature ?f }"
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "required": ["query"],
                "properties": {
                  "query":  { "type": "string" },
                  "format": { "type": "string", "enum": ["json","xml","csv","tsv","turtle","ntriples","jsonld"] }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "$ref": "#/components/responses/SparqlResult" },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "504": { "description": "Query exceeded the configured timeout." }
        }
      }
    },

    "/sequences/search": {
      "get": {
        "tags": ["Sequences"],
        "summary": "Nucleotide substring search (forward + reverse complement)",
        "description": "Exact-match search over every indexed nucleotide `sbol:Sequence`. The k-mer seed index covers queries ≥ 8 bp; shorter patterns fall back to an `ILIKE` candidate scan. See [`docs/sequences.md`](https://github.com/marpaia/sbol-db/blob/master/docs/sequences.md).",
        "operationId": "sequenceSearch",
        "parameters": [
          { "name": "pattern",      "in": "query", "required": true, "schema": { "type": "string" }, "example": "GAATTC" },
          { "name": "max_hits",     "in": "query", "schema": { "type": "integer", "default": 1024, "minimum": 1 } },
          { "name": "forward_only", "in": "query", "schema": { "type": "boolean", "default": false } }
        ],
        "responses": {
          "200": {
            "description": "Hits sorted by sequence then position.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": { "$ref": "#/components/schemas/SequenceMatch" }
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": ["Sequences"],
        "summary": "Bulk nucleotide substring search",
        "description": "Runs the GET form for each pattern in the request body. Capped at 256 patterns per call. The response preserves input order with one `BatchSequenceMatch` entry per pattern.",
        "operationId": "sequenceSearchBatch",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/SequenceSearchBatchRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "One entry per input pattern.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": { "$ref": "#/components/schemas/BatchSequenceMatch" }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" }
        }
      }
    },

    "/ontology": {
      "get": {
        "tags": ["Ontology"],
        "summary": "List loaded ontologies",
        "operationId": "ontologyList",
        "responses": {
          "200": {
            "description": "Ontologies currently in the database.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": { "$ref": "#/components/schemas/OntologyRecord" }
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": ["Ontology"],
        "summary": "Fetch an OBO ontology and load it",
        "description": "Recognised prefixes (`so`, `sbo`) resolve to OBO Foundry defaults; for any other prefix supply `url` (and optionally `name`). The terms, aliases, and transitive `is_a` closure are materialised in one transaction. Reload replaces the previous version atomically.",
        "operationId": "ontologyLoad",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/OntologyLoadRequest" },
              "examples": {
                "Sequence Ontology": {
                  "value": { "prefix": "so" }
                },
                "Custom": {
                  "value": {
                    "prefix": "chebi",
                    "url": "http://purl.obolibrary.org/obo/chebi/chebi_lite.obo",
                    "name": "Chemical Entities of Biological Interest"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Load report.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/OntologyLoadReport" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" }
        }
      }
    },
    "/ontology/term": {
      "get": {
        "tags": ["Ontology"],
        "summary": "Get an ontology term by IRI or CURIE",
        "operationId": "ontologyTerm",
        "parameters": [
          { "name": "iri", "in": "query", "required": true, "schema": { "type": "string" }, "example": "SO:0000167" }
        ],
        "responses": {
          "200": {
            "description": "Term metadata.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/OntologyTermRecord" }
              }
            }
          },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/ontology/terms": {
      "get": {
        "tags": ["Ontology"],
        "summary": "Page through every term in a loaded ontology",
        "description": "Returns the terms belonging to `prefix`, sorted by curie, optionally filtered by a case-insensitive substring match against either the curie or the name. The response includes the total match count so clients can render pagination without a second round-trip.",
        "operationId": "ontologyTerms",
        "parameters": [
          { "name": "prefix", "in": "query", "required": true, "schema": { "type": "string" }, "example": "SBO" },
          { "name": "q",      "in": "query", "required": false, "schema": { "type": "string" }, "example": "binding" },
          { "name": "limit",  "in": "query", "required": false, "schema": { "type": "integer", "minimum": 1, "maximum": 500, "default": 100 } },
          { "name": "offset", "in": "query", "required": false, "schema": { "type": "integer", "minimum": 0, "default": 0 } }
        ],
        "responses": {
          "200": {
            "description": "Matching terms with pagination metadata.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["prefix", "total", "limit", "offset", "terms"],
                  "properties": {
                    "prefix": { "type": "string" },
                    "total":  { "type": "integer", "minimum": 0 },
                    "limit":  { "type": "integer", "minimum": 1 },
                    "offset": { "type": "integer", "minimum": 0 },
                    "terms":  {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/OntologyTermRecord" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/ontology/descendants": {
      "get": {
        "tags": ["Ontology"],
        "summary": "Transitive `is_a` closure for a term",
        "description": "Returns the canonical term plus every descendant under it. Accepts the canonical OBO Foundry IRI (`http://purl.obolibrary.org/obo/SO_0000167`), the identifiers.org form, or a bare CURIE (`SO:0000167`).",
        "operationId": "ontologyDescendants",
        "parameters": [
          { "name": "iri", "in": "query", "required": true, "schema": { "type": "string" }, "example": "SO:0000167" }
        ],
        "responses": {
          "200": {
            "description": "Descendant IRIs with depth.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": ["iri", "depth"],
                    "properties": {
                      "iri":   { "type": "string", "format": "uri" },
                      "depth": { "type": "integer", "minimum": 0 }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },

    "/jobs": {
      "post": {
        "tags": ["Jobs"],
        "summary": "Enqueue a background job",
        "description": "Inserts a row in `sbol_jobs`. If `idempotency_key` is set and a non-terminal or succeeded job already exists for the same `(kind, idempotency_key)` pair, the existing job is returned with `deduplicated: true` rather than re-queued.",
        "operationId": "enqueueJob",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/EnqueueJobRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The job row, plus a flag indicating whether it was deduplicated against an existing entry.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/EnqueueJobResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" }
        }
      },
      "get": {
        "tags": ["Jobs"],
        "summary": "List jobs with optional filters",
        "description": "Filters compose with AND. The default `limit` is 100; values above 1000 are clamped. Results are ordered most-recent-first.",
        "operationId": "listJobs",
        "parameters": [
          { "name": "kind",           "in": "query", "schema": { "type": "string" } },
          { "name": "status",         "in": "query", "schema": { "type": "string", "enum": ["queued","running","succeeded","failed","cancelled","dead"] } },
          { "name": "queue",          "in": "query", "schema": { "type": "string" } },
          { "name": "correlation_id", "in": "query", "schema": { "type": "string", "format": "uuid" } },
          { "name": "limit",          "in": "query", "schema": { "type": "integer", "default": 100, "minimum": 1, "maximum": 1000 } }
        ],
        "responses": {
          "200": {
            "description": "Matching `sbol_jobs` rows.",
            "content": {
              "application/json": {
                "schema": { "type": "array", "items": { "$ref": "#/components/schemas/SbolJob" } }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" }
        }
      }
    },
    "/jobs/{id}": {
      "get": {
        "tags": ["Jobs"],
        "summary": "Fetch a job by id",
        "operationId": "getJob",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "200": {
            "description": "The job row.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/SbolJob" }
              }
            }
          },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/jobs/{id}/attempts": {
      "get": {
        "tags": ["Jobs"],
        "summary": "Per-attempt audit log for a job",
        "description": "Returns each row in `sbol_job_attempts` for the given job, newest first. Useful for inspecting a failed job's retry history, including the worker that ran each attempt and its error message. Returns 404 when the job id does not exist; returns 200 with an empty array when the job exists but has not yet been dequeued.",
        "operationId": "jobAttempts",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "200": {
            "description": "Attempts ordered by `attempt_no` descending.",
            "content": {
              "application/json": {
                "schema": { "type": "array", "items": { "$ref": "#/components/schemas/JobAttempt" } }
              }
            }
          },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/jobs/{id}/cancel": {
      "post": {
        "tags": ["Jobs"],
        "summary": "Cancel a queued or running job",
        "description": "Idempotent: transitions `queued` or `running` jobs to `cancelled` and returns `{ cancelled: true }`. Terminal jobs (succeeded / failed / dead / already cancelled) are left alone and return `{ cancelled: false }`.",
        "operationId": "cancelJob",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "200": {
            "description": "Whether this call transitioned the job.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["cancelled"],
                  "properties": { "cancelled": { "type": "boolean" } }
                }
              }
            }
          }
        }
      }
    },

    "/lab/api/observability/summary": {
      "get": {
        "tags": ["Lab Observability"],
        "summary": "Compact health + traffic snapshot for the lab observability page",
        "description": "Returns process health, the API + worker pool capacity, job queue depth + oldest-queued age, recent failure counts, and a rolling 10-minute traffic window (request rate, latency quantiles, error counts).",
        "operationId": "labObservabilitySummary",
        "responses": {
          "200": {
            "description": "Snapshot blob.",
            "content": { "application/json": { "schema": { "type": "object" } } }
          }
        }
      }
    },
    "/lab/api/info": {
      "get": {
        "tags": ["Lab"],
        "summary": "Active backend and its capabilities",
        "description": "Reports the running engine (`postgres`/`sqlite`/`rocksdb`), its display name, and capability flags (sql_console, relational_schema, maintenance, slow_query_stats, activity_and_locks). The lab UI fetches this once and gates features on it.",
        "operationId": "labInfo",
        "responses": {
          "200": {
            "description": "Backend identity and capability flags.",
            "content": { "application/json": { "schema": { "type": "object" } } }
          }
        }
      }
    },
    "/lab/api/observability/maintenance/database": {
      "get": {
        "tags": ["Lab Observability"],
        "summary": "Total database size",
        "description": "Relational engines only (Postgres, SQLite). 501 on a key-value backend.",
        "operationId": "labMaintDatabase",
        "responses": {
          "200": {
            "description": "Total bytes for the database.",
            "content": { "application/json": { "schema": { "type": "object" } } }
          }
        }
      }
    },
    "/lab/api/observability/maintenance/tables": {
      "get": {
        "tags": ["Lab Observability"],
        "summary": "Top tables by size",
        "description": "Relational engines only (Postgres, SQLite). 501 on a key-value backend.",
        "operationId": "labMaintTables",
        "parameters": [
          { "name": "limit",  "in": "query", "schema": { "type": "integer", "default": 20, "minimum": 1, "maximum": 200 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "default": 0,  "minimum": 0 } }
        ],
        "responses": {
          "200": {
            "description": "Per-table stats (rows, total and index bytes, and on Postgres dead-tuple and vacuum metadata).",
            "content": { "application/json": { "schema": { "type": "array", "items": { "type": "object" } } } }
          }
        }
      }
    },
    "/lab/api/observability/maintenance/indexes": {
      "get": {
        "tags": ["Lab Observability"],
        "summary": "Top indexes by on-disk size",
        "description": "Relational engines only (Postgres, SQLite). 501 on a key-value backend.",
        "operationId": "labMaintIndexes",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 30, "minimum": 1, "maximum": 200 } }
        ],
        "responses": {
          "200": {
            "description": "Index stats; idx_scan is reported on Postgres.",
            "content": { "application/json": { "schema": { "type": "array", "items": { "type": "object" } } } }
          }
        }
      }
    },
    "/lab/api/observability/maintenance/activity": {
      "get": {
        "tags": ["Lab Observability"],
        "summary": "Live sessions",
        "description": "Postgres only (from pg_stat_activity). Empty on other backends.",
        "operationId": "labMaintActivity",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 50, "minimum": 1, "maximum": 200 } }
        ],
        "responses": {
          "200": {
            "description": "Per-pid live state, excluding the requester's own backend.",
            "content": { "application/json": { "schema": { "type": "array", "items": { "type": "object" } } } }
          }
        }
      }
    },
    "/lab/api/observability/maintenance/locks": {
      "get": {
        "tags": ["Lab Observability"],
        "summary": "Blocking lock pairs",
        "description": "Postgres only (from pg_locks). Empty on other backends.",
        "operationId": "labMaintLocks",
        "responses": {
          "200": {
            "description": "Blocker to blocked pairs (read-only).",
            "content": { "application/json": { "schema": { "type": "array", "items": { "type": "object" } } } }
          }
        }
      }
    },
    "/lab/api/observability/maintenance/tables/{name}/schema": {
      "get": {
        "tags": ["Lab Observability"],
        "summary": "Schema introspection for a single table",
        "description": "Columns (name, column_type, nullability, default, comment, primary-key flag) plus outgoing and incoming foreign-key references. Relational engines only. Returns 404 when the relation does not exist.",
        "operationId": "labMaintTableSchema",
        "parameters": [
          { "name": "name", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Full schema metadata for the requested table.",
            "content": { "application/json": { "schema": { "type": "object" } } }
          },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/lab/api/observability/maintenance/slow-queries": {
      "get": {
        "tags": ["Lab Observability"],
        "summary": "Top slow queries (Postgres, if pg_stat_statements is installed)",
        "description": "Returns `{ status: \"not_installed\", setup_hint }` when the extension isn't present; otherwise `{ status: \"installed\", rows }`.",
        "operationId": "labMaintSlowQueries",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 20, "minimum": 1, "maximum": 100 } }
        ],
        "responses": {
          "200": {
            "description": "Tagged union: not_installed vs installed.",
            "content": { "application/json": { "schema": { "type": "object" } } }
          }
        }
      }
    },
    "/lab/api/observability/maintenance/optimize": {
      "post": {
        "tags": ["Lab Observability"],
        "summary": "Run routine optimize maintenance",
        "description": "Refreshes planner statistics and reclaims space (SQLite VACUUM/ANALYZE, Postgres ANALYZE). Relational engines only.",
        "operationId": "labMaintOptimize",
        "responses": {
          "200": {
            "description": "`{ ok: true }` when the maintenance ran.",
            "content": { "application/json": { "schema": { "type": "object" } } }
          }
        }
      }
    },
    "/lab/api/observability/maintenance/lsm": {
      "get": {
        "tags": ["Lab Observability"],
        "summary": "LSM engine internals",
        "description": "RocksDB only. Total size, estimated keys, pending compaction bytes, running compactions, and per-column-family and per-level breakdowns. 501 on other backends.",
        "operationId": "labMaintLsm",
        "responses": {
          "200": {
            "description": "Column families, levels, and compaction state.",
            "content": { "application/json": { "schema": { "type": "object" } } }
          }
        }
      }
    },
    "/lab/api/observability/maintenance/compact": {
      "post": {
        "tags": ["Lab Observability"],
        "summary": "Trigger a full manual compaction",
        "description": "RocksDB only. Compacts every column family; can be slow on a large store. 501 on other backends.",
        "operationId": "labMaintCompact",
        "responses": {
          "200": {
            "description": "`{ ok: true }` when compaction completed.",
            "content": { "application/json": { "schema": { "type": "object" } } }
          }
        }
      }
    },
    "/lab/api/observability/jobs/recent": {
      "get": {
        "tags": ["Lab Observability"],
        "summary": "Recent job history across all queues",
        "operationId": "labObsJobsRecent",
        "parameters": [
          { "name": "limit",  "in": "query", "schema": { "type": "integer", "default": 50, "minimum": 1, "maximum": 500 } },
          { "name": "queue",  "in": "query", "schema": { "type": "string" } },
          { "name": "status", "in": "query", "schema": { "type": "string", "enum": ["queued","running","succeeded","failed","cancelled","dead"] } }
        ],
        "responses": {
          "200": {
            "description": "Most-recent-first sbol_jobs rows.",
            "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/SbolJob" } } } }
          }
        }
      }
    },

    "/openapi.json": {
      "get": {
        "tags": ["Meta"],
        "summary": "OpenAPI 3.1 schema for this server",
        "operationId": "openApiSchema",
        "responses": {
          "200": {
            "description": "The OpenAPI document.",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/docs": {
      "get": {
        "tags": ["Meta"],
        "summary": "Interactive API documentation (Scalar)",
        "operationId": "docsUi",
        "responses": {
          "200": {
            "description": "The rendered docs page.",
            "content": {
              "text/html": { "schema": { "type": "string" } }
            }
          }
        }
      }
    }
  },

  "components": {
    "parameters": {
      "SerializationFormat": {
        "name": "format",
        "in": "query",
        "description": "Override the format inferred from `Content-Type`.",
        "schema": { "type": "string", "enum": ["turtle","jsonld","rdfxml","ntriples","genbank","fasta"] }
      },
      "NeighborhoodIri": {
        "name": "iri",
        "in": "query",
        "required": true,
        "schema": { "type": "string", "format": "uri" },
        "description": "Root IRI to expand from."
      },
      "NeighborhoodDepth": {
        "name": "depth",
        "in": "query",
        "schema": { "type": "integer", "default": 2, "minimum": 0 }
      },
      "NeighborhoodDirection": {
        "name": "direction",
        "in": "query",
        "schema": { "type": "string", "enum": ["forward","backward","both"], "default": "forward" }
      },
      "NeighborhoodPredicates": {
        "name": "predicates",
        "in": "query",
        "description": "Comma-separated predicate IRIs (axum's default query parser does not support repeated keys).",
        "schema": { "type": "string" }
      },
      "NeighborhoodMaxNodes": {
        "name": "max_nodes",
        "in": "query",
        "schema": { "type": "integer", "default": 2048, "minimum": 1 }
      },
      "NeighborhoodLiterals": {
        "name": "literals",
        "in": "query",
        "description": "Include literal-position edges in the result (does not affect the traversal frontier).",
        "schema": { "type": "boolean", "default": false }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "The request was malformed.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/ErrorBody" }
          }
        }
      },
      "NotFound": {
        "description": "The requested resource does not exist.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/ErrorBody" }
          }
        }
      },
      "SparqlResult": {
        "description": "Serialized SPARQL result. The content type matches the format the engine produced.",
        "content": {
          "application/sparql-results+json": { "schema": { "type": "object" } },
          "application/sparql-results+xml":  { "schema": { "type": "string" } },
          "text/csv":                        { "schema": { "type": "string" } },
          "text/tab-separated-values":       { "schema": { "type": "string" } },
          "text/turtle":                     { "schema": { "type": "string" } },
          "application/n-triples":           { "schema": { "type": "string" } },
          "application/ld+json":             { "schema": { "type": "object" } }
        }
      }
    },
    "schemas": {
      "ErrorBody": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error":   { "type": "string" },
          "details": { "type": "object", "additionalProperties": true }
        }
      },
      "ImportReport": {
        "type": "object",
        "required": ["document_id", "object_count", "quad_count", "validation_status", "validation_issue_count"],
        "properties": {
          "document_id":            { "type": "string", "format": "uuid" },
          "object_count":           { "type": "integer", "minimum": 0 },
          "quad_count":             { "type": "integer", "minimum": 0 },
          "validation_status":      { "type": "string", "enum": ["passed","failed"] },
          "validation_issue_count": { "type": "integer", "minimum": 0 }
        }
      },
      "DocumentRecord": {
        "type": "object",
        "properties": {
          "id":                   { "type": "string", "format": "uuid" },
          "document_iri":         { "type": "string", "format": "uri" },
          "name":                 { "type": "string" },
          "description":          { "type": "string" },
          "serialization_format": { "type": "string" },
          "source_uri":           { "type": "string" },
          "created_by":           { "type": "string" },
          "created_at":           { "type": "string", "format": "date-time" }
        }
      },
      "SbolObjectRecord": {
        "type": "object",
        "properties": {
          "id":                  { "type": "string", "format": "uuid" },
          "iri":                 { "type": "string", "format": "uri" },
          "sbol_class":          { "type": "string" },
          "display_id":          { "type": "string" },
          "name":                { "type": "string" },
          "persistent_identity": { "type": "string", "format": "uri" },
          "version":             { "type": "string" },
          "types":               { "type": "array", "items": { "type": "string" } },
          "roles":               { "type": "array", "items": { "type": "string" } },
          "data":                { "type": "object", "additionalProperties": true },
          "created_at":          { "type": "string", "format": "date-time" }
        }
      },
      "NeighborhoodResult": {
        "type": "object",
        "required": ["root_iri","nodes","edges","max_depth_reached","truncated"],
        "properties": {
          "root_iri":          { "type": "string", "format": "uri" },
          "nodes":             { "type": "array", "items": { "$ref": "#/components/schemas/NodeInfo" } },
          "edges":             { "type": "array", "items": { "$ref": "#/components/schemas/EdgeInfo" } },
          "max_depth_reached": { "type": "integer", "minimum": 0 },
          "truncated":         { "type": "boolean" }
        }
      },
      "NodeInfo": {
        "type": "object",
        "required": ["id","depth"],
        "properties": {
          "id":          { "type": "string" },
          "depth":       { "type": "integer", "minimum": 0 },
          "blank_node":  { "type": "boolean", "default": false },
          "sbol_class":  { "type": "string" },
          "display_id":  { "type": "string" },
          "name":        { "type": "string" }
        }
      },
      "EdgeInfo": {
        "type": "object",
        "required": ["subject","predicate","object","depth"],
        "properties": {
          "subject":   { "type": "string" },
          "predicate": { "type": "string", "format": "uri" },
          "depth":     { "type": "integer", "minimum": 0 },
          "object":    {
            "oneOf": [
              { "type": "object", "properties": { "iri":       { "type": "string", "format": "uri" } }, "required": ["iri"] },
              { "type": "object", "properties": { "blank":     { "type": "string" } },                  "required": ["blank"] },
              { "type": "object", "properties": {
                  "literal":  { "type": "string" },
                  "datatype": { "type": "string", "format": "uri" },
                  "language": { "type": "string" }
                }, "required": ["literal","datatype"] }
            ]
          }
        }
      },
      "SequenceMatch": {
        "type": "object",
        "required": ["sequence_iri","start","length","strand"],
        "properties": {
          "sequence_iri": { "type": "string", "format": "uri" },
          "start":        { "type": "integer", "minimum": 0 },
          "length":       { "type": "integer", "minimum": 1 },
          "strand":       { "type": "string", "enum": ["+","-"] }
        }
      },
      "BatchSequenceMatch": {
        "type": "object",
        "required": ["pattern","matches"],
        "properties": {
          "pattern": { "type": "string" },
          "matches": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/SequenceMatch" }
          }
        }
      },
      "SequenceSearchBatchRequest": {
        "type": "object",
        "required": ["patterns"],
        "properties": {
          "patterns":     { "type": "array", "items": { "type": "string" }, "maxItems": 256 },
          "max_hits":     { "type": "integer", "minimum": 1, "default": 1024 },
          "forward_only": { "type": "boolean", "default": false }
        }
      },
      "BulkImportRequest": {
        "type": "object",
        "required": ["documents"],
        "properties": {
          "documents": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "required": ["body","format"],
              "properties": {
                "body":         { "type": "string", "description": "Payload in the format named by `format`." },
                "format":       { "type": "string", "enum": ["turtle","jsonld","rdfxml","ntriples","genbank","fasta"] },
                "namespace":    { "type": "string", "format": "uri" },
                "source_uri":   { "type": "string" },
                "document_iri": { "type": "string", "format": "uri" },
                "name":         { "type": "string" },
                "description":  { "type": "string" },
                "created_by":   { "type": "string" }
              }
            }
          }
        }
      },
      "BulkImportResponse": {
        "type": "object",
        "required": ["imported","reports"],
        "properties": {
          "imported": { "type": "integer", "minimum": 0 },
          "reports":  { "type": "array", "items": { "$ref": "#/components/schemas/ImportReport" } }
        }
      },
      "LookupObjectsRequest": {
        "type": "object",
        "required": ["iris"],
        "properties": {
          "iris": { "type": "array", "items": { "type": "string", "format": "uri" }, "maxItems": 1000 }
        }
      },
      "LookupObjectsResponse": {
        "type": "object",
        "required": ["found","missing"],
        "properties": {
          "found":   { "type": "array", "items": { "$ref": "#/components/schemas/SbolObjectRecord" } },
          "missing": { "type": "array", "items": { "type": "string", "format": "uri" } }
        }
      },
      "ListObjectsResponse": {
        "type": "object",
        "required": ["objects"],
        "properties": {
          "objects":     { "type": "array", "items": { "$ref": "#/components/schemas/SbolObjectRecord" } },
          "next_cursor": { "type": "string", "format": "uri", "nullable": true, "description": "IRI to pass as `after` on the next call; absent or null when the listing is exhausted." }
        }
      },
      "OntologyRecord": {
        "type": "object",
        "required": ["prefix","name","term_count","imported_at"],
        "properties": {
          "prefix":     { "type": "string" },
          "name":       { "type": "string" },
          "source_url": { "type": "string", "format": "uri" },
          "version":    { "type": "string" },
          "term_count": { "type": "integer", "minimum": 0 },
          "imported_at":{ "type": "string", "format": "date-time" }
        }
      },
      "OntologyTermRecord": {
        "type": "object",
        "required": ["iri","prefix","curie","name","is_obsolete","synonyms"],
        "properties": {
          "iri":         { "type": "string", "format": "uri" },
          "prefix":      { "type": "string" },
          "curie":       { "type": "string", "example": "SO:0000167" },
          "name":        { "type": "string" },
          "definition":  { "type": "string" },
          "is_obsolete": { "type": "boolean" },
          "synonyms":    { "type": "array", "items": { "type": "string" } }
        }
      },
      "OntologyLoadRequest": {
        "type": "object",
        "required": ["prefix"],
        "properties": {
          "prefix": { "type": "string", "description": "Short prefix used as the row key (e.g. `so`, `sbo`)." },
          "url":    { "type": "string", "format": "uri", "description": "Required for prefixes without a built-in default." },
          "name":   { "type": "string", "description": "Display name. Defaults to the prefix when omitted." }
        }
      },
      "OntologyLoadReport": {
        "type": "object",
        "required": ["prefix","term_count","closure_count","alias_count"],
        "properties": {
          "prefix":        { "type": "string" },
          "source_url":    { "type": "string", "format": "uri" },
          "version":       { "type": "string" },
          "term_count":    { "type": "integer", "minimum": 0 },
          "closure_count": { "type": "integer", "minimum": 0 },
          "alias_count":   { "type": "integer", "minimum": 0 }
        }
      },
      "JobStatus": {
        "type": "string",
        "enum": ["queued","running","succeeded","failed","cancelled","dead"]
      },
      "SbolJob": {
        "type": "object",
        "required": ["id","kind","status","priority","queue","payload","attempts","max_attempts","available_at","created_at"],
        "properties": {
          "id":               { "type": "string", "format": "uuid" },
          "kind":             { "type": "string", "description": "Handler name. Built-in handlers include `import_document`, `import_remote_document`, and `import_synbiohub_collection`." },
          "status":           { "$ref": "#/components/schemas/JobStatus" },
          "priority":         { "type": "integer", "description": "Higher dequeues first." },
          "queue":            { "type": "string", "default": "default" },
          "payload":          { "description": "Handler-specific JSON payload." },
          "result":           { "description": "Handler-specific JSON result; populated after success.", "nullable": true },
          "error":            { "type": "string", "nullable": true, "description": "Last error message; populated after failure." },
          "idempotency_key":  { "type": "string", "nullable": true },
          "attempts":         { "type": "integer", "minimum": 0 },
          "max_attempts":     { "type": "integer", "minimum": 1 },
          "available_at":     { "type": "string", "format": "date-time", "description": "Earliest time the job is eligible for dequeue (used by retry backoff)." },
          "leased_by":        { "type": "string", "nullable": true, "description": "Worker id holding the lease while `status = running`." },
          "lease_expires_at": { "type": "string", "format": "date-time", "nullable": true },
          "parent_job_id":    { "type": "string", "format": "uuid", "nullable": true },
          "correlation_id":   { "type": "string", "format": "uuid", "nullable": true },
          "created_at":       { "type": "string", "format": "date-time" },
          "started_at":       { "type": "string", "format": "date-time", "nullable": true },
          "finished_at":      { "type": "string", "format": "date-time", "nullable": true }
        }
      },
      "EnqueueJobRequest": {
        "type": "object",
        "required": ["kind","payload"],
        "properties": {
          "kind":            { "type": "string" },
          "payload":         { "description": "Handler-specific JSON payload." },
          "queue":           { "type": "string" },
          "priority":        { "type": "integer" },
          "max_attempts":    { "type": "integer", "minimum": 1 },
          "idempotency_key": { "type": "string", "description": "When set, deduplicates against any non-terminal or succeeded job with the same `(kind, idempotency_key)`." },
          "correlation_id":  { "type": "string", "format": "uuid" }
        }
      },
      "JobAttempt": {
        "type": "object",
        "required": ["id","job_id","attempt_no","worker_id","started_at","status"],
        "properties": {
          "id":          { "type": "integer", "format": "int64", "description": "Auto-increment row id in `sbol_job_attempts`." },
          "job_id":      { "type": "string", "format": "uuid" },
          "attempt_no":  { "type": "integer", "minimum": 1 },
          "worker_id":   { "type": "string" },
          "started_at":  { "type": "string", "format": "date-time" },
          "finished_at": { "type": "string", "format": "date-time", "nullable": true, "description": "Null while the attempt is still in-flight." },
          "status":      { "$ref": "#/components/schemas/JobStatus" },
          "error":       { "type": "string", "nullable": true }
        }
      },
      "EnqueueJobResponse": {
        "type": "object",
        "required": ["job","deduplicated"],
        "properties": {
          "job":          { "$ref": "#/components/schemas/SbolJob" },
          "deduplicated": { "type": "boolean", "description": "True when an existing job was returned instead of inserting a new one." }
        }
      }
    }
  }
}