Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ickeundso opened this issue Aug 27, 2021 · 1 comment

Comments

@ickeundso
Copy link

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 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;
}

/**

`

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" }

@cowtowncoder
Copy link
Member

No plans to add general-purpose annotations related to schema generation; closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants