joffrey-bion / livedoc

A not-so-annotation-based documentation generator for REST and websocket services
MIT License
5 stars 2 forks source link

Add ReadOnly annotation #52

Open ST-DDT opened 7 years ago

ST-DDT commented 7 years ago

In some cases fields are read-only/used in responses and thus they won't be considered during an update. It would be nice to add such an annotation which is later shown in the docs-ui.

Maybe it could be possible to add more variants. @ApiPropertyAccess(ReadOnly/NotUpdateable/ReadWrite)

Example


@ApiPropertyAccess(ReadOnly)
int id;
@ApiPropertyAccess(NotUpdateable)
String title;
@ApiPropertyAccess(ReadWrite)
String comment;
joffrey-bion commented 7 years ago

Hi @ST-DDT, I would just like to make sure I understand the use case.

You're talking about documenting a REST API, and you want to mark some fields of some resources as read-only so that your users don't mention them in POST/PUT requests, is that it?

ST-DDT commented 7 years ago

Yes.

Here an example:

Model

@ApiPropertyAccess(ReadOnly)
@ApiProperty(description="The id of the user")
int id;

@ApiPropertyAccess(NotUpdateable)
@ApiProperty(description="The username used for the login")
@NotBlank
String username;

@ApiPropertyAccess(ReadWrite)
@ApiProperty(description="The displayname for friend lists")
@NotBlank
String displayname;

1. Create User

POST /user/register
{
"id": 1337, // Ignored
"username":"foobar",
"displayname":"Foo Bar"
}

2. Get user

GET /user/42
{
"id": 42,
"username":"foobar",
"displayname":"Foo Bar"
}

3. Update User

PUT /user/42
{
"id": 45, // Ignored
"username":"foobar123", // Ignored
"displayname":"Awesome Foo Bar"
}

4. Get updated user

GET /user/42
{
"id": 42,
"username":"foobar", 
"displayname":"Awesome Foo Bar"
}

user

joffrey-bion commented 7 years ago

Ok perfect, that's what I had understood. Thanks again for the detailed example.