Initialize a2ui_core SDK with schema definitions and basic UI catalog components#1575
Conversation
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
|
/gemini summary |
|
Warning Gemini encountered an error creating the summary. You can try again by commenting |
|
/gemini summary |
|
Warning Gemini encountered an error creating the summary. You can try again by commenting |
There was a problem hiding this comment.
Overall, this approach seems fantastic and we should adopt it in our other libraries.
Remind me again why we couldn't use something like https://pypi.org/project/json-schema-to-pydantic/ ? It'd be amazing if we didn't need to maintain so much special cased logic here. But also, we don't change the schema very often, so it's not a huge deal.
There was a problem hiding this comment.
I tried https://pypi.org/project/datamodel-code-generator/ instead of https://pypi.org/project/json-schema-to-pydantic/.
https://docs.google.com/document/d/11PYbSt0ThCjYabW8YN6fU2goJu44z-CmOzG49hPw5ew/edit?resourcekey=0-jN1YnS8nl6r7N7HOhVNXKg&tab=t.2fcdpw7eay5q#bookmark=id.r6fnse63e7y2 summarizes some issues I encountered during the generation process.
I can give json-schema-to-pydantic a quick shot to see whether it is a better fit.
There was a problem hiding this comment.
I ran into the following issues with json-schema-to-pydantic:
- Rejection of Cross-File / Multi-Document References ($ref): json-schema-to-pydantic strictly enforces intra-document references (#/). Even when converting remote URLs to local relative file paths (common_types.json#/..., catalog.json#/...), it immediately throws ReferenceError: Only local references (#/...) are supported. It lacks a multi-document resolver capable of linking our separated, modular specifications.
- Custom Catalog DSL Incompatibility: Our component catalog (
basic/catalog.json) groups specifications inside custom top-level container keys("components": { ... })rather than standard JSON Schema"properties". Generic parsers do not recognize this DSL layout, treating the catalog as an empty schema object. - Discriminated Union Optimization (O(1) Routing): We require O(1) routing via Pydantic's
Annotated[Union[...], Field(..., discriminator="component")]for high-frequency UI payload parsing. Off-the-shelf tools fail to synthesize optimized discriminated unions across heterogeneous component schemas, generating slow sequential try-except evaluators. - Symmetrical Inheritance & Singularization: We need components to cleanly inherit from
CatalogComponentCommonwithout duplicating inherited base fields (id,weight), and resolve inline JSON object definitions into clean semantic helper classes (e.g.,OptionIteminstead of genericOptionor DynamicModel wrappers).
I also updated the doc to include that.
| return "\n".join(output) | ||
|
|
||
|
|
||
| def generate_basic_catalog_components( |
There was a problem hiding this comment.
Future idea: It could be nice to generalize this to generate_catalog_components at some point, so we can point it at any catalog file that adheres to our structure.
There was a problem hiding this comment.
I created an issue to track the idea: #1592.
Description
Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.
List which issues are fixed by this PR. For larger changes, raising an issue first helps reduce redundant work.
Pre-launch Checklist
If you need help, consider asking for advice on the discussion board.