Skip to content

Commit

Permalink
When using @operation, treat deprecated false as NULL (reduce openapi…
Browse files Browse the repository at this point in the history
….json noise) (#575)

The prior change adding reading @operation, introduced an issue in that all non-deprecated methods then explicitly had in openapi.json a deprecated = false attribute.

This "fixes" that issue by only setting deprecated attribute when it is true.
  • Loading branch information
rbygrave authored Mar 10, 2025
1 parent 70d908c commit 3ed55e5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,12 @@ private List<OpenAPIResponsePrism> buildApiResponses() {
public void readOperation(Operation operation, Javadoc javadoc) {
OperationPrism.getOptionalOn(element).ifPresent(an -> {
operation.setOperationId(emptyToNull(an.operationId()));
operation.setDeprecated(an.deprecated());
operation.setSummary(emptyToNull(an.summary()));
operation.setDescription(emptyToNull(an.description()));
if (Boolean.TRUE.equals(an.deprecated())) {
// leave deprecated false as NULL to reduce openapi noise
operation.setDeprecated(true);
}
});
if (operation.getDescription() == null) {
operation.setDescription(javadoc.getDescription());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ HelloDto hello(int id, LocalDate date, String otherParam) {
* @return The Hellos that we found.
*/
@Roles(AppRoles.ADMIN)
@Operation(operationId = "findByName")
@Get("/findbyname/{name}")
List<HelloDto> findByName(String name, @QueryParam("my-param") @Default("one") String myParam) {
return new ArrayList<>();
Expand Down
1 change: 1 addition & 0 deletions tests/test-javalin/src/main/resources/public/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
],
"summary" : "Find Hellos by name",
"description" : "",
"operationId" : "findByName",
"parameters" : [
{
"name" : "name",
Expand Down

0 comments on commit 3ed55e5

Please sign in to comment.