Skip to content

Commit

Permalink
Merge pull request #1672 from altro3/improvements-by-swagger
Browse files Browse the repository at this point in the history
Minor improvements by swagger issues
  • Loading branch information
altro3 authored Aug 5, 2024
2 parents 2eeb3f2 + 85c20b8 commit 5355de6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,20 +34,23 @@ 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.
*/
public static final ObjectMapper CONVERT_JSON_MAPPER = ObjectMapperFactory.buildStrictGenericObjectMapper()
.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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5355de6

Please sign in to comment.