Skip to content

Commit

Permalink
Updated for release
Browse files Browse the repository at this point in the history
  • Loading branch information
wafflespeanut committed Jul 30, 2019
1 parent e72484c commit a0cfe6f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.3.0] - 2019-07-30
### Added
- Paperclip's `#[api_v2_schema]` derives raw schema structs (i.e., no smart pointers) along with actual schema structs for other users and plugins. An effect of this would be that now there's a `DefaultSchemaRaw` in addition to `DefaultSchema`.
- `TypedData`, `Apiv2Schema` and `Apiv2Operation` traits for deriving v2 spec for server plugins.
- `paperclip-core` crate for segregating core types and traits.
- `paperclip-actix` crate as an actix-web plugin for hosting v2 spec as a JSON by marking models and operations using proc macro attributes.
- `paperclip::actix` module for exporting `paperclip_actix::*` when `actix` feature is enabled.

### Changed
- Moved away from workspaces to individual crates and added features for paperclip.
- Segregated dependencies using feature gates.
- `Api::<S>::resolve` now returns `ValidationError` instead of `failure::Error`.
- During serialization, optional schema fields are skipped when empty/null.

Expand Down Expand Up @@ -56,6 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Loading OpenAPI v2 schema from JSON/YAML
- Workspace, README, LICENSE, Makefile, CI config, etc.

[Unreleased]: https://github.com/wafflespeanut/paperclip/compare/v0.2.0...HEAD
[Unreleased]: https://github.com/wafflespeanut/paperclip/compare/v0.3.0...HEAD
[0.1.0]: https://github.com/wafflespeanut/paperclip/releases/tag/v0.1.0
[0.2.0]: https://github.com/wafflespeanut/paperclip/releases/tag/v0.2.0
[0.3.0]: https://github.com/wafflespeanut/paperclip/releases/tag/v0.3.0
17 changes: 12 additions & 5 deletions book/actix-plugin.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Host OpenAPI spec through actix-web
# Host OpenAPI v2 spec through actix-web

With `actix` feature enabled, paperclip exports an **experimental** plugin for [actix-web](https://github.com/actix/actix-web) framework to host OpenAPI spec for your APIs *automatically*. While it's not feature complete, you can rely on it to not break your actix-web flow.
With `actix` feature enabled, paperclip exports an **experimental** plugin for [actix-web](https://github.com/actix/actix-web) framework to host OpenAPI v2 spec for your APIs *automatically*. While it's not feature complete, you can rely on it to not break your actix-web flow.

Let's start with a simple actix-web application. It has `actix-web` and `serde` for JSON'ifying your APIs. Let's also add `paperclip` with `actix` feature.

Expand Down Expand Up @@ -148,9 +148,14 @@ curl http://localhost:8080/api/spec

Similarly, if we were to use other extractors like `web::Query<T>`, `web::Form<T>` or `web::Path`, the plugin will emit the corresponding specification as expected.

#### Known Limitations
#### Known limitations

At the time of this writing, this plugin didn't support a number of OpenAPI features:
- **Enums:** OpenAPI (v2) itself supports using simple enums (i.e., with unit variants), but Rust and serde has support for variants with fields and tuples. I still haven't looked deep enough either to argue that this cannot be done in OpenAPI or find an elegant way to represent this in OpenAPI.
- **Functions returning abstractions:** The plugin has no way to obtain any useful information from functions returning abstractions such as `HttpResponse`, `impl Responder` or containers such as `Result<T, E>` containing those abstractions. So, the plugin silently ignores these types, which results in an empty value in your hosted specification.

#### Missing features

At the time of this writing, this plugin didn't support a few OpenAPI v2 features:

Affected entity | Missing feature(s)
--------------- | ---------------
Expand All @@ -161,4 +166,6 @@ Security ([definitions](https://github.com/OAI/OpenAPI-Specification/blob/master

#### Performance implications?

Even though we use a wrapper and generate schema structs for building the spec, we do this only once i.e., until the `.build()` function call. At runtime, it's basically an [`Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html) deref and [`RwLock`](https://docs.rs/parking_lot/*/parking_lot/type.RwLock.html) read, which is quite fast!
Even though we use some wrappers and generate schema structs for building the spec, we do this only once i.e., until the `.build()` function call. At runtime, it's basically an [`Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html) deref and [`RwLock`](https://docs.rs/parking_lot/*/parking_lot/type.RwLock.html) read, which is quite fast!

We also add a wrapper to blocks in functions tagged with `#[api_v2_operation]`, but those wrappers are unit structs and the code eventually gets optimized away anyway.
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ log = "0.4"
paperclip-macros = { path = "../macros", version = "0.2.0" }
parking_lot = "0.9"
regex = "1.1"
serde = "1.0"
serde = { version = "1.0", features = ["derive"] }

[features]
actix = ["default", "actix-http", "actix-web", "futures"]
Expand Down

0 comments on commit a0cfe6f

Please sign in to comment.