Aalexbit-codemod

openapi-post-to-query

Convert OpenAPI 3.2 POST operations to query when they are read-like (search, filter, list) rather than mutations. Conservative transforms plus needs-review annotations.

upgradestandardizationopenapiapi-design
Public
6 executions
2 stars
How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

Documentation

openapi-post-to-query

Convert OpenAPI 3.2 POST operations to query when they are read-like (search, filter, list) rather than mutations. Uses conservative, high-confidence transforms plus a "needs review" bucket via x-codemod-suggestion annotations.

Problem

In OpenAPI 3.2, query is the right verb for operations that:

  • Are safe (no server state change)
  • Are idempotent (same input → same effect)
  • Need a payload for complex filter criteria that don't fit in query params

Many APIs incorrectly use POST for search/filter/list endpoints. This codemod identifies and converts them.

Solution

  • Auto-convert when confidence score ≥ 7 and no mutation signals
  • Annotate when score 4–6 with x-codemod-suggestion: "convert-post-to-query (score=X: reason)"
  • Skip when mutation signals (201, Location, action verbs, etc.) or low score

Usage

bash

Or run the transform directly:

bash

Params

ParamTypeDefaultDescription
convert_thresholdnumber7Min score to auto-convert POST → query
annotate_thresholdnumber4Min score to add x-codemod-suggestion
commit_per_stepbooleanfalseCommit after each change-producing step
run_ai_stepbooleanfalseRun AI step for ambiguous cases
publish_prbooleanfalsePush branch and create PR (off by default)
main_branchstringmainTarget branch for PR
api_tokenstringGitHub API token when gh CLI unavailable
pr_titlestringOptional PR title
pr_bodystringOptional PR body

Metrics

  • openapi-post-to-query:
    • action: convert — POST converted to query (high confidence)
    • action: annotatex-codemod-suggestion added (needs review)
    • action: skip — not converted (hard block or low score)
    • reason — short explanation of signals

Tricky Cases (when to use run_ai_step=true)

  1. Ambiguous endpoints — POST with mixed read/mutation semantics
  2. Async job patterns — 202 with jobId/taskId (codemod skips, but review)
  3. Custom naming — operationIds or paths that don't match standard patterns

What Gets Fixed

Automated (high confidence)

  • post:query: when operationId matches search|query|filter|list|find|lookup|scan, path contains /search|/query|/filter, response has items/results/data, requestBody has filter keys, and only 200/206 responses

Annotated (needs review)

  • x-codemod-suggestion added when score 4–6; human/tooling decides

Skipped

  • 201, Location header, action verbs in description, mutation path patterns (/actions/, /execute, /run, etc.), mutation body keys (password, token, charge, etc.)

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.