Is there a reason why the Swagger2Module() ignores the pattern, type, and maxLength elements in @Schema? Is there something wrong with the configuration? The @Schema annotation can be applied to a class.
Configuration
static def schemaGeneratorConfigBuilder(annotationType, preset = OptionPreset.PLAIN_JSON) {
return new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2020_12, preset)
.with(moduleForAnnotationType(annotationType))
.with(new Swagger2Module())
.with(
Option.ADDITIONAL_FIXED_TYPES,
Option.EXTRA_OPEN_API_FORMAT_VALUES,
Option.FLATTENED_ENUMS_FROM_TOSTRING,
Option.FLATTENED_OPTIONALS,
Option.PLAIN_DEFINITION_KEYS,
Option.ALLOF_CLEANUP_AT_THE_END,
Option.FORBIDDEN_ADDITIONAL_PROPERTIES_BY_DEFAULT,
Option.DEFINITIONS_FOR_ALL_OBJECTS
)
}
Source Annotation
@Schema(
type = "string",
description = "A sequence of Unicode characters. Note that FHIR strings SHALL NOT exceed 1MB in size",
pattern = "^[ \\r\\n\\t\\S]+$",
maxLength = 1048576,
example = "Example string value"
)
public class FhirString extends PrimitiveElement<String, FhirString> {
//...
}
Output
{
"$schema" : "https://json-schema.org/draft/2020-12/schema",
"type" : "object",
"properties" : {
"id" : {
"$ref" : "#",
"description" : "Unique id for an element within a resource (for internal references, path PATCH, etc.)."
}
},
"additionalProperties" : false
}
Is there a reason why the
Swagger2Module()ignores thepattern,type, andmaxLengthelements in@Schema? Is there something wrong with the configuration? The@Schemaannotation can be applied to a class.Configuration
Source Annotation
Output
{ "$schema" : "https://json-schema.org/draft/2020-12/schema", "type" : "object", "properties" : { "id" : { "$ref" : "#", "description" : "Unique id for an element within a resource (for internal references, path PATCH, etc.)." } }, "additionalProperties" : false }