Skip to content
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

@Schema's description property is not successfully mapped to springdoc #1574

Closed
linghengqian opened this issue Mar 24, 2022 · 1 comment
Closed

Comments

@linghengqian
Copy link

linghengqian commented Mar 24, 2022

Describe the bug

  • If you are reporting a bug, please help to speed up problem diagnosis by providing as much information as possible:
  • A clear and concise description of what the bug is: the title of an issue is not enough

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?

2.6.4

  • What modules and versions of springdoc-openapi are you using?

org.springdoc:springdoc-openapi-ui:1.6.6

  • What is the actual and the expected result using OpenAPI Description (yml or json)?

What I want is the following display.

{
	"openapi": "3.0.1",
	"info": {
		"title": "OpenAPI definition",
		"version": "v0"
	},
	"servers": [{
		"url": "http://localhost:8080",
		"description": "Generated server url"
	}],
	"paths": {
		"/test": {
			"patch": {
				"tags": ["test-controller"],
				"operationId": "test",
				"requestBody": {
					"content": {
						"application/json": {
							"schema": {
								"$ref": "#/components/schemas/TestBO"
							}
						}
					},
					"required": true
				},
				"responses": {
					"200": {
						"description": "OK",
						"content": {
							"*/*": {
								"schema": {
									"type": "string"
								}
							}
						}
					}
				}
			}
		}
	},
	"components": {
		"schemas": {
			"TestBO": {
				"type": "object",
				"properties": {
					"id": {
						"type": "integer",
						"description": "the id",
						"format": "int32"
					},
					"testFiled": {
						"type": "integer",
						"description": "test filed with something",
						"format": "int32"
					},
					"pcount": {
						"type": "integer",
                                                "description": "something with p",
						"format": "int32"
					},
					"ccount": {
						"type": "integer",
                                                "description": "something with c",
						"format": "int32"
					}
				},
				"description": "TestBO"
			}
		}
	}
}

Actually, the descriptions of pcount and ccount are not in the OpenAPI Doc, I have provided an example project below to demonstrate the problem.

{
	"openapi": "3.0.1",
	"info": {
		"title": "OpenAPI definition",
		"version": "v0"
	},
	"servers": [{
		"url": "http://localhost:8080",
		"description": "Generated server url"
	}],
	"paths": {
		"/test": {
			"patch": {
				"tags": ["test-controller"],
				"operationId": "test",
				"requestBody": {
					"content": {
						"application/json": {
							"schema": {
								"$ref": "#/components/schemas/TestBO"
							}
						}
					},
					"required": true
				},
				"responses": {
					"200": {
						"description": "OK",
						"content": {
							"*/*": {
								"schema": {
									"type": "string"
								}
							}
						}
					}
				}
			}
		}
	},
	"components": {
		"schemas": {
			"TestBO": {
				"type": "object",
				"properties": {
					"id": {
						"type": "integer",
						"description": "the id",
						"format": "int32"
					},
					"testFiled": {
						"type": "integer",
						"description": "test filed with something",
						"format": "int32"
					},
					"pcount": {
						"type": "integer",
						"format": "int32"
					},
					"ccount": {
						"type": "integer",
						"format": "int32"
					}
				},
				"description": "TestBO"
			}
		}
	}
}
  • Provide with a sample code (HelloController) or Test that reproduces the problem

An example git repository is at https://github.com/linghengqian/springdoc-schema-test .

Screenshots
If applicable, add screenshots to help explain your problem.

  • image
  • image

Additional context
Add any other context about the problem here.

No.

@bnasslahsen
Copy link
Contributor

@linghengqian,

This is related to this lombok issue: projectlombok/lombok#2693
If you use, standard java getter/setter it will just work out of the box.

import java.io.Serializable;

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

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class SpringdocSchemaTestApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringdocSchemaTestApplication.class, args);
    }

}

@RestController
class testController {
    @PatchMapping("/test")
    public String test(@RequestBody TestBO testBO) {
        return "test" + testBO.getpCount() + testBO.getcCount();
    }
}


@Schema(description = "TestBO")
class TestBO implements Serializable {
    private static final long serialVersionUID = 1L;
    @Schema(description = "the id")
    private Integer id;
    @Schema(description = "something with c")
    private Integer cCount;
    @Schema(description = "something with p")
    private Integer pCount;
    @Schema(description = "test filed with something")
    private Integer testFiled;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getcCount() {
		return cCount;
	}

	public void setcCount(Integer cCount) {
		this.cCount = cCount;
	}

	public Integer getpCount() {
		return pCount;
	}

	public void setpCount(Integer pCount) {
		this.pCount = pCount;
	}

	public Integer getTestFiled() {
		return testFiled;
	}

	public void setTestFiled(Integer testFiled) {
		this.testFiled = testFiled;
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants