Files
herolib/lib/schemas/openrpc
Mahmoud-Emad ba48ae255b refactor: Update example generation and schema handling
- Remove unused `generate_example_call` and `generate_example_response` functions
- Rename `example_call` to `example_request` in `DocMethod`
- Update schema example extraction to use `schema.example` directly
- Introduce `generate_request_example` and `generate_response_example` for dynamic example generation
- Change type of `id` from string to number in schema examples

PS: The work is still in progress
2025-09-22 14:58:22 +03:00
..
2025-09-16 19:31:46 +03:00
...
2025-09-14 11:57:11 +02:00
2025-09-14 15:46:57 +03:00
2025-09-14 15:46:57 +03:00
...
2025-03-24 06:44:39 +01:00
2025-09-14 15:46:57 +03:00
2025-09-14 15:46:57 +03:00
2025-09-14 15:46:57 +03:00
2025-09-14 15:46:57 +03:00
...
2025-03-24 06:44:39 +01:00
...
2025-09-14 12:57:56 +02:00
...
2025-09-14 12:21:14 +02:00
...
2025-09-14 15:35:41 +02:00
...
2025-09-14 15:35:41 +02:00
2025-09-14 15:46:57 +03:00
2025-09-14 15:46:57 +03:00

OpenRPC Module

This module provides a complete implementation of the OpenRPC specification for V, enabling structured JSON-RPC 2.0 API development with schema-based validation and automatic documentation.

Purpose

  • Define and validate JSON-RPC APIs using OpenRPC schema definitions
  • Handle JSON-RPC requests/responses over HTTP or Unix sockets
  • Automatic discovery endpoint (rpc.discover) for API documentation
  • Type-safe request/response handling
  • Support for reusable components (schemas, parameters, errors, examples)

Usage

1. Create an OpenRPC Handler

Create a handler with your OpenRPC specification:

import freeflowuniverse.herolib.schemas.openrpc

// From file path
mut handler := openrpc.new_handler('path/to/openrpc.json')!

// From specification text
mut handler := openrpc.new(text: spec_json)!

2. Register Methods

Register your method handlers to process incoming JSON-RPC requests:

fn my_method(request jsonrpc.Request) !jsonrpc.Response {
    // Decode parameters
    mut params := json.decode(MyParams, request.params) or { 
        return jsonrpc.invalid_params 
    }
    
    // Process logic
    result := process_my_method(params)
    
    // Return response
    return jsonrpc.new_response(request.id, json.encode(result))
}

// Register the method
handler.register_procedure_handle('my.method', my_method)

3. Start Server

Launch the server using either HTTP or Unix socket transport:

// HTTP server
mut controller := openrpc.new_http_controller(handler)
controller.run(port: 8080)

// Unix socket server
mut server := openrpc.new_unix_server(handler)!
server.start()