Something went wrong. Try again.
Zig bindings for all 506 operations of the Forgejo API, generated from its own description, and zfj, a command line built on them.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! Turns the vendored Forgejo API description into Zig. The build runs this//! with `api/swagger.v1.json` on standard input and captures the Zig source it//! writes to standard output, so the generated bindings never land in the//! source tree and cannot drift from the specification they came from.
const std = @import("std");
const openapi2zig = @import("openapi2zig");
pub fn main(init: std.process.Init) !u8 { const io = init.io; const allocator = init.gpa;
var stdin_buffer: [4096]u8 = undefined; var stdin_file: std.Io.File = .stdin(); var stdin_reader = stdin_file.reader(io, &stdin_buffer); const stdin = &stdin_reader.interface;
var spec: std.Io.Writer.Allocating = .init(allocator); defer spec.deinit(); _ = try stdin.streamRemaining(&spec.writer);
const args = openapi2zig.CliArgs{ // Only ever read back in diagnostics: the input arrives on stdin and // the output leaves on stdout. .input_path = "api/swagger.v1.json", .output_path = "api.zig", // One client struct per Swagger tag, so an operation is reached as // `client.issue.issueGetIssue(...)` rather than out of a single // namespace holding all 506 of them. .multiple_clients = .per_tag, // The tag clients are the API surface; the path-shaped wrappers would // be a second one over the same operations. .resource_wrappers = .none, // Forgejo operations take up to a dozen parameters, and an options // struct keeps a call site readable and its arguments named. .parameters_as_struct = true, };
var document = try openapi2zig.parseToUnified(allocator, spec.written()); defer document.deinit(allocator);
const generated = try openapi2zig.generateCode(allocator, document, args); defer allocator.free(generated);
var stdout_buffer: [4096]u8 = undefined; var stdout_file: std.Io.File = .stdout(); var stdout_writer = stdout_file.writer(io, &stdout_buffer); const stdout = &stdout_writer.interface;
try stdout.writeAll(generated); try stdout.flush();
return 0;}