Skip to content

Fixed a bug that a NullPointerException is thrown when the descriptio… #2110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,12 @@ else if (!methodAttributes.isWithResponseBodySchemaDoc()) {
mergeContent(requestBody, methodAttributes, schema);
}


// Add requestBody javadoc
if (StringUtils.isBlank(requestBody.getDescription()) && parameterBuilder.getJavadocProvider() != null
&& parameterBuilder.isRequestBodyPresent(parameterInfo)) {
String paramJavadocDescription = parameterBuilder.getParamJavadoc(parameterBuilder.getJavadocProvider(), parameterInfo.getMethodParameter());
if (!StringUtils.isBlank(paramJavadocDescription)) {
requestBodyInfo.getRequestBody().setDescription(paramJavadocDescription);
requestBody.setDescription(paramJavadocDescription);
}
}
return requestBody;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
*
* * Copyright 2019-2023 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.app168;

import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* If the RequestBody description field is null, get the description from the javadoc.
*/
@RestController
@RequestMapping("description-in-requestbody-is-null")
public class DescriptionFieldInRequestBodyIsNullController {

/**
* Person person.
*
* @param person the person
*/
@PostMapping
public void person(
@io.swagger.v3.oas.annotations.parameters.RequestBody(content = @Content(schema = @Schema(implementation = Person.class))) @RequestBody Person person) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package test.org.springdoc.api.app168;

/**
* The type Person.
*/
public class Person {
/**
* The Id.
*/
private long id;

/**
* Gets id.
*
* @return the id
*/
public long getId() {
return id;
}

/**
* Sets id.
*
* @param id the id
*/
public void setId(long id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
*
* * Copyright 2019-2023 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.app168;

import test.org.springdoc.api.AbstractSpringDocTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* The type Spring doc app 168 test.
*/
public class SpringDocApp168Test extends AbstractSpringDocTest {

/**
* The type Spring doc test app.
*/
@SpringBootApplication
static class SpringDocTestApp {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localhost",
"description": "Generated server url"
}
],
"tags": [
{
"name": "description-field-in-request-body-is-null-controller",
"description": "If the RequestBody description field is null, get the description from the javadoc."
}
],
"paths": {
"/description-in-requestbody-is-null": {
"post": {
"tags": [
"description-field-in-request-body-is-null-controller"
],
"operationId": "person",
"summary": "Person person.",
"description": "Person person.",
"operationId": "person",
"requestBody": {
"description": "the person",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Person"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
}
}
}
},
"components": {
"schemas": {
"Person": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"description": "The Id.",
"format": "int64"
}
},
"description": "The type Person."
}
}
}
}