refactor!: Refactor common primitive types from shopping/types to common/types - #736
Conversation
igrigorik
left a comment
There was a problem hiding this comment.
Overall, looks good. Two documentation flags before we land this...
Can we preserve inline schema rendering?
Moving these schemas into common/types/ activates the existing shared-type behavior in schema_fields: inline field tables on the Catalog, Cart, Checkout, Fulfillment, and Order pages are replaced with links to the Schema Reference. That's a lot of external refs that were previously directly visible in the document, which I think is a meaningful regression.
This should require only small surgery in main.py. I would make inline rendering the default and make link-only rendering an explicit opt-out:
def schema_fields(entity_name, spec_file_name, inline=True):
...
if (
not inline
and spec_file_name != "reference"
and _resolves_to_shared_type(base_name) is not None
):
return _render_shared_type_link(base_name, spec_file_name)Call sites that intentionally want only the canonical-reference link can then opt out explicitly:
{{ schema_fields('types/postal_address', 'checkout', inline=False) }}Nit: stale totals.json reference
The complete Checkout example in docs/documentation/schema-authoring.md still contains:
"totals": {"$ref": "types/totals.json"}After this move, the correct relative reference from shopping/checkout.json is ../common/types/totals.json.
|
Thanks @igrigorik! Can we preserve inline schema rendering?I'd like to take a step back and make sure we are aligned on the rendering principles here. Based on #536, we aligned that:
Personally I think the increase in external refs/redirects from this PR is WAI and consistent with the expectation we want to set with developers. The net new effects:
I'm also fine to always inline schema rendering by default on capabilities documentation, but I want to make sure it then means we are doing it consistently to all Nit: stale totals.json referenceGood catch! I realized that there was one more stale reference to ( |
@jingyli my vote is for inline render. The main reason to avoid it is due to risk of them getting out of sync in different places, but since these are auto-resolved + inlined refs and we rebuild the whole tree, that risk is a no-op. By inlining we get the benefit of much easier and friendlier reading and comprehension -- no need to jump across tabs, etc. |
…. By default, we will always force an inline rendering and only redirect if the caller explicitly opted out.
|
@igrigorik Sounds good, PTAL at 623b2c8 - this updates both |
Correct the checkout schema example to model links as an array of the singular shared link type. Align the shared-type resolver documentation with the default-inline rendering policy used by capability pages.
| # itself always renders full tables via auto_generate_schema_reference. | ||
| # base_name is passed (suffix stripped) so the link anchor targets | ||
| # the canonical heading. | ||
| if ( |
There was a problem hiding this comment.
Nit: Note that _resolves_to_shared_type(base_name) strips suffixes but assumes base_name does not already end with .json. If a caller passes a .json path or pointer with #, _resolves_to_shared_type can construct .json.json. Normalizing clean = str(ref_path).split('#', 1)[0] and name = Path(clean).stem in _resolves_to_shared_type avoids this edge case.
There was a problem hiding this comment.
I agree with the suggestion to strengthen our parsing logic in _resolves_to_shared_type, though just calling out the gap more explicitly here with our current logic:
We may unintentionally introduce false negatives: i.e. schema_fields('context.json', ..., render_inline=False) will cause _resolves_to_shared_type to attempt resolve whether /common/types/context.json.json exists - which will result in None being returned from the function and the redirect rendering will not happen.
Another downside here is that it also expects the author to read through main.py to understand what ref_path we truly expect (which may or may not be a huge problem - if I play the devil's advocate here, we are forcing consistency since all other forms will result in broken documentation rendering and and the author will need to correct/fix the incorrect `ref_path).
|
Overall, this refactor is in great shape and is a solid step forward for the multi-vertical roadmap (#520). The switch to Before we land this breaking refactor, here are a few non-blocking suggestions to address before merging: 1. SDK Model Regeneration
2. Schema Authoring Guide Update (
|
|
Thanks @amithanda! 1. SDK Model RegenerationAck on this - I think a known gap is that our current generation script cannot be executed on draft PRs (even if there is a way to hack around it, it's not very well documented) and we will need to think about how to streamline that so that checkbox in the PR template makes sense for developers (@gsmith85 FYI). FWIW, when I tried regenerating the Python SDK based on the current 2. Schema Authoring Guide Update (render_inline)I gave this some thoughts when updating the script (e.g., documenting down our principles like always force inline type rendering on specification pages). But I think right now I think as a follow-up, maybe we should create a sibling page called |
Description
A continuation of #436, addressing Phase 3 + 4 in that PR. Also related to #723 when it comes to schema types clean-ups that go hand-in-hand with specification refactoring.
Design choices made in this PR:
source/schemas/shopping/types/tosource/schemas/common/types/:context.jsonsignals.jsontotals.jsontotal.jsonpolicy.jsonprice_filter.jsonprice_range.jsonattribution.jsonout-of-scope for now as we haven't fully vetted the design for x-vertical usages.Category (Required)
Please select one or more categories that apply to this change.
ucp-schematool (resolver, linter, validator). (Requires Maintainer approval)Related Issues
Phase 2 in #520
Checklist
!for breaking changes).Screenshots / Logs (if applicable)
Manually validated via local ucp.dev to ensure that none of the reference links in the existing
reference.mdwill break.Also a screenshot example of how the inline rendering now looks like in capability pages:
