expression

OpenAPI: describe a required path parameter

A templated path parameter must be declared and required. Its schema describes accepted values. This fixture checks the local document’s integer ID declaration, not the entire OpenAPI specification. Standalone synthetic example. Expected stdout (not executed): integer Common mistake: Documenting a path parameter as optional.

Formal Syntax & Structure

rust syntaxrust
parameters: [{name: id, in: path, required: true}]

Working Example

Example Snippetrust
use axum::{Router, Json, body::{Body, to_bytes}, http::{Request, StatusCode}};use serde::{Deserialize, Serialize};use tower::ServiceExt;
#[tokio::main(flavor = "current_thread")]async fn main() {    let doc: serde_json::Value = serde_json::from_str(include_str!("../../openapi.json")).unwrap();    let p = &doc["paths"]["/items/{id}"]["get"]["parameters"][0];    assert_eq!(p["name"], "id");    assert_eq!(p["in"], "path");    assert_eq!(p["required"], true);    println!("{}", p["schema"]["type"].as_str().unwrap());}
Rust Reference