world-engine icon indicating copy to clipboard operation
world-engine copied to clipboard

feat: setup speakeasy

Open rmrt1n opened this issue 1 year ago • 4 comments

Closes: WORLD-1180

Overview

Setup Speakeasy to generate SDKs for cardinal.

Change Breakdown

Speakeasy configuration

Speakeasy is configured using the workflow.yaml and gen.yaml in the .speakeasy dir in the root directory. Package names, SDK languages, input/output dir, etc. goes here. The generated SDKs go in cardinal/sdk/[language-name]. ATM only typescript is generated.

Speakeasy Generation Workflow

This PR introduces some scripts that needs to be run before and after generating the SDK for everyting to work correctly. See makefiles/api.mk, scripts/pre-speakeasy.js,and scripts/post-speakeasy.sh. Here are the steps to generate the SDK:

  1. Run make swagger to generate the swagger.json file.
  2. Run make swagger-codegen-install to install the swagger -> openapi 3 converter
  3. Run make speakeasy. this will: a. Convert swagger.json to openapi.json b. Run scripts/pre-speakeasy.js to modify openapi.json files c. Run speakeasy run to generate the SDK d. Run scripts/post-speakeasy.sh to modify the generated SDK

This workflow works, but requires the machine to have Java and Node installed.

Generated TypeScript SDK

The SDK is generated in cardinal/sdk/typescript. The only code that needs review here are in the cardinal/sdk/typescript/src/hooks dir, which contains custom hooks to sign transactions for the users. See hooks/cardinal.ts, which contains the custom hooks, and hooks/sign.ts, which contains the signing function (also used in the cardinal editor).

To get a quick feel of the SDK, read the README and the SDK docs.

Changes in Cardinal

Most of the changes in the cardinal code are only in the swaggo/swag comments/docstrings.

NOTE: 1 breaking change in cardinal is introduced in this PR. Transaction responses keys are changed to follow JSON conventions. See cardinal/server/handler/tx.go.

New GitHub Actions

See .github/workflows/sdk_generation.yaml and .github/workflows/sdk_publish.yaml.

Testing and Verifying

Manually tested & verified

Summary by CodeRabbit

  • New Features

    • Introduced a script to enhance OpenAPI specifications for compatibility with the Speakeasy SDK, allowing for endpoint management and parameter customization.
    • Added functionality to ignore specific endpoints from SDK generation.
    • Enhanced schema definitions to support dynamic keys and provided meaningful identifiers for generated types.
  • Documentation

    • Updated API documentation to include examples and improve clarity for users interacting with the API.

rmrt1n avatar Jul 26 '24 16:07 rmrt1n

Walkthrough

The changes introduce new GitHub Actions workflows for SDK generation and publishing, modify existing CI configurations, and enhance OpenAPI specifications. A new script is added to preprocess OpenAPI files for compatibility with the Speakeasy SDK. Various documentation files are created or updated to improve clarity and usability. Additionally, TypeScript configurations and utility files are introduced to support the SDK's functionality and maintainability.

Changes

File(s) Change Summary
.github/workflows/sdk_generation.yaml, .github/workflows/sdk_publish.yaml New workflows for generating and publishing SDKs are introduced.
.github/workflows/ci-md.yaml CI workflow modified to restrict linting to the docs directory.
scripts/pre-speakeasy.js New script added to modify OpenAPI specs for Speakeasy SDK compatibility, including parameter handling and schema adjustments.
.markdownlintignore, .speakeasy/gen.yaml, .speakeasy/workflow.lock, .speakeasy/workflow.yaml New configuration files introduced for linting, SDK generation parameters, and workflow management.
cardinal/sdk/typescript/... Multiple TypeScript files added, including utility functions and types for enhanced SDK functionality.
cardinal/server/docs/docs.go, cardinal/server/docs/openapi.json, cardinal/server/docs/swagger.* Documentation files updated to enhance clarity and include new operation IDs for API endpoints.
cardinal/server/handler/... Modifications to handler files to improve API documentation and add example values for parameters.
Makefile, makefiles/api.mk, makefiles/test.mk Adjustments made to Makefiles for organizing build processes and removing outdated tasks.
scripts/post-speakeasy.sh New script added to automate TypeScript type modifications for the SDK.
cardinal/types/... New TypeScript utilities introduced for better handling of types and validations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API
    participant Preprocess Script
    participant SDK

    User->>API: Request API Specification
    API->>User: Return OpenAPI Specification
    User->>Preprocess Script: Run Preprocessing Script
    Preprocess Script->>API: Modify OpenAPI Specification
    Preprocess Script->>SDK: Generate SDK from Modified Spec
    SDK->>User: Provide SDK

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Jul 26 '24 16:07 coderabbitai[bot]

Your org has enabled the Graphite merge queue for merging into main

Add the label “graphite/merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

graphite-app[bot] avatar Jul 26 '24 16:07 graphite-app[bot]

This stack of pull requests is managed by Graphite. Learn more about stacking.

rmrt1n avatar Jul 26 '24 16:07 rmrt1n

Codecov Report

Attention: Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 60.52%. Comparing base (be0f875) to head (748a8d5). Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
cardinal/server/handler/query.go 0.00% 2 Missing :warning:
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #794      +/-   ##
==========================================
- Coverage   60.53%   60.52%   -0.02%     
==========================================
  Files         143      143              
  Lines        7265     7268       +3     
==========================================
+ Hits         4398     4399       +1     
- Misses       2414     2416       +2     
  Partials      453      453              
Files with missing lines Coverage Δ
cardinal/server/docs/docs.go 100.00% <ø> (ø)
cardinal/server/handler/cql.go 77.77% <ø> (ø)
cardinal/server/handler/debug.go 71.42% <ø> (ø)
cardinal/server/handler/health.go 100.00% <ø> (ø)
cardinal/server/handler/receipts.go 77.14% <ø> (ø)
cardinal/server/handler/tx.go 62.26% <ø> (ø)
cardinal/server/handler/world.go 100.00% <ø> (ø)
cardinal/world.go 76.66% <100.00%> (+0.07%) :arrow_up:
cardinal/server/handler/query.go 45.45% <0.00%> (-10.11%) :arrow_down:

codecov[bot] avatar Jul 26 '24 16:07 codecov[bot]

closing this for now

smsunarto avatar Dec 04 '24 23:12 smsunarto