-
Notifications
You must be signed in to change notification settings - Fork 4
feat(spp_api_v2): OpenAPI polymorphic bodies, OAuth2 scheme in auth middleware, bundle schemas (re-land from #76) #276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gonzalesedwin1123
wants to merge
2
commits into
19.0
Choose a base branch
from
reland/api-v2-core
base: 19.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+527
−21
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Part of OpenSPP. See LICENSE file for full copyright and licensing details. | ||
| """OpenAPI-shape tests for the Bundle schema. | ||
|
|
||
| Asserts that `BundleEntry.resource` documents its accepted resource types | ||
| (Individual, Group) via `oneOf` of $refs instead of a bare `dict | None`. | ||
| """ | ||
|
|
||
| from odoo.tests.common import HttpCase, tagged | ||
|
|
||
|
|
||
| @tagged("post_install", "-at_install") | ||
| class TestBundleEntryOpenAPI(HttpCase): | ||
| """Bundle schema renders polymorphic resource documentation.""" | ||
|
|
||
| def test_bundle_entry_resource_documented_as_oneof(self): | ||
| """BundleEntry.resource should document oneOf of supported FHIR types. | ||
|
|
||
| Bundle service only supports Individual and Group (see | ||
| spp_api_v2/services/bundle_service.py:299, 324, 350); anything else | ||
| is rejected at runtime, so oneOf must list exactly those. | ||
| """ | ||
| response = self.url_open("/api/v2/spp/openapi.json") | ||
| self.assertEqual(response.status_code, 200, response.text) | ||
| schema = response.json() | ||
| components = schema["components"]["schemas"] | ||
|
|
||
| self.assertIn("BundleEntry", components) | ||
| resource_schema = components["BundleEntry"]["properties"]["resource"] | ||
|
|
||
| # Spike-confirmed shape: for `dict | None = polymorphic_body(...)`, | ||
| # Pydantic emits `anyOf: [{type: object}, {type: null}]` and our hook | ||
| # attaches `oneOf` at the SAME top level (siblings, not nested). | ||
| self.assertIn("oneOf", resource_schema, f"no oneOf at top level: {resource_schema}") | ||
| refs = [item.get("$ref") for item in resource_schema["oneOf"]] | ||
| self.assertIn("#/components/schemas/Individual", refs) | ||
| self.assertIn("#/components/schemas/Group", refs) | ||
|
|
||
| # And the nullable shape comes from anyOf alongside. | ||
| self.assertIn( | ||
| {"type": "null"}, | ||
| resource_schema.get("anyOf", []), | ||
| f"missing nullable anyOf branch: {resource_schema}", | ||
| ) | ||
|
|
||
| # Both referenced models must actually be present in components. | ||
| self.assertIn("Individual", components) | ||
| self.assertIn("Group", components) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Part of OpenSPP. See LICENSE file for full copyright and licensing details. | ||
| """Contract test: every $ref in the OpenAPI schema must resolve. | ||
|
|
||
| Catches the failure mode where polymorphic_body declares a oneOf of $refs | ||
| but the referenced model isn't registered or the OpenAPI hook isn't | ||
| installed. | ||
| """ | ||
|
|
||
| from odoo.tests.common import HttpCase, tagged | ||
|
|
||
|
|
||
| @tagged("post_install", "-at_install") | ||
| class TestOpenAPIContract(HttpCase): | ||
| """Walk the live OpenAPI schema; assert every $ref resolves.""" | ||
|
|
||
| def test_all_refs_resolve(self): | ||
| response = self.url_open("/api/v2/spp/openapi.json") | ||
| self.assertEqual(response.status_code, 200, response.text) | ||
| schema = response.json() | ||
| components = schema.get("components", {}).get("schemas", {}) | ||
|
|
||
| unresolved = [] | ||
|
|
||
| def walk(node, path): | ||
| if isinstance(node, dict): | ||
| ref = node.get("$ref") | ||
| if isinstance(ref, str) and ref.startswith("#/components/schemas/"): | ||
| name = ref.rsplit("/", 1)[-1] | ||
| if name not in components: | ||
| unresolved.append((path, ref)) | ||
| for k, v in node.items(): | ||
| walk(v, f"{path}.{k}") | ||
| elif isinstance(node, list): | ||
| for i, v in enumerate(node): | ||
| walk(v, f"{path}[{i}]") | ||
|
|
||
| walk(schema, "$") | ||
|
|
||
| self.assertEqual( | ||
| unresolved, | ||
| [], | ||
| "Unresolved $refs in OpenAPI schema. Either install_polymorphic_openapi_hook " | ||
| "is not wired, or a polymorphic_body() references a model not in components/schemas.\n" | ||
| f"Found: {unresolved[:5]}", | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slicing the token with
token[7:]when stripping the"bearer "prefix can leave leading or trailing whitespace if the client sent multiple spaces (e.g.,"Bearer eyJ..."). This can cause JWT decoding to fail.Applying
.strip()ensures that any extra whitespace is safely removed.