Skip to content

Conversation

@ne275
Copy link

@ne275 ne275 commented Dec 18, 2025

Description

This PR adds language-agnostic JSON Schema definitions for all AP2 mandate types, addressing the need for Verifiable Credential support in non-Python implementations.

Changes

  • ✅ Add JSON Schema files for IntentMandate, CartMandate, and PaymentMandate
    • schemas/intent-mandate.schema.json
    • schemas/cart-mandate.schema.json
    • schemas/payment-mandate.schema.json
  • ✅ Create automated schema generation script (scripts/generate_schemas.py)
    • Uses Pydantic's model_json_schema() to ensure schemas stay in sync with Python types
    • Adds proper $schema and $id fields for JSON Schema compliance
  • ✅ Add schema validation test script (scripts/validate_schemas.py)
  • ✅ Add comprehensive documentation (schemas/README.md)
    • Usage examples for Python, JavaScript/TypeScript, and Go
    • Instructions for type generation with tools like quicktype
    • Guidance for using schemas with Verifiable Credentials
  • ✅ Update main README with JSON Schema support section

Problem Solved

Previously, AP2 only provided Python type definitions (Pydantic models), which created barriers for:

  • Non-Python implementations
  • Verifiable Credential issuers who need portable, verifiable schema definitions
  • Cross-language validation and type generation
  • IDE autocomplete and validation in other languages

Solution Benefits

These schemas enable:

  • Validation of mandate objects in any programming language
  • Type generation for non-Python implementations (TypeScript, Go, Swift, Kotlin, etc.)
  • Verifiable Credential creation with proper schema references
  • IDE support with autocomplete and validation
  • Interoperability across different implementations

Schema URLs

Schemas are publicly accessible at:
https://raw.githubusercontent.com/google-agentic-commerce/AP2/main/schemas/intent-mandate.schema.json
https://raw.githubusercontent.com/google-agentic-commerce/AP2/main/schemas/cart-mandate.schema.json
https://raw.githubusercontent.com/google-agentic-commerce/AP2/main/schemas/payment-mandate.schema.json

Testing

  • Schemas generate successfully from Pydantic models
  • IntentMandate schema validates example instances
  • All files include proper Apache 2.0 license headers
  • Documentation includes working examples for multiple languages

Checklist

Fixes #127

@ne275 ne275 requested a review from a team as a code owner December 18, 2025 03:00
@google-cla
Copy link

google-cla bot commented Dec 18, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ne275, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the interoperability of the AP2 protocol by introducing language-agnostic JSON Schema definitions for its core mandate types (Intent, Cart, and Payment). This change addresses previous limitations where only Python type definitions were available, thereby enabling broader adoption across non-Python implementations, facilitating Verifiable Credential support, and improving cross-language validation and type generation. The new schemas provide a standardized way to define and validate AP2 mandate objects, fostering a more robust and accessible ecosystem.

Highlights

  • JSON Schema Definitions: Added language-agnostic JSON Schema files for IntentMandate, CartMandate, and PaymentMandate, enabling broader interoperability.
  • Automated Schema Generation: Introduced a Python script (scripts/generate_schemas.py) that leverages Pydantic's model_json_schema() to ensure the generated schemas remain synchronized with the Python type definitions.
  • Schema Validation Script: Included a new script (scripts/validate_schemas.py) to automatically validate the generated JSON schemas against example instances, ensuring their correctness.
  • Comprehensive Documentation: Added a detailed schemas/README.md, providing usage examples for validation in Python, JavaScript/TypeScript, and Go, along with instructions for type generation and integration with Verifiable Credentials.
  • Main README Update: The main README.md has been updated with a new section dedicated to JSON Schema support, outlining its benefits and linking to the new schema documentation.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is a great addition to the project! Providing JSON schemas significantly improves interoperability and makes it easier for developers using other languages to adopt AP2. The generation and validation scripts are excellent for ensuring the schemas stay in sync with the Pydantic models.

I've left a few suggestions to further improve the generated schemas and the documentation examples. Specifically, I've recommended:

  • Fixing the Go example in the schemas/README.md to be runnable.
  • Improving the schema generation script to clean up descriptions and add date-time formats.
  • Making the validation script's dependency handling more user-friendly.

Overall, this is a very solid and valuable contribution. Well done!

- Add JSON Schema files for IntentMandate, CartMandate, and PaymentMandate
- Create schema generation script using Pydantic's model_json_schema()
- Add schema validation test script
- Update README with JSON Schema documentation
- Add comprehensive schemas/README.md with usage examples for Python, JavaScript, Go
- Addresses issue requesting language-agnostic schema definitions for Verifiable Credentials support

These schemas enable:
- Validation of mandate objects in any programming language
- Type generation for non-Python implementations
- Verifiable Credential creation with proper schema references
- IDE autocomplete and validation support
@ne275 ne275 force-pushed the feat/json-schema-support branch from 226c695 to 138fc74 Compare December 18, 2025 03:04
@ne275 ne275 closed this Dec 18, 2025
@ne275 ne275 reopened this Dec 18, 2025
…xample

- Add textwrap.dedent to clean up multi-line docstring descriptions
- Add 'format: date-time' for timestamp fields (intent_expiry, cart_expiry, timestamp)
- Fix Go example to include missing imports (fmt, log)
- Fix Go example to properly handle validation errors (idiomatic error handling)
- Regenerate schemas with improved formatting and date-time formats
- Fix MD030 linting errors by using single space after list markers
- Change from '-   ' to '- ' format for consistency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat]: Published JSON schema defintions for mandate credentials

1 participant