Skip to content

When defining a Regex pattern in the @Schema annotation its never rendered in the generated JSON Schema #543

Description

@johnboyer

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions