Skip to content

Commit

Permalink
Merge pull request #62 from fussybeaver/ND/update-deps
Browse files Browse the repository at this point in the history
chore: update dependencies
  • Loading branch information
fussybeaver authored Oct 20, 2024
2 parents 0f46af4 + 115c1db commit b1fcb88
Show file tree
Hide file tree
Showing 64 changed files with 33,204 additions and 32,585 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Check
on:
repository_dispatch:
types:
- github-openapi-release
- octokit/openapi-release

jobs:
update:
Expand Down
25 changes: 13 additions & 12 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ jobs:
with:
command: check

- name: Run cargo check isahc
uses: actions-rs/cargo@v1
with:
command: check
args: --features isahc --target x86_64-unknown-linux-gnu

- name: Run cargo check reqwest
uses: actions-rs/cargo@v1
with:
Expand All @@ -53,6 +47,18 @@ jobs:
command: check
args: --target wasm32-unknown-unknown

- name: Run cargo check workspace examples
uses: actions-rs/cargo@v1
with:
command: check
args: --workspace --target wasm32-unknown-unknown

- name: Run cargo check min-req-adapter
uses: actions-rs/cargo@v1
with:
command: check
args: -p min-req-adapter

test:
name: Test Suite
runs-on: ubuntu-latest
Expand Down Expand Up @@ -85,17 +91,12 @@ jobs:
toolchain: stable
override: true

- name: Run cargo test isahc
uses: actions-rs/cargo@v1
with:
command: test
args: --features isahc --target x86_64-unknown-linux-gnu

- name: Run cargo test reqwest
uses: actions-rs/cargo@v1
with:
command: test
args: --features reqwest --target x86_64-unknown-linux-gnu

- name: Run cargo test ureq
uses: actions-rs/cargo@v1
with:
Expand Down
81 changes: 42 additions & 39 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,68 @@ repository = "https://github.com/fussybeaver/roctogen"
documentation = "https://docs.rs/roctogen"
readme = "README.md"
keywords = ["github"]
edition = "2018"
edition = "2021"

[workspace]
members = [
"examples/auth/*",
"examples/min-req-adapter",
]
exclude = ["codegen/**"]

[lib]
crate-type = ["cdylib", "rlib"]
path = "src/lib.rs"

[features]
default = []
reqwest = ["dep:reqwest", "dep:bytes"]

# Activate mock base url
mock = []

[dependencies]
base64 = "0.13"
[workspace.dependencies]
base64 = "0.22"
chrono = { version = "0.4", features = ["serde"] }
http = "0.2.3"
http = "1.1"
serde = "1.0"
serde_derive = "1.0"
serde_json = {version = "1.0"}
serde_urlencoded = { version = "0.7" }
thiserror = "1"
log = "0.4"

# isahc
isahc = { version = "1.1.0", optional = true, features = ["json"] }
# wasm
cfg-if = { version = "1" }
wasm-bindgen = { version = "0.2.95", features = ["serde-serialize"] }
wasm-bindgen-futures = { version = "0.4" }
console_error_panic_hook = { version = "0.1.1" }
wee_alloc = { version = "0.4.2" }
js-sys = { version = "0.3" }
web-sys = { version = "0.3", features = [ 'Headers', 'Request', 'RequestInit', 'Response', 'ServiceWorkerGlobalScope', 'Window', 'console' ] }
console_log = { version = "1", features = ["color"] }

[dependencies]
base64.workspace = true
chrono.workspace = true
http.workspace = true
serde.workspace = true
serde_derive.workspace = true
serde_json.workspace = true
serde_urlencoded.workspace = true
thiserror.workspace = true
log.workspace = true
bytes = { version = "1", optional = true }

# reqwest
reqwest = { version = "0.11.2", optional = true, features = ["json"] }
reqwest = { version = "0.12", optional = true, features = [] }

# ureq
ureq = { version = "2.1.0", optional = true, features = ["json"] }
ureq = { version = "3.0.0-rc2", optional = true, features = ["json"] }

# wasm
[target.'cfg(target_arch = "wasm32")'.dependencies]
cfg-if = { version = "0.1.2" }
cfg-if = { version = "1" }
wasm-bindgen = { version = "0.2.95", features = ["serde-serialize"] }
wasm-bindgen-futures = { version = "0.4" }
console_error_panic_hook = { version = "0.1.1" }
Expand All @@ -63,40 +90,16 @@ features = [
]

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.0"
console_log = { version = "0.2", features = ["color"] }
wasm-bindgen-test = "0.3.45"
console_log = { workspace = true, features = ["color"] }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
futures-lite = { version = "1.11" }
futures-io = { version = "0.3.13" }
futures-core = { version = "0.3.13" }
futures-lite = { version = "2.3" }
futures-io = { version = "0.3" }
futures-core = { version = "0.3" }
tokio = { version = "1.2", default-features = false, features = ["macros", "rt-multi-thread"] }
env_logger = "0.8"
env_logger = "0.11"

[package.metadata.docs.rs]
features = [
"ant-man",
"baptiste",
"cloak",
"comfort-fade",
"corsair",
"dorian",
"flash",
"groot",
"inertia",
"london",
"luke-cage",
"lydian",
"mercy",
"mockingbird",
"nebula",
"scarlet-witch",
"squirrel-girl",
"starfox",
"surtur",
"switcheroo",
"wyandotte",
"zzzax"
]
default-target = "x86_64-unknown-linux-gnu"
targets = ["wasm32-unknown-unknown"]
115 changes: 59 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
[![license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![docs](https://docs.rs/roctogen/badge.svg)](https://docs.rs/roctogen/)
[![GitHub workflow](https://github.com/github/docs/actions/workflows/default.yml/badge.svg)](https://github.com/fussybeaver/roctogen/actions/workflows/default.yml)
[![GitHub workflow](https://github.com/fussybeaver/roctogen/actions/workflows/default.yml/badge.svg)](https://github.com/fussybeaver/roctogen/actions/workflows/default.yml)

## Roctogen: a rust client library for the GitHub v3 API
## Roctogen: Rust Client Library for GitHub v3 API

This client API is generated from the [upstream OpenAPI
specification](https://github.com/github/rest-api-description/). The library currently supports
webassembly and both tokio and non-tokio based asynchronous requests and minimal dependency blocking
synchronous requests with a choice of different clients, enabled through cargo features:
**Roctogen** is a Rust library generated from the [GitHub REST API OpenAPI
specification](https://github.com/github/rest-api-description/). providing
comprehensive support for the GitHub v3 API. It offers flexible support for
both synchronous and asynchronous HTTP clients, including WebAssembly
compatibility. You can choose between multiple client libraries via Cargo
features, or integrate your own HTTP client handling by extending the
`adapter` subsytem:

- `isahc` feature (*sync* and non-tokio based *async*): [Isahc HTTP client](https://github.com/sagebind/isahc)
- `reqwest` feature (*async*) [Reqwest client](https://github.com/seanmonstar/reqwest)
- `ureq` feature (*sync*) [Ureq client](https://github.com/algesten/ureq)
- `reqwest`: Enables asynchronous requests using the [Reqwest client](https://github.com/seanmonstar/reqwest)
- `ureq`: Provides synchronous requests with the [Ureq client](https://github.com/algesten/ureq)

## Install
### Installation

Add the following to your `Cargo.toml` file
To include Roctogen in your project, add it to your `Cargo.toml`:

```nocompile
[dependencies]
roctogen = "0.12"
roctogen = "*"
```

## API
### Documentation

[API docs](https://docs.rs/roctogen/latest).
- [API docs](https://docs.rs/roctogen/latest).
- [Endpoints](https://docs.rs/roctogen/latest/roctogen/endpoints/index.html).

[Endpoints](https://docs.rs/roctogen/latest/roctogen/endpoints/index.html).
#### Supported endpoints:

Supported endpoints:
---
Roctogen supports a wide range of GitHub API endpoints, including:

- [Meta](https://docs.rs/roctogen/latest/roctogen/endpoints/meta/struct.Meta.html)
- [Issues](https://docs.rs/roctogen/latest/roctogen/endpoints/issues/struct.Issues.html)
Expand Down Expand Up @@ -69,31 +70,37 @@ Supported endpoints:
- [Codespaces](https://docs.rs/roctogen/latest/roctogen/endpoints/codespaces/struct.Codespaces.html)
- [Emojis](https://docs.rs/roctogen/latest/roctogen/endpoints/emojis/struct.Emojis.html)

## Usage
For a full list of supported endpoints, refer to the [API documentation](https://docs.rs/roctogen/latest/roctogen/endpoints/index.html).

A quick example of this library:
### Usage

Here's a basic example demonstrating how to use Roctogen:

```rust
use roctogen::api::{self, repos};
use roctogen::adapters::client;
use roctogen::auth::Auth;

let auth = Auth::None;
let client = client(&auth).expect("Cannot create new client");
let per_page = api::PerPage::new(10);

let mut params: repos::ReposListCommitsParams = per_page.as_ref().into();
params = params.author("fussybeaver").page(2);

repos::new(&auth).list_commits("fussybeaver", "bollard", Some(params));
repos::new(&client).list_commits("fussybeaver", "bollard", Some(params));
```

### Async
#### Asynchronous Requests

All the `async` methods are suffixed with `_async`, and are available on the wasm target or `isahc` and `reqwest` adapters.
For async support, use the `_async` suffix for method calls. These are
available with the `reqwest`, or WebAssembly targets.

### Webassembly
#### Webassembly

To compile for webassembly, you can use [`wasm-pack`](https://github.com/rustwasm/wasm-pack) or compile with the
`wasm32-unknown-unknown` target:
Roctogen can be compiled to WebAssembly using
[`wasm-pack`](https://github.com/rustwasm/wasm-pack) or by directly
targeting wasm32-unknown-unknown:

```nocompile
$ wasm-pack build
Expand All @@ -103,80 +110,76 @@ $ wasm-pack build
$ cargo build --target wasm32-unknown-unknown
```

If you are building a [cloudflare worker](https://workers.cloudflare.com/), you would use the
`wrangler` wrapper:

```nocompile
$ wrangler preview --watch
```

### Client adapters

Building on non-`wasm` targets generally requires adopting a feature for the desired
client adapter.

#### Isahc

Compiling for the [`isahc`](https://github.com/sagebind/isahc) client required the `isahc` feature:

```nocompile
$ cargo build --features isahc
```
Roctogen supports multiple HTTP clients, or you can write your own. Enable
the desired client using Cargo features:

#### Reqwest

Compiling for the [`reqwest`](https://github.com/seanmonstar/reqwest) client required the `reqwest` feature:
Compile with Reqwest support using the `reqwest` feature:

```nocompile
$ cargo build --features reqwest
```

#### Ureq

Compiling for the [`ureq`](https://github.com/algesten/ureq) client required the `ureq` feature:
Compile with Ureq support using the `ureq` feature:

```nocompile
$ cargo build --features ureq
```

## Generate the API
#### Custom Client Adapters

It's possible to write your own adapter, by extending
`roctogen::adapters::Client`. This allows you to handle rate limiting and
pagination - an example of extending the base adapter is available in the
example [`min-req-adapter`](/fussybeaver/roctogen/tree/master/examples/min-req-adapter).

### Generating the API

The majority of code is generated through the [Swagger OpenAPI
generator](https://github.com/swagger-api/swagger-codegen) (version 3). Building requires the
[`mvn`](https://maven.apache.org/install.html) Java build tool, pegged at Java version 8 (so
you'll need an appropriate JDK).
Roctogen's code is largely generated from the GitHub REST API specification
using the [Swagger OpenAPI
generator](https://github.com/swagger-api/swagger-codegen) (version 3).
Building the API requires the Java-based `mvn` tool with JDK 8 installed:

```nocompile
$ mvn -D org.slf4j.simpleLogger.defaultLogLevel=info clean compiler:compile generate-resources
```

## Tests
### Testing

Beware, tests that are not run with the `mock` feature are currently still doing real HTTP requests to the GitHub API.
Roctogen supports both WebAssembly and synchronous test environments. Be
aware that some tests perform real HTTP requests to the GitHub API unless
mocked.

Run the wasm tests:
- **WebAssembly Tests**:

```nocompile
$ wasm-pack test --firefox --headless
```

Run the sync tests:
- ** **Synchronous Tests**:

```nocompile
$ cargo test --features isahc,mercy,squirrel-girl,inertia,starfox --target x86_64-unknown-linux-gnu -- --nocapture
```

In order to avoid GitHub's API rate limiting, you can run the non-wasm tests using wiremock.
You'll need to start wiremock in the background:
To avoid GitHub's API rate limits during testing, you can use WireMock to
mock the API locally. Run the following to start WireMock, and run the
tests with the `--mock` feature:

```nocompile
$ docker run -d --name wiremock -p 8080:8080 -v $PWD/tests/stubs:/home/wiremock
rodolpheche/wiremock
$ cargo test --feature mock,ureq
```

#### Regenerate the wiremock stubs

You should regenerate the stubs if the remote API has changed:
If the GitHub API changes, you can regenerate the WireMock stubs:

```nocompile
$ docker run -d --name wiremock -p 8080:8080 -v $PWD/tests/stubs:/home/wiremock -u (id -u):(id -g) rodolpheche/wiremock --verbose --proxy-all="https://api.github.com" --record-mappings
Expand Down
Loading

0 comments on commit b1fcb88

Please sign in to comment.