You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Updating schema examples using in the custom AsyncApiCustomizer does not change examples of surrounding schemas #1262
But I have other schema's, e.g. Ipv4AddressConfiguration, that have Ipv4Address as a property. In the generated Springwolf UI, I can see that the example of Ipv4Address is changed but not the example of Ipv4AddressConfiguration.
How can I make sure that the example of the Ipv4AddressConfiguration is regenerated AFTER updating the "leaf" schema examples? Is there a way to regenerate ALL examples from the AsyncApiCustomizer?
Hi @limburgie,
thanks for reaching out. AsyncApiCustomizer is the last extension point to intercept generated document before serialization (see springwolf docs). There are no Springwolf processes working on the specification afterwards. It is therefore considered a low-level api where it its the implementors responsibility to take care of creating a consistent specification. Therefore I would not consider it a bug at the moment.
However, the general approach for customizing examples is using the @Schema annotation. Would this approach work for you? If not, what is your use case that prevents you from using it? I'd hope we find a better solution than going through AsyncApiCustomizer...
I agree that using @Schema would be the best option, however I don't have access to the core domain (which is also used as DTO's for my API)... So that's why I was looking for a way to edit the examples in another way.
To give you some more information as to why this is needed. I have implemented custom JsonSerializers and JsonDeserializers for some of my domain objects. The reason I am using these (de)serializers is because, again, I have no access to the domain so I cannot use @JsonValue and @JsonCreator on the domain classes. But this also causes Springwolf to have no clue that these domain classes are serialized/deserialized in a custom way.
I am using a custom ObjectMapper to register these custom (de)serializers in my application code. I noticed that Springwolf has its own ObjectMapper that it uses for e.g. generating examples. So another way might be if I could inject my custom ObjectMapper (or at least my custom (de)serializers) in Springwolf so they are taken into account?
I would love to hear your take on this!
Thanks for your help.
If you want to change how examples are treated, then you should have a look at the ExampleValueGenerators (ie ExampleJsonValueGenerator). They also use their own ObjectMapper instance. Internally Springwolf is not just deserializing objects to create examples, but reconstructing them from the schema provided by swagger core. Therefore I'm not sure if changing the ObjectMapper would really help.
There are multiple possibilities to change the schema or examples along the way:
ExampleValueGenerator.create*Example() -> Change example based on the Schema and Type
ExampleValueGenerator.prepareForSerialization() -> Change full Example as JsonNode based on Schema
Use a custom io.swagger.v3.core.converter.ModelConverter like MonetaryAmountConverter where could for example replace domain classes with your own classes.
Your use case is not clear enough for me to point you in a more specific direction, can you provide more information?
Activity
github-actions commentedon Apr 4, 2025
Welcome to Springwolf. Thanks a lot for reporting your first issue. Please check out our contributors guide and feel free to join us on discord.
sam0r040 commentedon Apr 4, 2025
Hi @limburgie,
thanks for reaching out. AsyncApiCustomizer is the last extension point to intercept generated document before serialization (see springwolf docs). There are no Springwolf processes working on the specification afterwards. It is therefore considered a low-level api where it its the implementors responsibility to take care of creating a consistent specification. Therefore I would not consider it a bug at the moment.
However, the general approach for customizing examples is using the
@Schemaannotation. Would this approach work for you? If not, what is your use case that prevents you from using it? I'd hope we find a better solution than going through AsyncApiCustomizer...Rhamid10 commentedon Apr 9, 2025
I have a similar need, I was able to update all my examples by simply iterating over all schemas.
limburgie commentedon Apr 10, 2025
Hi @sam0r040,
I agree that using
@Schemawould be the best option, however I don't have access to the core domain (which is also used as DTO's for my API)... So that's why I was looking for a way to edit the examples in another way.To give you some more information as to why this is needed. I have implemented custom
JsonSerializers andJsonDeserializers for some of my domain objects. The reason I am using these (de)serializers is because, again, I have no access to the domain so I cannot use@JsonValueand@JsonCreatoron the domain classes. But this also causes Springwolf to have no clue that these domain classes are serialized/deserialized in a custom way.I am using a custom ObjectMapper to register these custom (de)serializers in my application code. I noticed that Springwolf has its own ObjectMapper that it uses for e.g. generating examples. So another way might be if I could inject my custom ObjectMapper (or at least my custom (de)serializers) in Springwolf so they are taken into account?
I would love to hear your take on this!
Thanks for your help.
sam0r040 commentedon Apr 11, 2025
If you want to change how examples are treated, then you should have a look at the ExampleValueGenerators (ie ExampleJsonValueGenerator). They also use their own ObjectMapper instance. Internally Springwolf is not just deserializing objects to create examples, but reconstructing them from the schema provided by swagger core. Therefore I'm not sure if changing the ObjectMapper would really help.
There are multiple possibilities to change the schema or examples along the way:
Your use case is not clear enough for me to point you in a more specific direction, can you provide more information?
samr874 commentedon May 11, 2025
@limburgie Are the contributions still active for this project ??