Skip to content

Commit 64b9338

Browse files
committed
Improve OpenAPI documentation for PUT /api/v1/crates/new endpoint
1 parent aebebc4 commit 64b9338

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

src/controllers/krate/publish.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const MAX_DESCRIPTION_LENGTH: usize = 1000;
6363
("cookie" = []),
6464
),
6565
tag = "publish",
66-
responses((status = 200, description = "Successful Response")),
66+
responses((status = 200, description = "Successful Response", body = inline(GoodCrate))),
6767
)]
6868
pub async fn publish(app: AppState, req: Parts, body: Body) -> AppResult<Json<GoodCrate>> {
6969
let stream = body.into_data_stream();

src/snapshots/crates_io__openapi__tests__openapi_snapshot.snap

+51
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,38 @@ expression: response.json()
634634
],
635635
"type": "object"
636636
},
637+
"PublishWarnings": {
638+
"properties": {
639+
"invalid_badges": {
640+
"deprecated": true,
641+
"example": [],
642+
"items": {
643+
"type": "string"
644+
},
645+
"type": "array"
646+
},
647+
"invalid_categories": {
648+
"example": [],
649+
"items": {
650+
"type": "string"
651+
},
652+
"type": "array"
653+
},
654+
"other": {
655+
"example": [],
656+
"items": {
657+
"type": "string"
658+
},
659+
"type": "array"
660+
}
661+
},
662+
"required": [
663+
"invalid_categories",
664+
"invalid_badges",
665+
"other"
666+
],
667+
"type": "object"
668+
},
637669
"Slug": {
638670
"properties": {
639671
"description": {
@@ -1611,6 +1643,25 @@ expression: response.json()
16111643
"operationId": "publish",
16121644
"responses": {
16131645
"200": {
1646+
"content": {
1647+
"application/json": {
1648+
"schema": {
1649+
"properties": {
1650+
"crate": {
1651+
"$ref": "#/components/schemas/Crate"
1652+
},
1653+
"warnings": {
1654+
"$ref": "#/components/schemas/PublishWarnings"
1655+
}
1656+
},
1657+
"required": [
1658+
"crate",
1659+
"warnings"
1660+
],
1661+
"type": "object"
1662+
}
1663+
}
1664+
},
16141665
"description": "Successful Response"
16151666
}
16161667
},

src/views.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -983,17 +983,20 @@ pub struct EncodableVersionLinks {
983983
pub authors: String,
984984
}
985985

986-
#[derive(Serialize, Deserialize, Debug)]
986+
#[derive(Serialize, Deserialize, Debug, utoipa::ToSchema)]
987987
pub struct GoodCrate {
988988
#[serde(rename = "crate")]
989989
pub krate: EncodableCrate,
990990
pub warnings: PublishWarnings,
991991
}
992992

993-
#[derive(Serialize, Deserialize, Debug)]
993+
#[derive(Serialize, Deserialize, Debug, utoipa::ToSchema)]
994994
pub struct PublishWarnings {
995+
#[schema(example = json!([]))]
995996
pub invalid_categories: Vec<String>,
997+
#[schema(deprecated, example = json!([]))]
996998
pub invalid_badges: Vec<String>,
999+
#[schema(example = json!([]))]
9971000
pub other: Vec<String>,
9981001
}
9991002

0 commit comments

Comments
 (0)