Skip to content

feat(slicing): extract HttpStatus enum constants from ResponseEntity patterns#244

Open
abdul-levo wants to merge 1 commit intoAppThreat:mainfrom
abdul-levo:feat/emit-httpstatus-response-codes
Open

feat(slicing): extract HttpStatus enum constants from ResponseEntity patterns#244
abdul-levo wants to merge 1 commit intoAppThreat:mainfrom
abdul-levo:feat/emit-httpstatus-response-codes

Conversation

@abdul-levo
Copy link
Contributor

@abdul-levo abdul-levo commented Mar 13, 2026

Summary

  • Adds httpStatusFieldAccessSlices to extract HttpStatus.XXX enum field
    accesses from controller method bodies (e.g., HttpStatus.BAD_REQUEST,
    HttpStatus.UNAUTHORIZED)
  • Emits them as additional ObjectUsageSlice entries with
    resolvedMethod: "org.springframework.http.HttpStatus.BAD_REQUEST" etc.
  • Enables downstream tools (atom-tools) to generate OpenAPI specs with
    multiple response codes per endpoint instead of only the default 200/201

Test plan

  • sbt stage compiles successfully
  • Run atom on a Spring Boot project with HttpStatus usage
  • Verifed slices.json contains entries like "resolvedMethod": "org.springframework.http.HttpStatus.BAD_REQUEST"
  • Verified existing PARAM/CALL/ANNOTATION entries are unchanged
@prabhu
Copy link
Contributor

prabhu commented Mar 17, 2026

@abdul-levo could you rebase and fix the conflict?

@abdul-levo abdul-levo force-pushed the feat/emit-httpstatus-response-codes branch from ee10738 to 3c1620e Compare March 18, 2026 08:03
method: Method,
typeMap: Map[String, String]
): List[(Method, ObjectUsageSlice)] =
method.ast.isCall
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace method.ast.isCall with method.call. In general, going down the ast layer and trying to come back up will be too slow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Replaced method.ast.isCall with method.call and added .methodFullName(".HttpStatus.") regex filter

val fieldId = call.argument.collectFirst { case fi: FieldIdentifier => fi }
val isHttpStatus = call.argument.exists {
case id: Identifier =>
id.typeFullName.contains("HttpStatus") || id.name == "HttpStatus"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this query will be too slow and can be rewritten using regex. Can you share the below document with claude and ask it to rewrite? Also tell claude this is atom-chen and not joern.

https://github.com/AppThreat/chen/blob/main/docs/TRAVERSAL.md

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewritten. Removed the manual call.argument.exists check and replaced with .methodFullName(".HttpStatus.") regex at the query level.

@prabhu
Copy link
Contributor

prabhu commented Mar 18, 2026

Can you share the repo and what values are needed in the slice? Probably best done in chen directly instead since this query will make every usage slicing quite slow.

Extract HttpStatus.XXX static field accesses (e.g., BAD_REQUEST, UNAUTHORIZED) from method bodies and emit them as additional ObjectUsageSlice entries. This enables downstream tools to infer multiple HTTP response codes per endpoint for OpenAPI generation.
@abdul-levo abdul-levo force-pushed the feat/emit-httpstatus-response-codes branch from 3c1620e to 00866f5 Compare March 18, 2026 14:58
@abdul-levo
Copy link
Contributor Author

abdul-levo commented Mar 18, 2026

Can you share the repo and what values are needed in the slice? Probably best done in chen directly instead since this query will make every usage slicing quite slow.

The values needed in the slice are the HttpStatus enum constant names (e.g., BAD_REQUEST, UNAUTHORIZED) so downstream tools can map them to response codes in OpenAPI specs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants