# Path Generation
The `pathgen.rs` module generates type-safe API functions for every path and HTTP method in the OpenAPI spec.
```plantuml
@startuml
:OpenAPI Path\nwith HTTP methods;
:For each HTTP method;
:Build query param struct;
:Build response enum;
:Generate function body;
:Inject auth header;
:Generated Functions;
@enduml
```
## Function Generation
For each path item, a function is generated for each HTTP method (GET, PUT, POST, DELETE, PATCH, OPTIONS, HEAD, TRACE).
### Function Naming
Function names are derived from:
1. The `operationId` in the schema (if present)
2. A combination of the path (with base path stripped) and HTTP method
Example: path `/api/dcim/devices/` with `operationId: dcim_devices_list` becomes `dcim_devices_list`.
### Query Parameters
When a function has query parameters, a dedicated query struct is generated:
```rust
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
pub struct DevicesListQuery {
pub name: Option<Vec<String>>,
pub status: Option<Vec<String>>,
pub limit: Option<i64>,
pub offset: Option<i64>,
pub ordering: Option<String>,
pub q: Option<String>,
}
```
### Response Enums
Each function returns a `Result<ResponseEnum, Error>` where the response enum is discriminated by HTTP status code:
```rust
#[derive(Debug)]
pub enum DevicesListResponse {
Http200(PaginatedDeviceList),
Other(Response)
}
```
### Request Body
For POST, PUT, and PATCH operations, the request body type is taken from the `application/json` media type in the request body schema.
### Auth Header
Auth is handled generically. The generated code checks for `state.auth_header_value` (an `Option<String>`) and applies it to every request:
```rust
if let Some(ref auth) = state.auth_header_value {
r#request = r#request.header("Authorization", auth);
}
```
```admonish tip
Set `auth_header_value` to the complete Authorization header value, such as:
- `Some("Bearer mytoken".into())`
- `Some("Token mytoken".into())`
- `Some("Basic base64creds".into())`
```