Skip to content

Align entity write endpoints with request bodies + author entity resource in OpenAPI spec#151

Merged
dmccoystephenson merged 3 commits into
mainfrom
feature/entity-request-bodies
Jun 14, 2026
Merged

Align entity write endpoints with request bodies + author entity resource in OpenAPI spec#151
dmccoystephenson merged 3 commits into
mainfrom
feature/entity-request-bodies

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

  • Switches the entity write endpoints off the path-variable anti-pattern onto request-body DTOs, mirroring the already-aligned environment endpoints:
    • POST /api/v1/entities/{name}POST /api/v1/entities with a CreateEntityRequest body.
    • PATCH /api/v1/entities/{id}/name/{name}PATCH /api/v1/entities/{id}/name with an UpdateEntityNameRequest body.
  • Adds CreateEntityRequest / UpdateEntityNameRequest DTOs with @NotBlank validation (mirrors CreateEnvironmentRequest / UpdateEnvironmentNameRequest).
  • Authors the entity resource in docs/openapi/viron-api.json — it previously had no entity paths at all. Added all entity paths (list, by-id, by-environment/grid/location, unassigned, create, delete, rename) plus the two request schemas, and added the missing creationDate field to EntityDTO.
  • Corrects the environment POST response status in the spec from 200 to 201 to match the controller's @ResponseStatus(CREATED) (spec discrepancy explicitly tracked under Align entity write endpoints with request bodies + add entity resource to OpenAPI spec #135).
  • Updates the Python client (entityService) to send JSON bodies for create/rename, keeping the Java and Python clients parallel.

Test plan

  • mvn test (Java 21) — passes; EntityControllerTest updated to body-based requests + added blank-name validation tests for both write endpoints (now inherit @WithMockUser from the Endpoints are unauthenticated over plain HTTP; RFC 0001 specifies JWT auth over HTTPS #149 auth merge).
  • pytest (Python 3.11) — 80 passed; test_entityService updated to assert JSON-body calls.
  • DTO boundary preserved (controller returns EntityDto only); endpoints now match the spec.

Notes

Closes #135

@dmccoystephenson dmccoystephenson left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Self-review rubric (adversarial; CI is green on head as the external anchor):

Universal

  • Scope: PASS — all 8 files serve #135 (entity write endpoints + entity resource in spec + the doc/test reflections). The one cross-resource line (env POST 200→201) is flagged inline as a judgment call.
  • Tests-new: PASS — both changed write methods are exercised (createEntity_ReturnsCreated, updateEntityName_Success) and two new validation tests (createEntity_BlankName_ReturnsBadRequest, updateEntityName_BlankName_ReturnsBadRequest) cover the new @Valid behavior.
  • Tests-fix: N/A — refactor, not a bug fix; new validation behavior is nonetheless covered.
  • Sibling structure: PASS — CreateEntityRequest/UpdateEntityNameRequest mirror CreateEnvironmentRequest/UpdateEnvironmentNameRequest byte-for-byte in shape.
  • Sibling renames: PASS — entity write endpoints brought in line with the already-aligned environment pair (#137).
  • Docs: PASS — MVP.md line 57 (which explicitly tracked #135) marked implemented; spec authored; tickets.md/README/PLANNING/REBUILD_PLAN verified accurate. The stale Postman collection is the separate issue #136, deliberately untouched.
  • Issue resolution: PASS — #135's named surface (entity write endpoints + 'add entity resource to viron-api.json') is fully changed.
  • CI: PASS — build green on head c460b86.

Repo-specific

  • DTO boundary: PASS — createEntity returns EntityDto via mapper; no internal model exposed.
  • Spec alignment: PASS — every added entity path matches the controller (DELETE→204, POST→201, PATCH→200, relation GETs with correctly-named path params).
  • Java/Python parallelism: PASS — entityService create_entity/update_entity_name updated to JSON bodies to match Java; both test surfaces updated and green (mvn test exit 0; pytest 80 passed on py3.11).
  • Override correctness: N/A — no @OverRide added.

One non-blocking observation left inline. Not auto-merging: this PR edits the wire contract (docs/openapi/viron-api.json), which is on the do-not-auto-merge list — handing to a human reviewer.

},
"responses": {
"200": {
"201": {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Judgment call (not part of the entity surface): changed the environment POST response from 200 to 201 to match the controller's @ResponseStatus(HttpStatus.CREATED). This spec discrepancy was explicitly tracked under #135's "Related spec discrepancy" note, so it's included here rather than left dangling. Flagging in case a reviewer prefers it split into its own change.

@dmccoystephenson

Copy link
Copy Markdown
Member Author

Triage / skip reasons for this cycle (for auditability)

Picked: #135 (this PR). Deferred this cycle:

drafted by Claude on behalf of Daniel Stephenson

dmccoystephenson and others added 3 commits June 13, 2026 21:47
…urce in OpenAPI spec

- Switch POST /api/v1/entities and PATCH /api/v1/entities/{id}/name to
  @Valid @RequestBody DTOs (CreateEntityRequest, UpdateEntityNameRequest),
  mirroring the environment endpoints; drops the path-variable anti-pattern.
- Add the full entity resource to docs/openapi/viron-api.json (all GET/POST/
  DELETE/PATCH paths + request/response schemas); add creationDate to EntityDTO.
- Correct the environment POST response status in the spec from 200 to 201 to
  match the controller's @ResponseStatus(CREATED) (tracked under #135).
- Update the Python client (entityService) to send JSON bodies, and update both
  Java MockMvc and Python tests; add blank-name validation tests.

Closes #135

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…y endpoints

The in-repo Java client called the old path-variable endpoints
(POST /entities/{name}, PATCH /entities/{id}/name/{name}); align it with the
new request-body form so the Java and Python clients stay parallel.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dmccoystephenson dmccoystephenson force-pushed the feature/entity-request-bodies branch from 2d4d64f to 1d09451 Compare June 14, 2026 03:48
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Update: rebased onto latest main (now includes #150 JWT auth and #152 entity-movement/occupancy) and added one fix found during self-audit:

  • The in-repo Java client SDK (services/EntityService.java) was still calling the old path-variable endpoints (POST /entities/{name}, PATCH /entities/{id}/name/{name}). Updated it to send CreateEntityRequest / UpdateEntityNameRequest bodies, mirroring EnvironmentService — so the Java and Python clients are both aligned (closes the gap flagged by viron-dev-loop#6).

CI green on the rebased head. Still not auto-merging — this PR edits the wire contract (docs/openapi/viron-api.json), so it's handed off for human review.

drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson dmccoystephenson merged commit 73ab641 into main Jun 14, 2026
1 check passed
@dmccoystephenson dmccoystephenson deleted the feature/entity-request-bodies branch June 14, 2026 03:54
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.

Align entity write endpoints with request bodies + add entity resource to OpenAPI spec

1 participant