Skip to content

Commit

Permalink
Update book
Browse files Browse the repository at this point in the history
  • Loading branch information
wafflespeanut committed Nov 29, 2020
1 parent 2639e52 commit cb735bf
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 12 deletions.
8 changes: 3 additions & 5 deletions book/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ It's currently under active development and may not be ready for production use

### Features

**[Compile-time checking](build-script.md#compile-time-checks)**: See how paperclip checks parameters for API calls at compile time!

**[Console checks](cli.md#runtime-checks)**: See how the console generated by paperclip checks API calls.

**[Actix-web hosting](actix-plugin.md)**: See how paperclip can be used to host the API spec for your `actix-web` application.
- Paperclip CLI can generate API client library (which checks some usage at [compile-time](compile-checks.md)) or a console for your API (which checks usage at [runtime](cli.md#runtime-checks)).
- API client code can also be generated using [build scripts](build-script.md) which will then check parameters usage in your library at compile time.
- [Acix-web plugin](actix-plugin.md) can be used to host the API spec for your `actix-web` application.

### Design

Expand Down
2 changes: 2 additions & 0 deletions book/actix-operation-meta.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## Adding additional metadata to operations

By default, the first doc comment (if any) is taken for the `summary` field and the rest of the following doc comments
(if any) will be taken as `description` for that operation.

Expand Down
1 change: 1 addition & 0 deletions book/actix-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ curl http://localhost:8080/api/spec
"swagger": "2.0",
"definitions": {
"Pet": {
"type": "object",
"properties": {
"id": {
"type": "integer",
Expand Down
3 changes: 2 additions & 1 deletion book/actix-schema-defaults.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## Setting defaults in API schema

It is possible to define default initial values for the schema, which might be useful to define "info",
"schemes", "tags" and other top level schema fields which are not inherited from handlers.

```rust
use paperclip::v2::models::DefaultApiRaw;
use paperclip::v2::models::{DefaultApiRaw, Tag};

let mut spec = DefaultApiRaw::default();
spec.tags = vec![
Expand Down
2 changes: 2 additions & 0 deletions book/actix-security.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## Defining security schemes for your API

You can use `Apiv2Security` derive macro for structs which can then be used as handler parameters to have those handlers marked as requiring authorization.

```rust
Expand Down
1 change: 1 addition & 0 deletions book/actix-status-codes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## Adding additional response status codes to operations

Paperclip deduces your API schema using macros (which read the types of handlers and parameter structs at compile time), so in order for paperclip to know what response code sent by the API, it needs type information about it at compile time. It cannot be inferred from response at runtime.

Expand Down
2 changes: 1 addition & 1 deletion book/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ GET http://echo.jsontest.com/pets/25

Passing `-v` flag enables verbose mode which prints additional information about the request we've made. Also note that the body of the response is piped to stdout directly.

### Request body
#### Request body

Finally, let's `POST` something with a body. Here, `add-pet` requires a payload, so `--payload` argument is required. This argument is special in that it could be either a path to a file or `-` (when input is obtained from stdin). Either way, the input is parsed to the actual schema before making the API call.

Expand Down
10 changes: 5 additions & 5 deletions book/compile-checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ API calls often *require* some parameters. Should we miss those parameters when
For example, in the [previous example](build-script.md), in order to fetch a pet, [`petId` parameter](https://github.com/wafflespeanut/paperclip/blob/fa95b023aaf8b6e396c899a93a9eda6fd791505c/openapi/tests/pet-v2.yaml#L42-L47) is required. Let's change the main function in the above example to fetch a pet without its ID.

```rust
let pet = Pet::get_pet_by_id().send(&client).compat().await?;
let pet = Pet::get_pet_by_id().send(&client).await?;
```

If we try and compile the program, then we'll get the following error:
Expand All @@ -24,7 +24,7 @@ Hence the fix would be to set the required parameter using the relevant method c
let pet = Pet::get_pet_by_id()
.id(25)
.send(&client)
.compat().await?;
.await?;
```

... and the code will compile.
Expand All @@ -34,7 +34,7 @@ The same applies to using API objects (with required fields). For example, the [
So, if we did this:

```rust
let pet = Pet::add_pet().send(&client).compat().await?;
let pet = Pet::add_pet().send(&client).await?;
```

... we'd get an error during compilation:
Expand All @@ -55,9 +55,9 @@ let pet = Pet::add_pet()
.id(25)
.name("Milo")
.send(&client)
.compat().await?;
.await?;
```

... and the code will compile.

> **NOTE:** The types of arguments are also enforced.
Similarly, the types of arguments are also enforced.

0 comments on commit cb735bf

Please sign in to comment.