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

Wrong schema generated #158

Open
peterpivarnik opened this issue May 30, 2023 · 0 comments
Open

Wrong schema generated #158

peterpivarnik opened this issue May 30, 2023 · 0 comments

Comments

@peterpivarnik
Copy link

Hello, I want to generate schema for carDto, which contains as attributes also four tireDto's. Here is exmaple of such dto's:

@Getter
@Setter
public class CarDto
{
  private String licencePlate;
  private String vin;
  private String brand;
  private String model;
  private TireDto tireFrontLeft;
  private TireDto tireFrontRight;
  private TireDto tireBackLeft;
  private TireDto tireBackRight;
}
@Getter
@Setter
public class TireDto
{
  private String tireBrand;
  private String tireModel;
  private String dimension;
  private String season;
}

Here is the test how I want to generate schema:

  @Test
  void shouldGenerateValidSchema() throws IOException {
    SimpleModule module = new SimpleModule();
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(module);

    ObjectSchema dtoSchema = (ObjectSchema) new JsonSchemaGenerator(objectMapper).generateSchema(CarDto.class);

    System.out.println(dtoSchema.getProperties());
  }

I would expect that all attributes of class TireDto (tireFrontLeft, tireFrontRight, tireBackLeft and tireBackRight) will be instances of the same schema. But it is not like that. First attribute tireFrontLeft is instance of ObjectSchema and all others (tireFrontRight, tireBackLeft and tireBackRight) are instances of ReferenceSchema. Besides that, only tireFrontLeft contains also properties of TireDto.

Here I'm also attaching screenshot from debugging.
image

So is it a bug, or I'm missing some configuration?

@peterpivarnik peterpivarnik changed the title Wrongschema generated Wrong schema generated May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant