Just wondering if there is a way I can use my custom annotation in openapi specification.
Scenario-
User Object- I need to have notnull validation between username or email. either one of these should be provided in request

For this I can create a custom annotation in code something like @ValidateUserNameAndEmail, but not finding a way to apply this in openapi spec and include it like other annotation in generated code.
I use the latest version (6.2.1) of openapi-generator-maven-plugin and following works for me.
User:
type: object
x-class-extra-annotation: "@org.example.ValidateUsernameAndEmail"
...
The plugin generates following class:
@Schema(name = "User ")
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2022-11-24T14:51:09.277810200+01:00[Europe/Prague]")
@org.example.ValidateUsernameAndEmail
public class User {
...
}
You can also define a field-level annotation using x-field-extra-annotation if needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With