question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PropertyCustomizer not invoked for multiple properties of same type with the same annotations.

See original GitHub issue

A PropertyCustomizer is not invoked for every property where those properties have the same type and annotations.

For example with the following class (HelloController test here):

  public static class ApiType {
      Long a;
      Long b;
      String c;
     // getters...
  }

A PropertyCustomizer is invoked for properties ‘a’ & ‘c’ only; it is not invoked for property b (which shares the result of ‘a’).

This appears to be because the swagger generator is caching properties that share the same type and annotations and this is bypassing the type resolution process that drives the PropertyCustomizer.

Springdoc 1.5.2 Spring boot 2.4.1

Expected behavior PropertyCustomizer is invoked for every property.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bnasslahsencommented, Dec 29, 2020

You still can use OpenApiCustomiser. This is a sample code that you can adapt:

@Bean
public OpenApiCustomiser openApiCustomiser() {
  return openAPI -> openAPI.getComponents().getSchemas().values()
      .forEach(schema -> schema.setRequired(new ArrayList<>(schema.getProperties().keySet())));
}
0reactions
jaco0646commented, Jun 29, 2022

In SpringFox this can be accomplished using ModelPropertyBuilderPlugin, which applies to every Property of a Model, regardless of whether its Type is the same as another Property. Perhaps that offers some inspiration of how it might be implemented in SpringDoc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Multiple annotations of the same type on one element?
Obviously, I want to be able to quickly find instances of Employee by various properties of Project. I can either specify @Index twice...
Read more >
Spring Custom Property Editor | Baeldung
Simply put, Spring uses property editors heavily for managing conversion between String values and custom Object types; this is based on ...
Read more >
6.4 Bean manipulation and the BeanWrapper - Spring
A JavaBean is simply a class with a default no-argument constructor, which follows a naming convention where (by way of an example) a...
Read more >
1.7.1 - jqwik User Guide
Test container classes, groups, example methods and property methods can be tagged using the annotation @Tag("a-tag") . You can have many tags on...
Read more >
Type conversion - OWNER • Java™ properties reinvented.
OWER API supports properties conversion for primitive types and enums. ... annotations: you cannot specify two different ways to do the same thing!...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found