Skip to content

Commit 3ed55e5

Browse files
authored
When using @operation, treat deprecated false as NULL (reduce openapi.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.
1 parent 70d908c commit 3ed55e5

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

http-generator-core/src/main/java/io/avaje/http/generator/core/MethodReader.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,12 @@ private List<OpenAPIResponsePrism> buildApiResponses() {
273273
public void readOperation(Operation operation, Javadoc javadoc) {
274274
OperationPrism.getOptionalOn(element).ifPresent(an -> {
275275
operation.setOperationId(emptyToNull(an.operationId()));
276-
operation.setDeprecated(an.deprecated());
277276
operation.setSummary(emptyToNull(an.summary()));
278277
operation.setDescription(emptyToNull(an.description()));
278+
if (Boolean.TRUE.equals(an.deprecated())) {
279+
// leave deprecated false as NULL to reduce openapi noise
280+
operation.setDeprecated(true);
281+
}
279282
});
280283
if (operation.getDescription() == null) {
281284
operation.setDescription(javadoc.getDescription());

tests/test-javalin/src/main/java/org/example/myapp/web/HelloController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ HelloDto hello(int id, LocalDate date, String otherParam) {
7676
* @return The Hellos that we found.
7777
*/
7878
@Roles(AppRoles.ADMIN)
79+
@Operation(operationId = "findByName")
7980
@Get("/findbyname/{name}")
8081
List<HelloDto> findByName(String name, @QueryParam("my-param") @Default("one") String myParam) {
8182
return new ArrayList<>();

tests/test-javalin/src/main/resources/public/openapi.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@
351351
],
352352
"summary" : "Find Hellos by name",
353353
"description" : "",
354+
"operationId" : "findByName",
354355
"parameters" : [
355356
{
356357
"name" : "name",

0 commit comments

Comments
 (0)