spring-projects / spring-projects/spring-data-rest

Neither @JsonPropertyDescription nor @Description are respected when constructing JsonSchema [DATAREST-824]

Open
#1,129 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Petar Tahchiev opened DATAREST-824 and commented

Hello,

I put these annotations on my entity:

@Description("SDR Description")
@JsonPropertyDescription(value = "The content unit of this product.")
@JsonProperty(access = JsonProperty.Access.READ_WRITE, required = true)
@ManyToOne(fetch = FetchType.LAZY, targetEntity = UnitEntityDefinition.class)
@JoinColumn(name = UnitEntityDefinition.NAME + "_pk", nullable = true, referencedColumnName = "pk")
UnitEntityDefinition getContentUnit();

and I try to get the json+schema for this entity, and I get the following:

"contentUnit" : {
  "title" : "Content Unit",
  "readOnly" : false,
  "type" : "string",
  "format" : "uri"
},

I noticed that this happens because spring-data-rest looks only in a message source file called rest-messages.properties. I checked PersistentEntityToJsonSchemaConverter:getSchemaProperty:

	private JsonSchemaProperty getSchemaProperty(BeanPropertyDefinition definition, TypeInformation<?> type,
			ResourceDescription description) {

		String name = definition.getName();
		String title = resolveMessageWithDefault(new ResolvableProperty(definition));
		String resolvedDescription = resolveMessage(description);

and the description that is passed here is:

result = {AnnotationBasedResourceDescription@21424} 
 message = "SDR Description"
 fallback = {TypedResourceDescription@21430} 
  type = {Class@15588} "interface com.nemesis.platform.module.commerce.core.definition.catalog.UnitEntityDefinition"
  message = "rest.description.product.contentUnit"
  mediaType = {MediaType@21363} "text/plain"

but what the resolve message method does is simply lookup in the message source:

	private String resolveMessage(MessageSourceResolvable resolvable) {

		if (resolvable == null) {
			return null;
		}

		try {
			return accessor.getMessage(resolvable);
		} catch (NoSuchMessageException o_O) {

			if (configuration.getMetadataConfiguration().omitUnresolvableDescriptionKeys()) {
				return null;
			} else {
				throw o_O;
			}
		}
	}

Affects: 2.4.4 (Gosling SR4)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.