From 85c20b85649ae7679caa1fe0bbfe83f0a0a5c694 Mon Sep 17 00:00:00 2001 From: altro3 Date: Mon, 5 Aug 2024 03:06:55 +0700 Subject: [PATCH] Minor improvements by swagger issues --- .../main/java/io/micronaut/openapi/OpenApiUtils.java | 10 +++++++--- .../openapi/visitor/SchemaDefinitionUtils.java | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/openapi-common/src/main/java/io/micronaut/openapi/OpenApiUtils.java b/openapi-common/src/main/java/io/micronaut/openapi/OpenApiUtils.java index 64354b18d3..1a1ceb72b2 100644 --- a/openapi-common/src/main/java/io/micronaut/openapi/OpenApiUtils.java +++ b/openapi-common/src/main/java/io/micronaut/openapi/OpenApiUtils.java @@ -15,6 +15,7 @@ */ package io.micronaut.openapi; +import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -33,12 +34,14 @@ public final class OpenApiUtils { * The JSON mapper. */ public static final ObjectMapper JSON_MAPPER = ObjectMapperFactory.createJson() - .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) + .enable(JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION); /** * The JSON 3.1 mapper. */ public static final ObjectMapper JSON_MAPPER_31 = ObjectMapperFactory.createJson31() - .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) + .enable(JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION); /** * The JSON mapper for security scheme. */ @@ -46,7 +49,8 @@ public final class OpenApiUtils { .enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING) .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS, SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) - .enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING, DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + .enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING, DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) + .enable(JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION); /** * The YAML mapper. */ diff --git a/openapi/src/main/java/io/micronaut/openapi/visitor/SchemaDefinitionUtils.java b/openapi/src/main/java/io/micronaut/openapi/visitor/SchemaDefinitionUtils.java index e83d718c11..38a1387076 100644 --- a/openapi/src/main/java/io/micronaut/openapi/visitor/SchemaDefinitionUtils.java +++ b/openapi/src/main/java/io/micronaut/openapi/visitor/SchemaDefinitionUtils.java @@ -16,6 +16,7 @@ package io.micronaut.openapi.visitor; import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonUnwrapped; @@ -1490,6 +1491,7 @@ private static void populateSchemaProperties(OpenAPI openAPI, VisitorContext con PropertyElementQuery.of(classElement) .excludedAnnotations(Set.of( Hidden.class.getName(), + JsonBackReference.class.getName(), JsonIgnore.class.getName() )) ).stream() @@ -2365,6 +2367,7 @@ private static boolean isHiddenElement(TypedElement elementType) { var jsonAnySetterAnn = getAnnotation(elementType, JsonAnySetter.class); return elementType.getType().isAssignable(Class.class) || isAnnotationPresent(elementType, JsonIgnore.class) + || isAnnotationPresent(elementType, JsonBackReference.class) || isAnnotationPresent(elementType, Hidden.class) || (jsonAnySetterAnn != null && jsonAnySetterAnn.booleanValue("enabled").orElse(true)) || isHidden;