Skip to content

fix(api): accept an empty body on the AI analysis trigger - #523

Merged
M0Rf30 merged 1 commit into
openartifact:mainfrom
kocagozhkn:fix/ai-trigger-empty-body
Nov 26, 2026
Merged

M0Rf30 merged 1 commit into
openartifact:mainfrom
kocagozhkn:fix/ai-trigger-empty-body

Conversation

@kocagozhkn

Copy link
Copy Markdown
Contributor

Fixes #508.

POST /api/v1/repositories/{name}/ai-analysis/{artifactID}/trigger answered 400 invalid JSON body for a request without a body, although every body field is optional and the first example in docs/integrations/ai-analysis.md sends none. decodeJSON returns io.EOF for an empty body and the handler treated any error as bad JSON.

The handler now treats io.EOF as "no fields", the same way the other optional-body handlers do (admin_gpg.go, admin_signing_key.go, docker_gc.go, bundles.go). Malformed JSON is still rejected with 400.

Tests

Three cases added to TestAITriggerWithoutManifestText:

  • no body, stored artifact: 202
  • no body, unknown artifact: 404
  • malformed body ({): 400

The first two fail on main with 400 and pass with the change. go test -short -race ./internal/api/, go vet (with and without -tags noai) and golangci-lint v2.15.0 on ./internal/api/... pass locally; I did not run the full make test / make check.

The trigger body is documented as optional and the first example in
docs/integrations/ai-analysis.md sends none, but the handler answered
400 "invalid JSON body" because decodeJSON returns io.EOF for an empty
body. Treat io.EOF as "no fields", as the other optional-body handlers
do. Malformed JSON is still rejected.

Fixes openartifact#508
@M0Rf30 M0Rf30 mentioned this pull request Nov 26, 2026
@M0Rf30
M0Rf30 merged commit 6c6a5aa into openartifact:main Nov 26, 2026
23 checks passed
@M0Rf30 M0Rf30 mentioned this pull request Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI analysis trigger rejects an empty body with 400 although the body is documented as optional (doc example fails)

2 participants