|
| 1 | +.. _origin_curation_api: |
| 2 | + |
| 3 | +Origin Curation API |
| 4 | +=================== |
| 5 | + |
| 6 | +The origin curation API extends the project endpoints with helpers to list, |
| 7 | +create, update, and bulk-curate ``CodebaseRelation`` entries. Every endpoint |
| 8 | +is nested under a project resource: |
| 9 | + |
| 10 | +.. code-block:: text |
| 11 | +
|
| 12 | + /api/projects/<project_uuid>/relations/ |
| 13 | +
|
| 14 | +Authentication |
| 15 | +-------------- |
| 16 | + |
| 17 | +All endpoints require the same authentication and permission settings as the |
| 18 | +core API. When ``REQUIRE_AUTHENTICATION`` is enabled, include the API token in |
| 19 | +the ``Authorization`` header:: |
| 20 | + |
| 21 | + Authorization: Token <your-token> |
| 22 | + |
| 23 | +Listing relations |
| 24 | +----------------- |
| 25 | + |
| 26 | +``GET /api/projects/<uuid>/relations/`` |
| 27 | + |
| 28 | +Returns a paginated list of relations for the project. Results can be filtered |
| 29 | +using the parameters provided by :class:`RelationFilterSet`: |
| 30 | + |
| 31 | +``search`` |
| 32 | + Full text search on the ``to_resource.path``. |
| 33 | +``map_type`` |
| 34 | + Filter by relation map type (for example ``java_to_class``). |
| 35 | +``status`` |
| 36 | + Status of the ``to_resource`` (``requires-review``, ``ok``, etc.). |
| 37 | +``curation_status`` |
| 38 | + One of ``pending``, ``approved``, or ``rejected``. |
| 39 | +``confidence_level`` |
| 40 | + One of ``low``, ``medium``, ``high``, or ``verified``. |
| 41 | +``curated_by`` |
| 42 | + Username of the curator (partial match). |
| 43 | +``requires_review`` |
| 44 | + Boolean flag to return relations whose ``to_resource`` status is |
| 45 | + ``requires-review``. |
| 46 | + |
| 47 | +Example: |
| 48 | + |
| 49 | +.. code-block:: console |
| 50 | +
|
| 51 | + curl -X GET \ |
| 52 | + "http://localhost:8001/api/projects/4f3f.../relations/?curation_status=pending&requires_review=true" \ |
| 53 | + -H "Authorization: Token abc123" |
| 54 | +
|
| 55 | +Sample response: |
| 56 | + |
| 57 | +.. code-block:: json |
| 58 | +
|
| 59 | + { |
| 60 | + "count": 2, |
| 61 | + "next": null, |
| 62 | + "previous": null, |
| 63 | + "results": [ |
| 64 | + { |
| 65 | + "uuid": "f3d9cfcd-7627-478b-91cb-a2d553b79db9", |
| 66 | + "to_resource": "to/com/example/App.class", |
| 67 | + "status": "requires-review", |
| 68 | + "map_type": "java_to_class", |
| 69 | + "score": "0.87 diff_ratio: 0.12", |
| 70 | + "from_resource": "from/src/main/java/com/example/App.java", |
| 71 | + "curation_status": "pending", |
| 72 | + "confidence_level": "medium", |
| 73 | + "curation_notes": "Automated detection, needs review", |
| 74 | + "curated_by": "admin", |
| 75 | + "curated_at": "2025-11-11T06:12:48.912345Z" |
| 76 | + } |
| 77 | + ] |
| 78 | + } |
| 79 | +
|
| 80 | +Creating a relation |
| 81 | +------------------- |
| 82 | + |
| 83 | +``POST /api/projects/<uuid>/relations/`` |
| 84 | + |
| 85 | +Required fields: |
| 86 | + |
| 87 | +``from_resource_path`` |
| 88 | + Path of the source resource within the project. |
| 89 | +``to_resource_path`` |
| 90 | + Path of the target resource within the project. |
| 91 | +``map_type`` |
| 92 | + Relation category (for example ``java_to_class`` or ``checksum_match``). |
| 93 | + |
| 94 | +Optional fields: |
| 95 | + |
| 96 | +``curation_status`` ``confidence_level`` ``curation_notes`` |
| 97 | + Set initial curation metadata. When provided, an ``OriginCuration`` record |
| 98 | + is automatically created. |
| 99 | + |
| 100 | +.. code-block:: json |
| 101 | +
|
| 102 | + { |
| 103 | + "from_resource_path": "from/src/main/java/com/example/Service.java", |
| 104 | + "to_resource_path": "to/com/example/Service.class", |
| 105 | + "map_type": "java_to_class", |
| 106 | + "curation_status": "approved", |
| 107 | + "confidence_level": "high", |
| 108 | + "curation_notes": "Reviewed manually" |
| 109 | + } |
| 110 | +
|
| 111 | +Updating or deleting a relation |
| 112 | +------------------------------- |
| 113 | + |
| 114 | +``GET /api/projects/<uuid>/relations/<relation_uuid>/`` |
| 115 | +``PATCH /api/projects/<uuid>/relations/<relation_uuid>/`` |
| 116 | +``DELETE /api/projects/<uuid>/relations/<relation_uuid>/`` |
| 117 | + |
| 118 | +PATCH accepts the same payload as the creation endpoint. When curation fields |
| 119 | +change, a new ``OriginCuration`` history row is added. |
| 120 | + |
| 121 | +.. code-block:: console |
| 122 | +
|
| 123 | + curl -X PATCH \ |
| 124 | + "http://localhost:8001/api/projects/4f3f.../relations/f3d9cfcd-7627-478b-91cb-a2d553b79db9/" \ |
| 125 | + -H "Authorization: Token abc123" \ |
| 126 | + -H "Content-Type: application/json" \ |
| 127 | + -d '{"curation_status": "approved", "confidence_level": "verified"}' |
| 128 | +
|
| 129 | +Bulk curation |
| 130 | +------------- |
| 131 | + |
| 132 | +``POST /api/projects/<uuid>/relations/bulk-curate/`` |
| 133 | + |
| 134 | +Payload structure: |
| 135 | + |
| 136 | +``relation_uuids`` *(list, required)* |
| 137 | + Array of relation UUIDs to update. |
| 138 | +``action`` *(string, required)* |
| 139 | + One of ``approve``, ``reject``, ``mark_pending``, or ``set_confidence``. |
| 140 | +``confidence_level`` *(string, required when action is ``set_confidence``)* |
| 141 | + Confidence level to apply. |
| 142 | +``curation_notes`` *(string, optional)* |
| 143 | + Notes appended to each relation (preserved across updates). |
| 144 | + |
| 145 | +Example: |
| 146 | + |
| 147 | +.. code-block:: json |
| 148 | +
|
| 149 | + { |
| 150 | + "relation_uuids": [ |
| 151 | + "f3d9cfcd-7627-478b-91cb-a2d553b79db9", |
| 152 | + "a49036e2-f0c0-4104-9d9d-00ba578d72f6" |
| 153 | + ], |
| 154 | + "action": "approve", |
| 155 | + "curation_notes": "Reviewed with upstream team" |
| 156 | + } |
| 157 | +
|
| 158 | +Successful responses include the count of updated relations and per-relation |
| 159 | +history entries are written automatically. |
| 160 | + |
| 161 | +Field reference |
| 162 | +--------------- |
| 163 | + |
| 164 | +Returned ``CodebaseRelation`` objects contain: |
| 165 | + |
| 166 | +``uuid`` |
| 167 | + Stable identifier for the relation. |
| 168 | +``from_resource`` ``to_resource`` |
| 169 | + Resource paths represented as strings. |
| 170 | +``map_type`` |
| 171 | + Relation mapping category. |
| 172 | +``status`` |
| 173 | + The ``to_resource.status`` value, exposed for convenience. |
| 174 | +``score`` |
| 175 | + Human-readable hint compiled from ``extra_data`` (for example similarity |
| 176 | + or diff metrics). Blank when no score is available. |
| 177 | +``curation_status`` ``confidence_level`` ``curation_notes`` |
| 178 | + Latest curation metadata. |
| 179 | +``curated_by`` ``curated_at`` |
| 180 | + Username and timestamp of the most recent curation update. |
| 181 | + |
| 182 | +Error handling |
| 183 | +-------------- |
| 184 | + |
| 185 | +Errors return a JSON object with a ``message`` key and the HTTP status code |
| 186 | +appropriate to the failure (400 for validation issues, 404 when a relation |
| 187 | +cannot be found, etc.). Examples: |
| 188 | + |
| 189 | +.. code-block:: json |
| 190 | +
|
| 191 | + { |
| 192 | + "message": "relation_uuids is required." |
| 193 | + } |
| 194 | +
|
| 195 | + { |
| 196 | + "message": { |
| 197 | + "from_resource_path": ["Resource not found: from/src/missing.java"] |
| 198 | + } |
| 199 | + } |
| 200 | +
|
| 201 | +
|
| 202 | +
|
| 203 | +
|
0 commit comments