Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'@JsonClassDescription' annotation is not taken into account #136

Open
gtbromen opened this issue Jun 14, 2019 · 8 comments
Open

'@JsonClassDescription' annotation is not taken into account #136

gtbromen opened this issue Jun 14, 2019 · 8 comments
Labels
pr-needed Feature request for which PR likely needed (no active development but idea appears workable)

Comments

@gtbromen
Copy link

@JsonClassDescription supported by jackson-module-jsonSchema? I have tried to generate JSON schema with jackson-module-jsonSchema 2.7.4 However, it ignores @JsonClassDescription annotation

@cowtowncoder
Copy link
Member

Version 2.7.4 is very old so I would recommend upgrade to a later version, ideally 2.9(.9).
If description is still not included, please file an issue (or change this one) to include reproduction of what you think should happen, ideally in form of failing unit test.

@gtbromen
Copy link
Author

gtbromen commented Jun 17, 2019

I try with 2.9.9 version and i have the same issue (JsonPropertyDescription annotation is ok but not JsonClassDescription annotation)

Here is the example

package test;
import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper;

@JsonClassDescription("Description of calss Test")
public class Test {
	
	@JsonPropertyDescription("Description of property name")
	private String name;

	public Test() {
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public static void main(String[] args) throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();
		SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
		mapper.acceptJsonFormatVisitor(Test.class, visitor);
		com.fasterxml.jackson.module.jsonSchema.JsonSchema jsonSchema = visitor.finalSchema();
		System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema));
	}
}

output

{
  "type" : "object",
  "id" : "urn:jsonschema:test:Test",
  "properties" : {
    "name" : {
      "type" : "string",
      "description" : "Description of property name"
    }
  }
}

@cowtowncoder
Copy link
Member

Sounds like support for class description is missing then (I remember addition of property descriptions).

Contributions welcome!

@cowtowncoder cowtowncoder changed the title @JsonClassDescription annotation is not taken into account '@JsonClassDescription' annotation is not taken into account Aug 10, 2019
@cowtowncoder
Copy link
Member

I checked that code indeed does not fetch this information. It would be available from jackson-databind side using BeanDescription.findClassDescription(), but wiring does not exist.
This is different from description for properties which get access via JsonSchema.enrichWithBeanProperty() (using beanProperty.getMetadata().getDescription()).

So: someone would need to connect the dots. I do not work on this module, but maybe someone else has time and interest.

@bmogensen
Copy link

I decided to use the Swagger annotations instead with:

@ApiModel(
		value = "Party",
		description = "An organization or person")
public class Party {
...
}

Create the Swagger module and add it to config builder:

SwaggerModule swaggerModule = new SwaggerModule();
...
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(objectMapper,SchemaVersion.DRAFT_2019_09,OptionPreset.PLAIN_JSON).with(jacksonModule).with(swaggerModule)

@Praytic
Copy link

Praytic commented Jul 12, 2022

I think, as a part of this effort, @JsonPropertyDescription annotation can also be taken into the account.

@mdedetrich
Copy link

I think, as a part of this effort, @JsonPropertyDescription annotation can also be taken into the account.

@JsonPropertyDescription's annotation only works on fields and I think it makes sense to keep it this way. Its probably best to update @JsonClassDescription so that it does actually work as intuitively intended.

@cowtowncoder cowtowncoder added the pr-needed Feature request for which PR likely needed (no active development but idea appears workable) label Nov 9, 2023
@cowtowncoder
Copy link
Member

Added pr-needed since I won't have any time to work on this. But it seems like a valid idea (within constraints that this module is itself unsupported ... but is released for Jackson 2.x, PRs accepted etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-needed Feature request for which PR likely needed (no active development but idea appears workable)
Projects
None yet
Development

No branches or pull requests

5 participants