MCPcopy Create free account
hub / github.com/baerwang/openapi-rs / demonstrate_json_schema_dialect

Function demonstrate_json_schema_dialect

examples/openapi_31_features.rs:182–240  ·  view source on GitHub ↗

Demonstrates parsing and working with JSON Schema Dialect

()

Source from the content-addressed store, hash-verified

180
181/// Demonstrates parsing and working with JSON Schema Dialect
182fn demonstrate_json_schema_dialect() -> Result<()> {
183 let dialect_yaml = r#"
184openapi: 3.1.0
185jsonSchemaDialect: https://spec.openapis.org/oas/3.1/dialect/base
186info:
187 title: User Management API
188 version: '1.0.0'
189paths:
190 /users:
191 get:
192 summary: List users
193 parameters:
194 - name: limit
195 in: query
196 schema:
197 type: integer
198 minimum: 1
199 maximum: 100
200 default: 20
201 responses:
202 '200':
203 description: OK
204 "#;
205
206 let openapi: OpenAPI = OpenAPI::yaml(dialect_yaml)?;
207
208 println!(" OpenAPI Version: {}", openapi.openapi);
209
210 // Access JSON Schema Dialect
211 match &openapi.json_schema_dialect {
212 Some(dialect) => {
213 println!(" 📐 JSON Schema Dialect: {}", dialect);
214
215 // Parse and display info about the dialect
216 if dialect.contains("3.1") {
217 println!(" └─ Using OpenAPI 3.1 compatible dialect");
218 } else if dialect.contains("2020-12") {
219 println!(" └─ Using JSON Schema 2020-12");
220 } else if dialect.contains("2019-09") {
221 println!(" └─ Using JSON Schema 2019-09");
222 } else {
223 println!(" └─ Using custom dialect");
224 }
225 }
226 None => {
227 println!(" ℹ️ No JSON Schema Dialect specified (will use default)");
228 }
229 }
230
231 // Demonstrate that other 3.0 features still work
232 println!();
233 println!(" 📄 Paths Available: {}", openapi.paths.len());
234
235 for (path, _path_item) in openapi.paths.iter() {
236 println!(" - {}", path);
237 }
238
239 Ok(())

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected