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

Generate JSON Schema based on JSR-303 bean validation annotations [DATAREST-735]

Open
#1,106 5 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

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

Description

Augusto David Altman Quaranta opened DATAREST-735 and commented

It would be great if the JSON Schema generated when hitting the profile api (alps) is generated taking in consideration the bean validation annotations on the entities.

For example, given the following entity

@Entity
@Table(name = "clients")
public class Client {
    @Max(100)
    @Min(0)
    @NotNull
    private int percentaje;

    @NotEmpty
    private String fantasyName;

    Client() { // jpa only
    }

    public int getPercentaje() {
        return percentaje;
    }
    
    public void setPercentaje(int percentaje) {
        this.percentaje = percentaje;
    }

    public String getFantasyName() {
        return fantasyName;
    }
    
    public void setFantasyName(String fantasyName) {
        this.fantasyName = fantasyName;
    }
}

I would like to get the following JSON Schema

{
	"title": "Clients",
	"type": "object",
	"properties": {
		"fantasyName": {
			"type": "string"
		},
		"percentaje": {
			"description": "Age in years",
			"type": "integer",
			"minimum": 0,
                        "maximum": 100,
		}
	},
	"required": ["fantasyName", "percentaje"]
}

Affects: 2.4.1 (Gosling SR1)

Issue Links:

  • DATAREST-736 Generate JSON Schema based on JSR-303 bean validation annotations
    ("is duplicated by")

3 votes, 7 watchers

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.