Skip to content

Commit

Permalink
Merge branch 'fix_npe_request_body_service' of https://github.com/uc4…
Browse files Browse the repository at this point in the history
…w6c/springdoc-openapi into uc4w6c-fix_npe_request_body_service
  • Loading branch information
bnasslahsen committed Mar 9, 2023
2 parents 82d46fd + 71454f0 commit ee0aee2
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ else if (!methodAttributes.isWithResponseBodySchemaDoc()) {
&& 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 {
}
}
63 changes: 63 additions & 0 deletions springdoc-openapi-javadoc/src/test/resources/results/app168.json
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."
}
}
}
}

0 comments on commit ee0aee2

Please sign in to comment.