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

Make UriToEntityConverter usable for just <id> not only ..../<resource>/<id>

Open
#2,131 1 comment 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Apr 11, 2022.

status: waiting-for-triage
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

I'm wondering what is this safe-check for in UriToEntityConverter.java How about removing it?

if (parts.length < 2) {
			throw new ConversionFailedException(sourceType, targetType, source, new IllegalArgumentException(
					"Cannot resolve URI " + uri + ". Is it local or remote? Only local URIs are resolvable."));
		}

IMHO it's unnecessary. UriToEntityConverter just uses the last part of the URI and deduces type from targetType not uri path. So we could say that by design it assumes URI is relative to targetType's resource, however it forbids short URI imposing full resource path. In result:

http://localhost:8080/entity/1 is proper URI (although only "1" is actually taken from this)
/entity/1 is also a proper URI
1 is not resolvable URI anymore

Why? Such short relative URIs containing just ID are actually very useful and used by many frameworks.

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.