From 14a463dd08f0f4e663794b62a687f114c205b174 Mon Sep 17 00:00:00 2001 From: Sven Reinhardt Date: Wed, 22 Jun 2022 13:58:36 +0200 Subject: [PATCH] fix javadoc of JsonUnwrapped fields not set --- .../javadoc/JavadocPropertyCustomizer.java | 4 ++ .../test/org/springdoc/api/app165/Bar.java | 29 ++++++++ .../test/org/springdoc/api/app165/Foo.java | 32 +++++++++ .../springdoc/api/app165/HelloController.java | 42 ++++++++++++ .../api/app165/SpringDocApp165Test.java | 36 ++++++++++ .../src/test/resources/results/app165.json | 67 +++++++++++++++++++ 6 files changed, 210 insertions(+) create mode 100644 springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/Bar.java create mode 100644 springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/Foo.java create mode 100644 springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/HelloController.java create mode 100644 springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/SpringDocApp165Test.java create mode 100644 springdoc-openapi-javadoc/src/test/resources/results/app165.json diff --git a/springdoc-openapi-javadoc/src/main/java/org/springdoc/openapi/javadoc/JavadocPropertyCustomizer.java b/springdoc-openapi-javadoc/src/main/java/org/springdoc/openapi/javadoc/JavadocPropertyCustomizer.java index 170723d5e..f48b39549 100644 --- a/springdoc-openapi-javadoc/src/main/java/org/springdoc/openapi/javadoc/JavadocPropertyCustomizer.java +++ b/springdoc-openapi-javadoc/src/main/java/org/springdoc/openapi/javadoc/JavadocPropertyCustomizer.java @@ -28,6 +28,8 @@ import java.util.Map; import java.util.Optional; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.databind.JavaType; import io.swagger.v3.core.converter.AnnotatedType; import io.swagger.v3.core.converter.ModelConverter; @@ -125,6 +127,8 @@ private void setJavadocDescription(Class cls, List fields, Schema exis stringSchemaEntry.getValue().setDescription(fieldJavadoc); }); }); + fields.stream().filter(f -> f.isAnnotationPresent(JsonUnwrapped.class)) + .forEach(f -> setJavadocDescription(f.getType(), FieldUtils.getAllFieldsList(f.getType()), existingSchema)); } } diff --git a/springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/Bar.java b/springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/Bar.java new file mode 100644 index 000000000..e24c6fb2b --- /dev/null +++ b/springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/Bar.java @@ -0,0 +1,29 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * https://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package test.org.springdoc.api.app165; + +/** + * The type Bar. + */ +public class Bar { + /** + * The BarField. + */ + public String barField = "bar"; +} diff --git a/springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/Foo.java b/springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/Foo.java new file mode 100644 index 000000000..14c440e91 --- /dev/null +++ b/springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/Foo.java @@ -0,0 +1,32 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * https://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package test.org.springdoc.api.app165; + +import com.fasterxml.jackson.annotation.JsonUnwrapped; + +/** + * The type Foo. + */ +public class Foo { + /** + * The Bar. + */ + @JsonUnwrapped + public Bar bar; +} diff --git a/springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/HelloController.java b/springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/HelloController.java new file mode 100644 index 000000000..d090bdced --- /dev/null +++ b/springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/HelloController.java @@ -0,0 +1,42 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * https://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package test.org.springdoc.api.app165; + +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +import io.swagger.v3.oas.annotations.parameters.RequestBody; + +/** + * The type Hello controller. + */ +@RestController("/api") +public class HelloController { + + /** + * Process foo. + * + * @param a the a + * @return the foo + */ + @PostMapping + public Foo process(@RequestBody Foo a) { + return a; + } +} \ No newline at end of file diff --git a/springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/SpringDocApp165Test.java b/springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/SpringDocApp165Test.java new file mode 100644 index 000000000..7fee65d42 --- /dev/null +++ b/springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app165/SpringDocApp165Test.java @@ -0,0 +1,36 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * https://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package test.org.springdoc.api.app165; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import test.org.springdoc.api.AbstractSpringDocTest; + +/** + * The type Spring doc app 165 test. + */ +public class SpringDocApp165Test extends AbstractSpringDocTest { + + /** + * The type Spring doc test app. + */ + @SpringBootApplication + static class SpringDocTestApp { + } +} \ No newline at end of file diff --git a/springdoc-openapi-javadoc/src/test/resources/results/app165.json b/springdoc-openapi-javadoc/src/test/resources/results/app165.json new file mode 100644 index 000000000..47858b4c8 --- /dev/null +++ b/springdoc-openapi-javadoc/src/test/resources/results/app165.json @@ -0,0 +1,67 @@ +{ + "openapi": "3.0.1", + "info": { + "title": "OpenAPI definition", + "version": "v0" + }, + "servers": [ + { + "url": "http://localhost", + "description": "Generated server url" + } + ], + "tags": [ + { + "name": "hello-controller", + "description": "The type Hello controller." + } + ], + "paths": { + "/": { + "post": { + "tags": [ + "hello-controller" + ], + "summary": "Process foo.", + "description": "Process foo.", + "operationId": "process", + "requestBody": { + "description": "the a", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Foo" + } + } + } + }, + "responses": { + "200": { + "description": "the foo", + "content": { + "*/*": { + "schema": { + "$ref": "#/components/schemas/Foo" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "Foo": { + "type": "object", + "properties": { + "barField": { + "type": "string", + "description": "The BarField." + } + }, + "description": "The type Foo." + } + } + } +} \ No newline at end of file