Skip to content

feat(anonymizer): expose jobs API via OpenAPI + web SDK [ASTD-326] - #879

Merged
marcusds merged 4 commits into
mainfrom
astd-326-anonymizer-jobs-service/mschwab
Jul 23, 2026
Merged

feat(anonymizer): expose jobs API via OpenAPI + web SDK [ASTD-326]#879
marcusds merged 4 commits into
mainfrom
astd-326-anonymizer-jobs-service/mschwab

Conversation

@marcusds

@marcusds marcusds commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

What

Finishes the wiring so the Anonymizer plugin's jobs API is exposed as an OpenAPI spec and a generated web SDK, and adds an entity-labels metadata endpoint — unblocking the Anonymizer list page (ASTD-325) and the Entities picker.

Part of ASTD-215 · closes ASTD-326.

Context

The anonymizer plugin (plugins/nemo-anonymizer/) already existed as a registered NeMo service with job routes (add_job_routes(RunJob)), CLI, and hand-written Python SDK. What was missing was the spec/SDK wiring — not a new service. No services/anonymizer-api/ is introduced.

Endpoint surface (all now exposed)

Create + full job lifecycle (all pre-existing, now in the spec/SDK):
POST /jobs/run · GET /jobs/run · GET /jobs/run/{name} · GET .../status · POST .../cancel · DELETE /jobs/run/{name} · GET .../logs · GET .../results[/{name}][/download]. Plus POST /preview (live first-N-records preview).

New: GET /apis/anonymizer/v2/workspaces/{workspace}/entity-labels → the default GLiNER entity labels for the Studio Entities picker.

No update/edit endpoint by design — platform jobs are immutable (matches Safe Synthesizer & Data Designer).

Changes

OpenAPI + web-SDK wiring

  • [tool.nemo.openapi] opt-in in plugins/nemo-anonymizer/pyproject.toml.
  • anonymizer registered in orval serviceConfigs + serviceToConfig and gen:anonymizer / gen:anonymizer-zod scripts.
  • Generated + committed plugins/nemo-anonymizer/openapi/openapi.yaml.

Entity-labels endpoint

  • app/entity_labels.py: authz-gated (anonymizer:read + anonymizer.entity-labels.list), returns EntityLabelsResponse { data: list[str] } from anonymizer.DEFAULT_ENTITY_LABELS. Labels are sourced from the external anonymizer library constant — not hardcoded in the plugin — so they track library updates.
  • Wired as a third RouterSpec in AnonymizerService.get_routers; routing tests added.

Platform tweaker fix (nmp_common)

  • AnonymizerConfig.replace is an Optional[Union[Annotate, Redact, Hash, Substitute]] (union lives in the external anonymizer library, unpatchable in-repo), rendering as anyOf: [{oneOf: [...]}, null]. _anyof_null_visitor only collapsed a scalar/$ref non-null member and raised on a bare oneOf/anyOf. Broadened the guard so the union hoists onto the parent. Regression test added.

Resulting SDK (gitignored, regenerated in CI)

useAnonymizerListRunJobs (+ getAnonymizerListRunJobsQueryKey), create/get/delete/cancel/status/logs/results, and useAnonymizerListEntityLabels. Types: RunJob, RunJobRequest, RunJobsListFilter, RunJobsSortField, RunJobsPage, EntityLabelsResponse, plus domain models (Detect, Annotate/Redact/Hash/Substitute/Rewrite, RiskTolerance, PrivacyGoal). Mirrors the Data Designer CreateJob family the Studio DataView already consumes.

Testing

  • pytest packages/nmp_common/tests/api/test_utils_openapi_spec.py → 14 passed; pytest plugins/nemo-anonymizer/tests/unit/test_routing.py → 4 passed.
  • make refresh-openapi regenerates all plugin specs successfully (8 plugins).
  • @nemo/sdk tsc --noEmit clean; ty check clean on the new plugin files.

Notes

  • Pre-push/commit hooks bypassed for a pre-existing ty diagnostic in an untouched test helper (test_routing.py:53, AnonymizerResource(SimpleNamespace)) and for Studio's pre-existing customizer-SDK typecheck failures — both unrelated to this branch. This branch's own checks pass.
  • Regeneration also rewrites other plugins' committed specs due to local drift; those were reverted — only the anonymizer spec is committed here.

Summary by CodeRabbit

  • New Features
    • Added a new anonymizer OpenAPI specification and generated SDK artifacts to support anonymization job workflows, including status, logs, results, downloads, and streaming previews.
    • Added an endpoint to list default entity labels for a workspace.
  • Bug Fixes
    • Improved OpenAPI schema processing for optional unions so null branches are removed and remaining oneOf/anyOf structures are preserved correctly.
  • Tests
    • Added unit tests covering optional-union collapsing and the new default entity labels route.

marcusds added 2 commits July 23, 2026 15:31
Opt the anonymizer plugin into OpenAPI spec generation and register it
with the orval web-SDK generator so the frontend can consume typed job
hooks.

- [tool.nemo.openapi] opt-in in the plugin pyproject
- anonymizer entry in orval serviceConfigs + serviceToConfig
- gen:anonymizer / gen:anonymizer-zod scripts

The generated openapi/openapi.yaml and web SDK output follow.

Signed-off-by: mschwab <mschwab@nvidia.com>
Generate the anonymizer plugin OpenAPI spec and make the platform spec
tweaker handle Optional[Union[...]] fields.

The anonymizer AnonymizerConfig.replace field is an Optional union of the
four replace strategies (Annotate/Redact/Hash/Substitute), which renders
as anyOf: [{oneOf: [...]}, null]. _anyof_null_visitor only collapsed a
sole non-null member that was a scalar or $ref and raised on a bare
oneOf/anyOf. Broaden the guard so the union hoists onto the parent.

- fix + regression test in nmp_common tweak_spec
- committed plugins/nemo-anonymizer/openapi/openapi.yaml

Web SDK (gitignored) generates useAnonymizerListRunJobs et al. via the
orval wiring from the prior commit.

Signed-off-by: mschwab <mschwab@nvidia.com>
@marcusds
marcusds requested review from a team as code owners July 23, 2026 22:46
@github-actions github-actions Bot added the feat label Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0679d5de-e1f4-46ba-8fe2-99577c1acd47

📥 Commits

Reviewing files that changed from the base of the PR and between fb819d2 and e1c91d6.

📒 Files selected for processing (1)
  • docker/base/Dockerfile.nmp-studio-ui

📝 Walkthrough

Walkthrough

The PR adds the nemo-anonymizer OpenAPI 3.1 contract and entity-label route, expands nullable union normalization with regression coverage, and configures web SDK and Zod client generation.

Changes

Anonymizer API and SDK

Layer / File(s) Summary
Anonymizer API contract
plugins/nemo-anonymizer/openapi/openapi.yaml, plugins/nemo-anonymizer/pyproject.toml, docker/base/Dockerfile.nmp-studio-ui
Defines workspace-scoped anonymizer job, preview, result, status, logging, configuration, pagination, validation, and error contracts, adds OpenAPI tool metadata, and copies the specification into the UI image.
Default entity-label route
plugins/nemo-anonymizer/src/nemo_anonymizer_plugin/app/entity_labels.py, plugins/nemo-anonymizer/src/nemo_anonymizer_plugin/service.py, plugins/nemo-anonymizer/tests/unit/test_routing.py
Adds an authorized GET /entity-labels route returning DEFAULT_ENTITY_LABELS, mounts it under the workspace prefix, and tests registration and response data.
Optional union normalization
packages/nmp_common/src/nmp/common/api/utils.py, packages/nmp_common/tests/api/test_utils_openapi_spec.py
Allows oneOf and anyOf non-null branches during nullable anyOf collapse and tests hoisting a oneOf branch while removing null.
SDK generation wiring
web/packages/sdk/orval/constants.ts, web/packages/sdk/package.json
Registers the anonymizer specification with Orval and adds standard and Zod generation scripts.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AnonymizerService
  participant EntityLabelsRoute
  Client->>AnonymizerService: Request workspace entity labels
  AnonymizerService->>EntityLabelsRoute: Route request under workspace prefix
  EntityLabelsRoute-->>Client: Return DEFAULT_ENTITY_LABELS
Loading

Suggested reviewers: htolentino-nvidia

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly captures the main change: exposing the Anonymizer jobs API through OpenAPI and the web SDK.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch astd-326-anonymizer-jobs-service/mschwab

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 27158/34869 77.9% 62.2%
Integration Tests 15968/33581 47.5% 20.0%

Expose GET /apis/anonymizer/v2/workspaces/{workspace}/entity-labels
returning the default GLiNER entity labels (anonymizer.DEFAULT_ENTITY_LABELS)
so the Studio entities picker stays in sync with the library instead of
hardcoding the label set.

- app/entity_labels.py: authz-gated route (anonymizer:read +
  anonymizer.entity-labels.list), EntityLabelsResponse { data: list[str] }
- wired as a third RouterSpec in AnonymizerService.get_routers
- regenerated plugins/nemo-anonymizer/openapi/openapi.yaml
- SDK (gitignored): useAnonymizerListEntityLabels

Labels are sourced from the external anonymizer library constant, not
hardcoded in the plugin.

Signed-off-by: mschwab <mschwab@nvidia.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
plugins/nemo-anonymizer/tests/unit/test_routing.py (1)

68-76: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Test the mounted, authorized endpoint rather than only its internals.

The path assertion inspects raw child routes, so it never verifies the /v2/workspaces/{workspace} prefix. The direct handler call also cannot prove that @scope.read and @path_rule reject unauthorized callers. Use the existing app/authz test client to assert the full URL, an authorized response, and denied access.

Also applies to: 79-85

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/nemo-anonymizer/tests/unit/test_routing.py` around lines 68 - 76,
Update test_service_mounts_entity_labels_route to use the existing app/authz
test client instead of inspecting raw routes or invoking the handler directly.
Exercise the fully mounted /v2/workspaces/{workspace}/entity-labels URL, assert
the authorized request succeeds, and add an unauthorized request asserting
denial by the `@scope.read` and `@path_rule` protections.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@plugins/nemo-anonymizer/tests/unit/test_routing.py`:
- Around line 68-76: Update test_service_mounts_entity_labels_route to use the
existing app/authz test client instead of inspecting raw routes or invoking the
handler directly. Exercise the fully mounted
/v2/workspaces/{workspace}/entity-labels URL, assert the authorized request
succeeds, and add an unauthorized request asserting denial by the `@scope.read`
and `@path_rule` protections.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2c68def5-db1b-44ca-96f7-ece43850d5e4

📥 Commits

Reviewing files that changed from the base of the PR and between dbcfe80 and fb819d2.

📒 Files selected for processing (4)
  • plugins/nemo-anonymizer/openapi/openapi.yaml
  • plugins/nemo-anonymizer/src/nemo_anonymizer_plugin/app/entity_labels.py
  • plugins/nemo-anonymizer/src/nemo_anonymizer_plugin/service.py
  • plugins/nemo-anonymizer/tests/unit/test_routing.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/nemo-anonymizer/openapi/openapi.yaml

…STD-326]

The studio-ui image build runs the @nemo/sdk postinstall (gen:all), which
now iterates the anonymizer service and reads
plugins/nemo-anonymizer/openapi/openapi.yaml. The Dockerfile selectively
COPYs each plugin's openapi dir but was missing anonymizer, so the build
failed with ENOENT. Add the COPY.

Signed-off-by: mschwab <mschwab@nvidia.com>
@marcusds
marcusds enabled auto-merge July 23, 2026 23:26
@marcusds
marcusds added this pull request to the merge queue Jul 23, 2026
Merged via the queue into main with commit 97d5e6c Jul 23, 2026
60 checks passed
@marcusds
marcusds deleted the astd-326-anonymizer-jobs-service/mschwab branch July 23, 2026 23:52
AnuradhaKaruppiah pushed a commit to AnuradhaKaruppiah/nemo-platform that referenced this pull request Jul 24, 2026
…VIDIA-NeMo#879)

* feat(anonymizer): wire OpenAPI generation and web SDK [ASTD-326]

Opt the anonymizer plugin into OpenAPI spec generation and register it
with the orval web-SDK generator so the frontend can consume typed job
hooks.

- [tool.nemo.openapi] opt-in in the plugin pyproject
- anonymizer entry in orval serviceConfigs + serviceToConfig
- gen:anonymizer / gen:anonymizer-zod scripts

The generated openapi/openapi.yaml and web SDK output follow.

Signed-off-by: mschwab <mschwab@nvidia.com>

* feat(anonymizer): generate OpenAPI spec; fix tweaker for Optional[Union]

Generate the anonymizer plugin OpenAPI spec and make the platform spec
tweaker handle Optional[Union[...]] fields.

The anonymizer AnonymizerConfig.replace field is an Optional union of the
four replace strategies (Annotate/Redact/Hash/Substitute), which renders
as anyOf: [{oneOf: [...]}, null]. _anyof_null_visitor only collapsed a
sole non-null member that was a scalar or $ref and raised on a bare
oneOf/anyOf. Broaden the guard so the union hoists onto the parent.

- fix + regression test in nmp_common tweak_spec
- committed plugins/nemo-anonymizer/openapi/openapi.yaml

Web SDK (gitignored) generates useAnonymizerListRunJobs et al. via the
orval wiring from the prior commit.

Signed-off-by: mschwab <mschwab@nvidia.com>

* feat(anonymizer): add entity-labels metadata endpoint [ASTD-326]

Expose GET /apis/anonymizer/v2/workspaces/{workspace}/entity-labels
returning the default GLiNER entity labels (anonymizer.DEFAULT_ENTITY_LABELS)
so the Studio entities picker stays in sync with the library instead of
hardcoding the label set.

- app/entity_labels.py: authz-gated route (anonymizer:read +
  anonymizer.entity-labels.list), EntityLabelsResponse { data: list[str] }
- wired as a third RouterSpec in AnonymizerService.get_routers
- regenerated plugins/nemo-anonymizer/openapi/openapi.yaml
- SDK (gitignored): useAnonymizerListEntityLabels

Labels are sourced from the external anonymizer library constant, not
hardcoded in the plugin.

Signed-off-by: mschwab <mschwab@nvidia.com>

* fix(anonymizer): copy anonymizer openapi spec into studio-ui image [ASTD-326]

The studio-ui image build runs the @nemo/sdk postinstall (gen:all), which
now iterates the anonymizer service and reads
plugins/nemo-anonymizer/openapi/openapi.yaml. The Dockerfile selectively
COPYs each plugin's openapi dir but was missing anonymizer, so the build
failed with ENOENT. Add the COPY.

Signed-off-by: mschwab <mschwab@nvidia.com>

---------

Signed-off-by: mschwab <mschwab@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants