Skip to content

Commit b26ba89

Browse files
authored
Merge pull request #3 from Tuntii/0.0.3-Performance
Swager Auth UI
2 parents 623ed69 + 095a9da commit b26ba89

File tree

33 files changed

+5862
-60
lines changed

33 files changed

+5862
-60
lines changed

.github/workflows/ci.yml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
RUST_BACKTRACE: 1
12+
13+
jobs:
14+
test:
15+
name: Test
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Install Rust
21+
uses: dtolnay/rust-toolchain@stable
22+
23+
- name: Cache cargo registry
24+
uses: actions/cache@v4
25+
with:
26+
path: |
27+
~/.cargo/registry
28+
~/.cargo/git
29+
target
30+
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
31+
restore-keys: |
32+
${{ runner.os }}-cargo-test-
33+
34+
- name: Run tests
35+
run: cargo test --workspace
36+
37+
- name: Run tests with all features
38+
run: cargo test --workspace --all-features
39+
40+
lint:
41+
name: Lint
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v4
45+
46+
- name: Install Rust
47+
uses: dtolnay/rust-toolchain@stable
48+
with:
49+
components: rustfmt, clippy
50+
51+
- name: Cache cargo registry
52+
uses: actions/cache@v4
53+
with:
54+
path: |
55+
~/.cargo/registry
56+
~/.cargo/git
57+
target
58+
key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }}
59+
restore-keys: |
60+
${{ runner.os }}-cargo-lint-
61+
62+
- name: Check formatting
63+
run: cargo fmt --all -- --check
64+
65+
- name: Run clippy
66+
run: cargo clippy --workspace --all-features -- -D warnings
67+
68+
build:
69+
name: Build
70+
runs-on: ubuntu-latest
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- name: Install Rust
75+
uses: dtolnay/rust-toolchain@stable
76+
77+
- name: Cache cargo registry
78+
uses: actions/cache@v4
79+
with:
80+
path: |
81+
~/.cargo/registry
82+
~/.cargo/git
83+
target
84+
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
85+
restore-keys: |
86+
${{ runner.os }}-cargo-build-
87+
88+
- name: Build
89+
run: cargo build --workspace
90+
91+
- name: Build with all features
92+
run: cargo build --workspace --all-features
93+
94+
- name: Build release
95+
run: cargo build --workspace --release
96+
97+
docs:
98+
name: Documentation
99+
runs-on: ubuntu-latest
100+
steps:
101+
- uses: actions/checkout@v4
102+
103+
- name: Install Rust
104+
uses: dtolnay/rust-toolchain@stable
105+
106+
- name: Cache cargo registry
107+
uses: actions/cache@v4
108+
with:
109+
path: |
110+
~/.cargo/registry
111+
~/.cargo/git
112+
target
113+
key: ${{ runner.os }}-cargo-docs-${{ hashFiles('**/Cargo.lock') }}
114+
restore-keys: |
115+
${{ runner.os }}-cargo-docs-
116+
117+
- name: Build documentation
118+
run: cargo doc --workspace --all-features --no-deps
119+
env:
120+
RUSTDOCFLAGS: -D warnings
121+
122+
msrv:
123+
name: MSRV (1.75)
124+
runs-on: ubuntu-latest
125+
steps:
126+
- uses: actions/checkout@v4
127+
128+
- name: Install Rust 1.75
129+
uses: dtolnay/rust-action@1.75
130+
131+
- name: Cache cargo registry
132+
uses: actions/cache@v4
133+
with:
134+
path: |
135+
~/.cargo/registry
136+
~/.cargo/git
137+
target
138+
key: ${{ runner.os }}-cargo-msrv-${{ hashFiles('**/Cargo.lock') }}
139+
restore-keys: |
140+
${{ runner.os }}-cargo-msrv-
141+
142+
- name: Check MSRV
143+
run: cargo check --workspace --all-features

CHANGELOG.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.1.2] - 2024-12-31
11+
12+
### Added
13+
- `skip_paths` method for JwtLayer to exclude paths from JWT validation
14+
- `docs_with_auth` method for Basic Auth protected Swagger UI
15+
- `docs_with_auth_and_info` method for customized protected docs
16+
17+
### Changed
18+
- auth-api example now demonstrates protected docs with Basic Auth
19+
- JWT middleware can now skip validation for public endpoints
20+
21+
## [0.1.1] - 2024-12-31
22+
23+
### Added
24+
25+
#### Phase 4: Ergonomics & v1.0 Preparation
26+
- Body size limit middleware with configurable limits
27+
- `.body_limit(size)` builder method on RustApi (default: 1MB)
28+
- 413 Payload Too Large response for oversized requests
29+
- Production error masking (`RUSTAPI_ENV=production`)
30+
- Development error details (`RUSTAPI_ENV=development`)
31+
- Unique error IDs (`err_{uuid}`) for log correlation
32+
- Enhanced tracing layer with request_id, status, and duration
33+
- Custom span field support via `.with_field(key, value)`
34+
- Prometheus metrics middleware (feature-gated)
35+
- `http_requests_total` counter with method, path, status labels
36+
- `http_request_duration_seconds` histogram
37+
- `rustapi_info` gauge with version information
38+
- `/metrics` endpoint handler
39+
- TestClient for integration testing without network binding
40+
- TestRequest builder with method, header, and body support
41+
- TestResponse with assertion helpers
42+
- `RUSTAPI_DEBUG=1` macro expansion output support
43+
- Improved route path validation at compile time
44+
- Enhanced route conflict detection messages
45+
46+
### Changed
47+
- Error responses now include `error_id` field
48+
- TracingLayer enhanced with additional span fields
49+
50+
## [0.1.0] - 2024-12-01
51+
52+
### Added
53+
54+
#### Phase 1: MVP Core
55+
- Core HTTP server built on tokio and hyper 1.0
56+
- Radix-tree based routing with matchit
57+
- Request extractors: `Json<T>`, `Query<T>`, `Path<T>`
58+
- Response types with automatic serialization
59+
- Async handler support
60+
- Basic error handling with `ApiError`
61+
- `#[rustapi::get]`, `#[rustapi::post]` route macros
62+
- `#[rustapi::main]` async main macro
63+
64+
#### Phase 2: Validation & OpenAPI
65+
- Automatic OpenAPI spec generation
66+
- Swagger UI at `/docs` endpoint
67+
- Request validation with validator crate
68+
- `#[validate]` attribute support
69+
- 422 Unprocessable Entity for validation errors
70+
- `#[rustapi::tag]` and `#[rustapi::summary]` macros
71+
- Schema derivation for request/response types
72+
73+
#### Phase 3: Batteries Included
74+
- JWT authentication middleware (`jwt` feature)
75+
- `AuthUser<T>` extractor for authenticated routes
76+
- CORS middleware with builder pattern (`cors` feature)
77+
- IP-based rate limiting (`rate-limit` feature)
78+
- Configuration management with `.env` support (`config` feature)
79+
- Cookie parsing extractor (`cookies` feature)
80+
- SQLx error conversion (`sqlx` feature)
81+
- Request ID middleware
82+
- Middleware layer trait for custom middleware
83+
- `extras` meta-feature for common optional features
84+
- `full` feature for all optional features
85+
86+
[Unreleased]: https://github.com/Tuntii/RustAPI/compare/v0.1.2...HEAD
87+
[0.1.2]: https://github.com/Tuntii/RustAPI/compare/v0.1.1...v0.1.2
88+
[0.1.1]: https://github.com/Tuntii/RustAPI/compare/v0.1.0...v0.1.1
89+
[0.1.0]: https://github.com/Tuntii/RustAPI/releases/tag/v0.1.0

CONTRIBUTING.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Contributing to RustAPI
2+
3+
Thank you for your interest in contributing to RustAPI! This document provides guidelines and information for contributors.
4+
5+
## Code of Conduct
6+
7+
By participating in this project, you agree to maintain a respectful and inclusive environment for everyone.
8+
9+
## Getting Started
10+
11+
1. Fork the repository
12+
2. Clone your fork: `git clone https://github.com/Tuntii/RustAPI.git`
13+
3. Create a new branch: `git checkout -b feature/your-feature-name`
14+
4. Make your changes
15+
5. Run tests: `cargo test --workspace`
16+
6. Submit a pull request
17+
18+
## Development Setup
19+
20+
### Prerequisites
21+
22+
- Rust 1.75 or later
23+
- Cargo (comes with Rust)
24+
25+
### Building
26+
27+
```bash
28+
# Build all crates
29+
cargo build --workspace
30+
31+
# Build with all features
32+
cargo build --workspace --all-features
33+
```
34+
35+
### Running Tests
36+
37+
```bash
38+
# Run all tests
39+
cargo test --workspace
40+
41+
# Run tests with all features
42+
cargo test --workspace --all-features
43+
44+
# Run a specific crate's tests
45+
cargo test -p rustapi-core
46+
```
47+
48+
## Code Style
49+
50+
### Formatting
51+
52+
All code must be formatted with `rustfmt`:
53+
54+
```bash
55+
cargo fmt --all
56+
```
57+
58+
### Linting
59+
60+
All code must pass `clippy` checks:
61+
62+
```bash
63+
cargo clippy --workspace --all-features -- -D warnings
64+
```
65+
66+
### Documentation
67+
68+
- All public APIs must have rustdoc documentation
69+
- Include code examples in doc comments where appropriate
70+
- Doc examples must compile and run
71+
72+
## Pull Request Process
73+
74+
1. **Create a descriptive PR title** following conventional commits:
75+
- `feat:` for new features
76+
- `fix:` for bug fixes
77+
- `docs:` for documentation changes
78+
- `refactor:` for code refactoring
79+
- `test:` for test additions/changes
80+
- `chore:` for maintenance tasks
81+
82+
2. **Fill out the PR template** with:
83+
- Description of changes
84+
- Related issue numbers
85+
- Testing performed
86+
87+
3. **Ensure all checks pass**:
88+
- All tests pass
89+
- Code is formatted (`cargo fmt`)
90+
- No clippy warnings (`cargo clippy`)
91+
- Documentation builds
92+
93+
4. **Request review** from maintainers
94+
95+
5. **Address feedback** promptly and push updates
96+
97+
## Commit Guidelines
98+
99+
- Write clear, concise commit messages
100+
- Use present tense ("Add feature" not "Added feature")
101+
- Reference issues when applicable (`Fixes #123`)
102+
103+
## Project Structure
104+
105+
```
106+
RustAPI/
107+
├── crates/
108+
│ ├── rustapi-rs/ # Public-facing crate (re-exports)
109+
│ ├── rustapi-core/ # Core HTTP engine and routing
110+
│ ├── rustapi-macros/ # Procedural macros
111+
│ ├── rustapi-validate/ # Validation integration
112+
│ ├── rustapi-openapi/ # OpenAPI/Swagger support
113+
│ └── rustapi-extras/ # Optional features (JWT, CORS, etc.)
114+
├── examples/ # Example applications
115+
├── benches/ # Benchmarks
116+
└── scripts/ # Build and publish scripts
117+
```
118+
119+
## Adding New Features
120+
121+
1. Discuss the feature in an issue first
122+
2. Follow the existing architecture patterns
123+
3. Add tests for new functionality
124+
4. Update documentation
125+
5. Add examples if applicable
126+
127+
## Reporting Issues
128+
129+
When reporting issues, please include:
130+
131+
- Rust version (`rustc --version`)
132+
- RustAPI version
133+
- Minimal reproduction code
134+
- Expected vs actual behavior
135+
- Error messages (if any)
136+
137+
## Questions?
138+
139+
Feel free to open an issue for questions or join discussions in existing issues.
140+
141+
Thank you for contributing to RustAPI!

0 commit comments

Comments
 (0)