-
Notifications
You must be signed in to change notification settings - Fork 204
feat: Removed python schema files & support JSON Schema uploads and updates to related deployment scripts #566
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
677fa9c
feat(schemavault): accept JSON Schema uploads alongside legacy .py
d0139e0
feat(schemavault): convert remaining sample schemas to JSON; register…
1fb797f
feat(schemavault): switch default samples and deployment scripts to .…
6cb8cf9
fix(deps): add jsonschema==4.25.1 to pyproject.toml and refresh uv.lock
6b37de5
feat(schemavault)!: remove legacy .py schema path (RCE remediation)
c33918e
Merge remote-tracking branch 'origin/dev' into feature/json-schema-su…
9b9f0c2
fix: Copilot comments
e8b2fae
fix: Fixed copilot comments
87a7108
fix: Updated unit tests
7244f95
refactore: Removed unused headers
22cd514
updated uv.lock
b341a93
refactore: removed unused files
fa465a9
fix: Fixed copilot comments
37d338b
fix: Updated documentation for JSON schema files
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """Convert a legacy Pydantic ``.py`` schema into a declarative ``.json`` schema. | ||
|
|
||
| This helper is part of the migration away from executable Python schemas. | ||
| It imports a Pydantic model from a ``.py`` file *in a trusted local | ||
| context* (the developer's machine), reads its | ||
| :py:meth:`pydantic.BaseModel.model_json_schema` output, and writes the | ||
| result to a ``.json`` file alongside. | ||
|
|
||
| Usage: | ||
|
|
||
| python scripts/py_schema_to_json.py \ | ||
| src/ContentProcessorAPI/samples/schemas/autoclaim.py \ | ||
| AutoInsuranceClaimForm | ||
|
|
||
| The generated JSON is what should be uploaded to the schema vault going | ||
| forward; it is data only and never executed by the worker. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import importlib.util | ||
| import json | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| def convert(py_path: Path, class_name: str, out_path: Path | None = None) -> Path: | ||
| """Load *class_name* from *py_path* and write its JSON schema next to it.""" | ||
| spec = importlib.util.spec_from_file_location(py_path.stem, py_path) | ||
| if spec is None or spec.loader is None: | ||
| raise RuntimeError(f"Cannot import schema module from {py_path}") | ||
| module = importlib.util.module_from_spec(spec) | ||
| sys.modules[spec.name] = module | ||
| spec.loader.exec_module(module) # noqa: S102 - trusted local conversion only | ||
|
|
||
| cls = getattr(module, class_name, None) | ||
| if cls is None or not isinstance(cls, type) or not issubclass(cls, BaseModel): | ||
| raise RuntimeError( | ||
| f"'{class_name}' is not a Pydantic BaseModel in {py_path}" | ||
| ) | ||
|
|
||
| schema = cls.model_json_schema() | ||
| # Pydantic emits "title" at the root; ensure it matches the requested | ||
| # class name so the worker's ``derive_class_name`` picks it up. | ||
| schema["title"] = class_name | ||
|
|
||
| target = out_path or py_path.with_suffix(".json") | ||
| target.write_text(json.dumps(schema, indent=2) + "\n", encoding="utf-8") | ||
| return target | ||
|
|
||
|
|
||
| def main() -> int: | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument("py_path", type=Path, help="Path to the .py schema file.") | ||
| parser.add_argument("class_name", help="BaseModel class to export.") | ||
| parser.add_argument( | ||
| "--out", | ||
| type=Path, | ||
| default=None, | ||
| help="Output .json path (defaults to alongside the input).", | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| target = convert(args.py_path, args.class_name, args.out) | ||
| print(f"Wrote {target}") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) |
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 |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ dependencies = [ | |
| "protobuf==6.33.6", | ||
| "pyjwt==2.12.1", | ||
| "pyasn1==0.6.3", | ||
| "jsonschema==4.25.1", | ||
| ] | ||
|
|
||
|
|
||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.