jackson-annotations icon indicating copy to clipboard operation
jackson-annotations copied to clipboard

FEATURE : add annotation support to generate dependencies / dependentRequired into a schema file

Open ickeundso opened this issue 3 years ago • 0 comments

Hi, I love the JsonSchemaGenerator were I can use your JSON* annotations and javax.validation.constraints without problems. One feature I miss is the possibility to generate a dependencies (until draft-07) / dependentRequired (since 2019_09) definition.

I would expect something like that @JsonDependsOn ` package cms.container.module;

import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import crisp.explore.schema.SchemaVersion;

import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.util.List;

@TranslationType @SchemaVersion(major = 2, minor = 0, fix = 0) public class QuotationAuthor {

public static final String CONTENTTYPE_ID = "quotationAuthor";

private static final String DISPLAY_NAME_FIELD = "displayName"; private static final String POSITION_FIELD = "position"; private static final String COMPANY_FIELD = "company"; private static final String AVATAR_URI_FIELD = "avatarUri"; private static final String IMAGE_CAPTION_FIELD = "imageCaption"; private static final String IMAGE_ALTERNATE_TEXT_FIELD = "imageAlternateText"; private static final String IMAGE_TITLE_FIELD = "imageTitle";

private String displayName; private String position; private String company; private String avatarUri; private String imageCaption; private String imageAlternateText; private String imageTitle;

/**

  • Constructor. */ @JsonCreator public QuotationAuthor(@JsonProperty(BaseContent.CMS_ID_FIELD) final String cmsId, @JsonProperty(BaseContent.GC_ID_FIELD) final String gcId, @JsonProperty(BaseContent.GC_TYPE_FIELD) final GcType gcType, @JsonProperty(BaseContent.REALM_FIELD) final List<String> realms, @JsonProperty(BaseContent.LOCALE_FIELD) final String locale, @JsonProperty(QuotationAuthor.DISPLAY_NAME_FIELD) final String displayName, @JsonProperty(QuotationAuthor.POSITION_FIELD) final String position, @JsonProperty(QuotationAuthor.COMPANY_FIELD) final String company, @JsonProperty(QuotationAuthor.AVATAR_URI_FIELD) final String avatarUri, @JsonProperty(QuotationAuthor.IMAGE_CAPTION_FIELD) final String imageCaption, @JsonProperty(QuotationAuthor.IMAGE_ALTERNATE_TEXT_FIELD) final String imageAlternateText, @JsonProperty(QuotationAuthor.IMAGE_TITLE_FIELD) final String imageTitle) { super(cmsId, gcId, gcType, realms, locale); this.displayName = displayName; this.position = position; this.company = company; this.avatarUri = avatarUri; this.imageCaption = imageCaption; this.imageAlternateText = imageAlternateText; this.imageTitle = imageTitle; }

@NotNull @NotEmpty @NotBlank public String getDisplayName() { return this.displayName; }

public void setDisplayName(final String displayName) { this.displayName = displayName; }

public String getPosition() { return this.position; }

public void setPosition(final String position) { this.position = position; }

public String getCompany() { return this.company; }

public void setCompany(final String company) { this.company = company; }

@NotNull @NotEmpty @NotBlank @JsonDependsOn("imageCaption","imageTitle","imageAlternateText") public String getAvatarUri() { return this.avatarUri; }

public void setAvatarUri(final String avatarUri) { this.avatarUri = avatarUri; } @NotNull @NotEmpty @NotBlank @JsonDependsOn("avatarUri","imageTitle","imageAlternateText") public String getImageCaption() { return this.imageCaption; }

public void setImageCaption(final String imageCaption) { this.imageCaption = imageCaption; }

@NotNull @NotEmpty @NotBlank @JsonDependsOn("imageCaption","imageTitle","avatarUri") public String getImageAlternateText() { return this.imageAlternateText; }

public void setImageAlternateText(final String imageAlternateText) { this.imageAlternateText = imageAlternateText; }

@NotNull @NotEmpty @NotBlank @JsonDependsOn("imageCaption","avatarUri","imageAlternateText") public String getImageTitle() { return this.imageTitle; }

public void setImageTitle(final String imageTitle) { this.imageTitle = imageTitle; }

/**

  • The identify equal to the content type name in contentful. */ @Override @JsonProperty @NotNull @NotEmpty @NotBlank public String contentTypeId() { return QuotationAuthor.CONTENTTYPE_ID; }

`

Here the expected schema file { "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "title": "QuotationAuthor", "type": "object", "properties": { "avatarUri": {"anyOf": [ { "type": "null", "title": "Not included" }, {"type": "string"} ]}, "realms": { "minItems": 1, "type": "array", "items": {"type": "string"} }, "cmsId": { "minLength": 1, "pattern": "^.*\\S+.*$", "type": "string" }, "displayName": { "minLength": 1, "pattern": "^.*\\S+.*$", "type": "string" }, "gcId": { "minLength": 1, "pattern": "^.*\\S+.*$", "type": "string" }, "gcType": { "type": "string", "enum": [ "Master Content", "Localized Content", "Undefined" ] }, "syncDate": {"anyOf": [ { "type": "null", "title": "Not included" }, { "format": "date-time", "type": "string" } ]}, "contentTypeId": { "minLength": 1, "pattern": "^.*\\S+.*$", "type": "string" }, "imageAlternateText": { "minLength": 1, "pattern": "^.*\\S+.*$", "type": "string" }, "locale": { "minLength": 1, "pattern": "^.*\\S+.*$", "type": "string" }, "environment": {"anyOf": [ { "type": "null", "title": "Not included" }, {"type": "string"} ]}, "imageCaption":{ "minLength": 1, "pattern": "^.*\\S+.*$", "type": "string" }, "provider": { "default": "QuotationAuthor", "type": "string", "enum": ["QuotationAuthor"] }, "company": {"anyOf": [ { "type": "null", "title": "Not included" }, {"type": "string"} ]}, "position": {"anyOf": [ { "type": "null", "title": "Not included" }, {"type": "string"} ]}, "imageTitle": { "minLength": 1, "pattern": "^.*\\S+.*$", "type": "string" } }, "required": [ "provider", "cmsId", "gcType", "realms", "locale", "displayName", "gcId", "contentTypeId" ], "dependencies": { "avatarUri": ["imageCaption","imageTitle","imageAlternateText"], "imageCaption": ["avatarUri","imageTitle","imageAlternateText"], "imageTitle": ["imageCaption","avatarUri","imageAlternateText"], "imageAlternateText": ["imageCaption","imageTitle","avatarUri"] }, "$id": "classpath://schema/cms-quotationauthor-schema-2.0.0.json" }

ickeundso avatar Aug 27 '21 07:08 ickeundso