const std = @import("std"); const config = @import("../../core/config.zig"); const model = @import("model.zig"); const Endpoint = model.Endpoint; const endpoints = model.endpoints; pub fn render(allocator: std.mem.Allocator) ![]const u8 { var out: std.Io.Writer.Allocating = .init(allocator); defer out.deinit(); try out.writer.print( \\{{"openapi":"3.1.0","info":{{"title":"ZDS endpoint reference","version":"0.1.0","description":"Endpoint inventory generated by ZDS."}},"servers":[{{"url":{f}}}],"paths":{{ , .{std.json.fmt(config.publicUrl(), .{})}); var first_path = true; for (endpoints, 0..) |endpoint, i| { if (model.pathSeenBefore(i)) continue; if (!first_path) try out.writer.writeAll(","); first_path = false; try out.writer.print("{f}:{{", .{std.json.fmt(endpoint.path, .{})}); var first_method = true; for (endpoints) |method_endpoint| { if (!std.mem.eql(u8, endpoint.path, method_endpoint.path)) continue; if (!first_method) try out.writer.writeAll(","); first_method = false; try renderOperation(&out.writer, method_endpoint); } try out.writer.writeAll("}"); } try out.writer.writeAll("}}\n"); return out.toOwnedSlice(); } fn renderOperation(writer: *std.Io.Writer, endpoint: Endpoint) !void { try writer.print( \\{f}:{{"summary":{f},"tags":[{f}],"description":{f} , .{ std.json.fmt(model.methodLower(endpoint.method), .{}), std.json.fmt(endpoint.summary, .{}), std.json.fmt(endpoint.group, .{}), std.json.fmt(endpointDescription(endpoint), .{}), }); if (model.isExperimental(endpoint)) { try writer.writeAll(\\,"x-zds-experimental":true ); } try writer.writeAll(\\,"responses":{"200":{"description":"OK"}}} ); } fn endpointDescription(endpoint: Endpoint) []const u8 { if (model.isExperimental(endpoint)) { return "Experimental permissioned-data method gated by ZDS_PERMISSIONED_DATA."; } return "Generated from the ZDS endpoint inventory."; }