Repository navigation
fix: validate template resourceType against endpoint resource type - #5330
अनुक्रमा पौड्याल (AnukramaPoudyal) wants to merge 1 commit into
Conversation
Signed-off-by: AnukramaPoudyal <87685960+AnukramaPoudyal@users.noreply.github.com>
|
अनुक्रमा पौड्याल (@AnukramaPoudyal) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
There was a problem hiding this comment.
🟡 Changes recommended
The missing API version bump will cause the Docker build’s stale-version check to fail before API tests run, and the required changelog entry is also absent.
2 open issues
What changed in this PR
This PR addresses #1123 by validating template resource types during API registration, preventing mismatched template payloads from being accepted by an endpoint.
Changes:
- Adds an optional
resourceTypefield while preserving support for payloads that omit it. - Rejects supplied resource types that differ from the endpoint’s expected type.
- Adds parameterized tests for workspace/workspace-service mismatches in both directions.
| File | Description |
|---|---|
api_app/tests_ma/test_db/test_repositories/test_resource_templates_repository.py |
Tests that mismatched resource types raise InvalidInput. |
api_app/models/schemas/resource_template.py |
Adds the optional, enum-typed resourceType field. |
api_app/db/repositories/resource_templates.py |
Validates resource type before version lookup and registration. |
Review effort: Balanced
| Updates the current version for the template | ||
| Saves to the database and returns the enriched template | ||
| """ | ||
| if template_input.resourceType is not None and template_input.resourceType != resource_type: |
| raise InvalidInput( | ||
| f"Invalid template - resourceType '{template_input.resourceType.value}' does not match expected '{resource_type.value}'" | ||
| ) |


Adds optional
esourceType\ to \ResourceTemplateInCreate\ and validates it against the expected \ResourceType\ in \ResourceTemplateRepository.create_and_validate_template, raising \InvalidInput\ (HTTP 422) when a mismatched template payload is posted (e.g., posting a workspace-service template to the workspace-templates endpoint).
Adds unit tests in \�pi_app/tests_ma/test_db/test_repositories/test_resource_templates_repository.py.
Fixes #1123