Skip to content

AprilNEA/harbor-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Harbor API Rust Client

A Rust client library for the Harbor API, automatically generated from their OpenAPI specification.

Features

  • Fully typed API client generated from Harbor's OpenAPI spec
  • Async/await support with tokio
  • Automatic retry and error handling via progenitor
  • Builder pattern for constructing API requests

Installation

Add this to your Cargo.toml:

[dependencies]
harbor-api = { git = "https://github.com/AprilNEA/harbor-api" }

Usage

use harbor_api::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a new client instance
    let client = Client::new("https://api.harbor.gg");

    // Make API calls using the generated methods
    // Example (adjust based on actual API endpoints):
    // let response = client.get_something().send().await?;

    Ok(())
}

Building from Source

This project uses a build script to generate the API client from Harbor's OpenAPI specification.

Prerequisites

  • Rust 1.70 or later
  • Internet connection (for fetching the OpenAPI spec during build)

Build

cargo build

Custom API Spec

You can override the default API specification URL by setting the SPEC_URL environment variable:

SPEC_URL=https://your-harbor-instance.com/api/swagger.json cargo build

Development

The API client is generated at build time using progenitor. The build script:

  1. Fetches the OpenAPI specification from Harbor's API
  2. Ensures all operations have unique operation IDs
  3. Filters out unsupported operations (e.g., multipart/form-data)
  4. Generates type-safe Rust code

Project Structure

harbor-api/
├── Cargo.toml          # Project dependencies
├── build.rs            # Build script for code generation
├── src/
│   └── lib.rs         # Library entry point (includes generated code)
└── target/
    └── debug/
        └── build/.../out/
            └── codegen.rs  # Generated API client code

Known Limitations

  • Operations that use multipart/form-data content type are not supported and are filtered out during code generation
  • The generated client requires an active internet connection during the build process to fetch the API specification

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is open source. Please check the repository for license details.

Author

Acknowledgments

  • Harbor for providing the API
  • progenitor for the excellent OpenAPI code generation tools

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages