Skip to content

Conversation

@aorumbayev
Copy link
Collaborator

@aorumbayev aorumbayev commented Apr 28, 2025

Proposed changes

This PR introduces the infrastructure for generating Algorand API clients using the OpenAPI Generator tool. This approach automates the creation of clients in various languages (initially focusing on Python and TypeScript for algokit-utils) from a single OpenAPI specification, ensuring consistency and reducing maintenance overhead.

Motivation:

As outlined in docs/research/openapi-generators.md, manually maintaining API clients across multiple languages is time-consuming and error-prone. Using OpenAPI generators allows us to:

  • Generate consistent clients from a single source of truth (the OpenAPI spec).
  • Easily propagate API changes to all supported languages.
  • Leverage a mature, well-maintained open-source tool.

Changes:

  1. Directory Structure: Introduced new directories and files under /api to support the generation process:
    • api/specs/: Contains the OpenAPI specifications (v2 and v3).
    • api/api_clients/: Will hold the generated client code.
    • api/oas_templates/: Stores custom Mustache templates for tailoring generated code.
    • api/scripts/: Includes utility scripts (generate-api-clients.ts) for managing the generation process.
    • Configuration files (openapitools.json, package.json, tsconfig.json, openapi-config.yaml) to configure the generator and manage dependencies (like bun for running the generation script).
  2. Specification Handling:
    • Uses the v3 OpenAPI spec derived from the official Go Algorand source for better generator compatibility.
    • Includes minor improvements to the spec for clarity and generator compatibility (e.g., formatting, fixing AvmValue schema for Python).
  3. Generation Script: Added scripts/generate-api-clients.ts (run via bun run) to orchestrate the client generation, including handling .openapi-generator-ignore files to protect custom code.
  4. Initial Client Focus: The initial setup targets core transaction endpoints (get pending txns, get tx params, post raw txn) needed for algokit-utils integration.
  5. Testing Strategy: Adopted a custom testing approach (as detailed in the research doc) rather than modifying generated tests, allowing for more robust and maintainable tests tailored to our environment (e.g., Sandbox dependencies).
  6. Documentation: Added docs/research/openapi-generators.md detailing the approach, structure, rationale, and future work.
  7. Dependency Updates: Updated poetry.lock and pyproject.toml in packages/python/algokit_transact reflecting changes potentially related to CFFI or other dependencies needed for the generated clients or testing infrastructure. (Specific updates include cffi, maturin, packaging, pluggy, pytest, tomli, and adjustments to dev dependencies).

This PR lays the baseline for a more scalable and maintainable approach to managing Algorand API clients across different languages within the monorepo project.

@aorumbayev aorumbayev force-pushed the spike/oas_clients branch 5 times, most recently from 97af59d to 49cf4e5 Compare April 29, 2025 00:29
@aorumbayev aorumbayev marked this pull request as ready for review April 29, 2025 11:17
@joe-p
Copy link
Collaborator

joe-p commented Apr 29, 2025

Haven't reviewed in-depth yet, but would it be possible make the Python changes in a separate PR? We have merge conflicts anyways after #61 and having that work in a separate PR will make it a bit easier to review and iterate.

@aorumbayev aorumbayev force-pushed the spike/oas_clients branch 4 times, most recently from 8e6f806 to 6b060a0 Compare April 29, 2025 20:36
@aorumbayev
Copy link
Collaborator Author

@joe-p moved python ffi changes to #65

@aorumbayev aorumbayev requested a review from PatrickDinh May 2, 2025 17:03
@joe-p
Copy link
Collaborator

joe-p commented May 4, 2025

Could we add extension to the moustache template files to make them a bit easier to digest? For example, instead of conftest.moustache it could be conftest.py.moustache

@aorumbayev
Copy link
Collaborator Author

@joe-p adding extensions to mustache templates, while possible with mustache templating in general, wouldn't fit well to our use case. The base template was generated via oas generator command that stores the base files to the filesystem so developers can then extend them. The problem is that extension mapping for template files included in the base template are all postfixed with .mustache, if we are to preserve the extensions from original base templates we would have to manually update the files and then original generator would threat them as supporting external files instead of recognizing as files from base templates. Whenever potential updates in base templates arrive it would be hard for us to manually keep track of changes and remapping against latest templates we maintain with the file extensions.

Once we have CD for clients, we can add the generated clients back to version control for tracking output stability, at that point it would be fairly easy to traceback from generated file back to mustache template by the filename. In most cases those would be custom template files for tests and those also contain explicit filename specification in the spec files per template folder. https://github.com/algorandfoundation/algokit-core/blob/spike/oas_clients/api/oas_templates/python/openapi-config.yaml

@aorumbayev aorumbayev force-pushed the spike/oas_clients branch from 47ad6e9 to 2e60651 Compare May 5, 2025 11:57
@aorumbayev aorumbayev force-pushed the spike/oas_clients branch 2 times, most recently from 9ff4673 to 1861099 Compare May 6, 2025 09:13
chore: adding more structure to api folder; automating generation of py|ts clients

chore: refining stock template to leverage pytest over unittest and auto generate valid baseline tests

chore: removing auto generated tests as they are too cumbersome to modify

- Instead setting up a structure for custom mustache files implementing manually written tests given that each end point (total around 55) often requires complex state setup
- For the time being the only test established is the test for sending raw transactions

chore: refining base python tests; fixing typescript template

chore: add basic txn params tests

chore: refine python transaction tests

chore: typescript client tweaks and initial tests

docs: initial doc on api folder and oas generators

chore: adding default pr and issue templates

chore: refning docs

chore: moving python ffi improvements to separate pr; adding basic ci for oas clients

chore: expose raw response context (#67)

chore: addressing pr comments

chore: merge conflict fixes

chore: addressing pr comments
@aorumbayev aorumbayev force-pushed the spike/oas_clients branch from 1861099 to ef830d0 Compare May 6, 2025 09:21
@aorumbayev aorumbayev merged commit 324f57f into main May 6, 2025
17 checks passed
@aorumbayev aorumbayev deleted the spike/oas_clients branch May 6, 2025 09:26
@engineering-ci
Copy link
Contributor

🎉 This PR is included in version 1.0.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@engineering-ci
Copy link
Contributor

🎉 This PR is included in version 1.0.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@engineering-ci
Copy link
Contributor

🎉 This PR is included in version 1.0.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@engineering-ci
Copy link
Contributor

🎉 This PR is included in version 1.0.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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.

5 participants