diff --git a/dropshot/src/schema_util.rs b/dropshot/src/schema_util.rs index a3f4008f..19176655 100644 --- a/dropshot/src/schema_util.rs +++ b/dropshot/src/schema_util.rs @@ -929,6 +929,7 @@ mod test { use super::j2oas_schema; use super::j2oas_schema_object; + use super::make_subschema_for; use schemars::JsonSchema; #[test] @@ -1030,6 +1031,36 @@ mod test { ); } + #[test] + fn test_nullable_subschema() { + #[expect(dead_code)] + #[derive(JsonSchema)] + struct Foo { + bar: String, + } + let settings = schemars::r#gen::SchemaSettings::openapi3(); + let mut generator = schemars::r#gen::SchemaGenerator::new(settings); + + // BUG: Currently, the fact that the type is nullable is dropped from + // the output, leading to the generated schema for Option being + // the same as the one for Foo below. + let schema = make_subschema_for::>(&mut generator); + assert_eq!( + j2oas_schema(None, &schema), + openapiv3::ReferenceOr::Reference { + reference: "#/components/schemas/Foo".to_string() + } + ); + + let schema = make_subschema_for::(&mut generator); + assert_eq!( + j2oas_schema(None, &schema), + openapiv3::ReferenceOr::Reference { + reference: "#/components/schemas/Foo".to_string() + } + ); + } + /// These cases are errors, but we want to provide good error messages for /// them. #[test] diff --git a/dropshot/tests/integration-tests/openapi.rs b/dropshot/tests/integration-tests/openapi.rs index 170297f5..685fe554 100644 --- a/dropshot/tests/integration-tests/openapi.rs +++ b/dropshot/tests/integration-tests/openapi.rs @@ -688,6 +688,18 @@ async fn handler32( todo!(); } +#[endpoint { + method = PUT, + path = "/testing33", + tags = ["it"] +}] +async fn handler33( + _: RequestContext<()>, + _: TypedBody>, +) -> Result>, HttpError> { + todo!(); +} + fn make_api( maybe_tag_config: Option, ) -> Result, ApiDescriptionRegisterError> { @@ -729,6 +741,7 @@ fn make_api( api.register(handler30)?; api.register(handler31)?; api.register(handler32)?; + api.register(handler33)?; Ok(api) } diff --git a/dropshot/tests/test_openapi.json b/dropshot/tests/test_openapi.json index bf49feec..3e0c548d 100644 --- a/dropshot/tests/test_openapi.json +++ b/dropshot/tests/test_openapi.json @@ -935,6 +935,42 @@ } } }, + "/testing33": { + "put": { + "tags": [ + "it" + ], + "operationId": "handler33", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CoolStruct" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CoolStruct" + } + } + } + }, + "4XX": { + "$ref": "#/components/responses/Error" + }, + "5XX": { + "$ref": "#/components/responses/Error" + } + } + } + }, "/thing_with_headers": { "get": { "tags": [ diff --git a/dropshot/tests/test_openapi_fuller.json b/dropshot/tests/test_openapi_fuller.json index ffc25577..e2183e49 100644 --- a/dropshot/tests/test_openapi_fuller.json +++ b/dropshot/tests/test_openapi_fuller.json @@ -943,6 +943,42 @@ } } }, + "/testing33": { + "put": { + "tags": [ + "it" + ], + "operationId": "handler33", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CoolStruct" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CoolStruct" + } + } + } + }, + "4XX": { + "$ref": "#/components/responses/Error" + }, + "5XX": { + "$ref": "#/components/responses/Error" + } + } + } + }, "/thing_with_headers": { "get": { "tags": [