Class SchemaUtils

java.lang.Object
org.springdoc.core.utils.SchemaUtils

public class SchemaUtils extends Object
The type Validation utils.
Author:
dyun
  • Field Details

    • JAVA_FIELD_NULLABLE_DEFAULT

      public static final Boolean JAVA_FIELD_NULLABLE_DEFAULT
      The constant JAVA_FIELD_NULLABLE_DEFAULT.
    • ANNOTATIONS_FOR_REQUIRED

      public static final List<String> ANNOTATIONS_FOR_REQUIRED
      The constant ANNOTATIONS_FOR_REQUIRED.
    • ANNOTATIONS_FOR_NULLABLE

      public static final List<String> ANNOTATIONS_FOR_NULLABLE
      The constant ANNOTATIONS_FOR_NULLABLE.
  • Constructor Details

    • SchemaUtils

      public SchemaUtils(Optional<SpringDocKotlinUtils> kotlinUtilsOptional)
      The constructor.
      Parameters:
      kotlinUtilsOptional - the kotlin utils optional
  • Method Details

    • swaggerVisible

      public static boolean swaggerVisible(@Nullable io.swagger.v3.oas.annotations.media.Schema schema, @Nullable io.swagger.v3.oas.annotations.Parameter parameter)
      Is swagger visible.
      Parameters:
      schema - the schema
      parameter - the parameter
      Returns:
      the boolean
    • swaggerRequired

      @Nullable public static Boolean swaggerRequired(@Nullable io.swagger.v3.oas.annotations.media.Schema schema, @Nullable io.swagger.v3.oas.annotations.Parameter parameter)
      Is swagger required. it may return null if not specified require value or mode
      Parameters:
      schema - the schema
      parameter - the parameter
      Returns:
      the boolean or null
      See Also:
      • Parameter#required()
      • io.swagger.v3.oas.annotations.media.Schema#required()
      • io.swagger.v3.oas.annotations.media.Schema#requiredMode()
    • annotatedNotNull

      public static boolean annotatedNotNull(List<Annotation> annotations)
      Is annotated notnull.
      Parameters:
      annotations - the field annotations
      Returns:
      the boolean
    • fieldNullable

      public boolean fieldNullable(Field field)
      Is field nullable. java default is nullable JAVA_FIELD_NULLABLE_DEFAULT
      Parameters:
      field - the field
      Returns:
      the boolean
    • fieldRequired

      public boolean fieldRequired(Field field, io.swagger.v3.oas.annotations.media.Schema schema, io.swagger.v3.oas.annotations.Parameter parameter)
      Is field required.
      Parameters:
      field - the field
      schema - the schema
      parameter - the parameter
      Returns:
      the boolean
      See Also:
      • Parameter#required()
      • io.swagger.v3.oas.annotations.media.Schema#required()
      • io.swagger.v3.oas.annotations.media.Schema#requiredMode()
    • applyValidationsToSchema

      public static void applyValidationsToSchema(io.swagger.v3.oas.models.media.Schema<?> schema, List<Annotation> annotations, String openapiVersion)
      Apply validations to schema. the annotation order effects the result of the validation.
      Parameters:
      schema - the schema
      annotations - the annotations
      openapiVersion - the openapi version
    • hasValidationConstraints

      public static boolean hasValidationConstraints(List<Annotation> annotations)
      Whether the given annotations contain a bean-validation constraint that applyValidationsToSchema(Schema, List, String) would apply to a schema.
      Parameters:
      annotations - the annotations
      Returns:
      true if at least one validation constraint is present
    • fixOAS31ExclusiveConstraints

      public static void fixOAS31ExclusiveConstraints(io.swagger.v3.oas.models.media.Schema<?> schema)
      Swagger-core 2.2.49 introduced so that Positive and Negative are introspected. It does not correctly use the fact that exclusiveMinimum/exclusiveMaximum are values in OAS31.

      Tracked under swagger-core#5170.

      Parameters:
      schema - the schema to fix