FasterXML / jackson-annotations

Core annotations (annotations that only depend on jackson-core) for Jackson data processor
https://github.com/FasterXML/jackson
Apache License 2.0
1.03k stars 330 forks source link

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

Closed ickeundso closed 7 months ago

ickeundso commented 3 years ago

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;

/**

`

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 commented 7 months ago

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