openapi_mocker/
lib.rs

1//! # OpenAPI Mock Server
2//!
3//! `openapi-mocker` is a simple mock server for OpenAPI 3.0 specs.
4//! It can be used to quickly create a mock server for an OpenAPI spec.
5//!
6//! The server will respond with example responses defined in the spec.
7//! If no example is defined, it will respond with an empty JSON object.
8//! The server will respond with a 200 status code by default, but you can
9//! specify a different status code in the URL.
10//!
11//! ## Usage
12//! ```sh
13//! openapi-mocker <spec> [port]
14//! ```
15//! * `<spec>` - Path to the OpenAPI spec file
16//! * `[port]` - Port to bind the server to (default: 8080)
17//!
18//! ## Example
19//! ```sh
20//! openapi-mocker tests/testdata/petstore.yaml
21//! ```
22//! This will start a server on port 8080 with the Petstore spec.
23//! You can then make requests to the server to get example responses.
24//! For example, to get a list of pets:
25//! ```sh
26//! curl http://localhost:8080/pets
27//! ```
28//! This will return a list of pets from the example response in the spec.
29use clap::Parser;
30use std::path::PathBuf;
31pub mod openapi;
32pub mod server;
33
34#[derive(Parser)]
35#[clap(version = "0.1.3", author = "Thiago Pacheco")]
36pub struct Args {
37    #[clap(index = 1)]
38    pub spec: PathBuf,
39    #[clap(short, long, default_value = "8080")]
40    pub port: Option<u16>,
41}