Skip to content

Commit 101a79a

Browse files
committed
[e2e-example] add a version with query params
1 parent ed0ca0e commit 101a79a

3 files changed

Lines changed: 181 additions & 4 deletions

File tree

e2e-example/apis/src/lib.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025 Oxide Computer Company
1+
// Copyright 2026 Oxide Computer Company
22

33
//! Example API descriptions for the Dropshot API manager -- a couple of
44
//! examples, one that's lockstep and one that's versioned.
@@ -19,12 +19,15 @@ pub mod lockstep {
1919
}
2020

2121
pub mod versioned {
22-
use dropshot::{HttpError, HttpResponseOk, RequestContext};
22+
use dropshot::{HttpError, HttpResponseOk, Query, RequestContext};
2323
use dropshot_api_manager_types::api_versions;
2424
use schemars::JsonSchema;
25-
use serde::Serialize;
25+
use serde::{Deserialize, Serialize};
2626

2727
api_versions!([
28+
// Version 4.0.0 adds an endpoint with query parameters, to test
29+
// detection of query parameter changes.
30+
(4, WITH_QUERY_PARAMS),
2831
// Version 3.0.0 was added to capture bytewise changes to the schema
2932
// serialization (e.g., the Number wrapper type being serialized as a
3033
// separate schema instead of inlined).
@@ -64,6 +67,19 @@ pub mod versioned {
6467
async fn get_thing_v2(
6568
rqctx: RequestContext<Self::Context>,
6669
) -> Result<HttpResponseOk<ThingV2>, HttpError>;
70+
71+
/// Search for items.
72+
///
73+
/// This endpoint demonstrates query parameters for testing purposes.
74+
#[endpoint {
75+
method = GET,
76+
path = "/search",
77+
versions = VERSION_WITH_QUERY_PARAMS..
78+
}]
79+
async fn search(
80+
rqctx: RequestContext<Self::Context>,
81+
query_params: Query<SearchParams>,
82+
) -> Result<HttpResponseOk<Vec<SearchResult>>, HttpError>;
6783
}
6884

6985
#[derive(Serialize, JsonSchema)]
@@ -85,4 +101,20 @@ pub mod versioned {
85101

86102
#[derive(Serialize, JsonSchema)]
87103
struct Number(u32);
104+
105+
/// Query parameters for the search endpoint.
106+
#[derive(Deserialize, JsonSchema)]
107+
pub struct SearchParams {
108+
/// The search query string.
109+
pub query: String,
110+
}
111+
112+
/// A search result item.
113+
#[derive(Serialize, JsonSchema)]
114+
pub struct SearchResult {
115+
/// The ID of the matching item.
116+
pub id: u64,
117+
/// The name of the matching item.
118+
pub name: String,
119+
}
88120
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
{
2+
"openapi": "3.0.3",
3+
"info": {
4+
"title": "Versioned API",
5+
"description": "A versioned API",
6+
"version": "4.0.0"
7+
},
8+
"paths": {
9+
"/search": {
10+
"get": {
11+
"summary": "Search for items.",
12+
"description": "This endpoint demonstrates query parameters for testing purposes.",
13+
"operationId": "search",
14+
"parameters": [
15+
{
16+
"in": "query",
17+
"name": "query",
18+
"description": "The search query string.",
19+
"required": true,
20+
"schema": {
21+
"type": "string"
22+
}
23+
}
24+
],
25+
"responses": {
26+
"200": {
27+
"description": "successful operation",
28+
"content": {
29+
"application/json": {
30+
"schema": {
31+
"title": "Array_of_SearchResult",
32+
"type": "array",
33+
"items": {
34+
"$ref": "#/components/schemas/SearchResult"
35+
}
36+
}
37+
}
38+
}
39+
},
40+
"4XX": {
41+
"$ref": "#/components/responses/Error"
42+
},
43+
"5XX": {
44+
"$ref": "#/components/responses/Error"
45+
}
46+
}
47+
}
48+
},
49+
"/thing": {
50+
"get": {
51+
"summary": "Fetch `thing`",
52+
"operationId": "get_thing",
53+
"responses": {
54+
"200": {
55+
"description": "successful operation",
56+
"content": {
57+
"application/json": {
58+
"schema": {
59+
"$ref": "#/components/schemas/ThingV2"
60+
}
61+
}
62+
}
63+
},
64+
"4XX": {
65+
"$ref": "#/components/responses/Error"
66+
},
67+
"5XX": {
68+
"$ref": "#/components/responses/Error"
69+
}
70+
}
71+
}
72+
}
73+
},
74+
"components": {
75+
"schemas": {
76+
"Error": {
77+
"description": "Error information from a response.",
78+
"type": "object",
79+
"properties": {
80+
"error_code": {
81+
"type": "string"
82+
},
83+
"message": {
84+
"type": "string"
85+
},
86+
"request_id": {
87+
"type": "string"
88+
}
89+
},
90+
"required": [
91+
"message",
92+
"request_id"
93+
]
94+
},
95+
"Number": {
96+
"type": "integer",
97+
"format": "uint32",
98+
"minimum": 0
99+
},
100+
"SearchResult": {
101+
"description": "A search result item.",
102+
"type": "object",
103+
"properties": {
104+
"id": {
105+
"description": "The ID of the matching item.",
106+
"type": "integer",
107+
"format": "uint64",
108+
"minimum": 0
109+
},
110+
"name": {
111+
"description": "The name of the matching item.",
112+
"type": "string"
113+
}
114+
},
115+
"required": [
116+
"id",
117+
"name"
118+
]
119+
},
120+
"ThingV2": {
121+
"type": "object",
122+
"properties": {
123+
"thing_number": {
124+
"$ref": "#/components/schemas/Number"
125+
}
126+
},
127+
"required": [
128+
"thing_number"
129+
]
130+
}
131+
},
132+
"responses": {
133+
"Error": {
134+
"description": "Error",
135+
"content": {
136+
"application/json": {
137+
"schema": {
138+
"$ref": "#/components/schemas/Error"
139+
}
140+
}
141+
}
142+
}
143+
}
144+
}
145+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
versioned-3.0.0-b48dc9.json
1+
versioned-4.0.0-92a798.json

0 commit comments

Comments
 (0)