-
Notifications
You must be signed in to change notification settings - Fork 96
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
New feature: schema decorators #885
New feature: schema decorators #885
Conversation
59c5fa7
to
2ab2352
Compare
…ecorators # Conflicts: # openapi/src/main/java/io/micronaut/openapi/visitor/OpenApiApplicationVisitor.java
@graemerocher Hi! Could you merge this PR and release a new 4.9.0 release? I ran into a problem on my project. I have generated API models according to the xsd scheme. There can be up to 10 such schemes, each for its own version of the API. The problem is that micronaut-openapi does not take into account when generating schemas that the classes are in different packages, but the classes are named the same. Because of this, the final swagger file is generated incorrectly. This is one of the methods for solving this problem, suitable for me. In the future, I will add the ability to specify a behavior strategy for classes with the same name, i.e. so that, for example, an index is automatically added to the end of the model name, as is now done with duplicate operationId |
return javaName.replace("$", "."); | ||
String packageName = fullClassName.substring(0, fullClassName.lastIndexOf('.')); | ||
OpenApiApplicationVisitor.SchemaDecorator schemaDecorator = OpenApiApplicationVisitor.getSchemaDecoration(packageName, context); | ||
javaName = javaName.replace("$", "."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use getCanonicalName()
on the element instead of this hack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? If you are talking about substring by dollar symbol, then this is not my code, it was written that way. And I didn't understand how you suggest to use canoncialName ? getCanoncialName returns the full name of the class along with the package, but I don't need it, I need either the class name or the package name.
In any case, I changed the logic for calculating the package name.
@@ -218,6 +218,25 @@ public class OpenApiApplicationVisitor extends AbstractOpenApiVisitor implements | |||
*/ | |||
private static final String MICRONAUT_OPENAPI_SCHEMA = "micronaut.openapi.schema"; | |||
private static final String MICRONAUT_CUSTOM_SCHEMAS = "micronaut.internal.custom.schemas"; | |||
/** | |||
* Properties prefix to set schema name prefixe or postfix by package. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo prefixe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@graemerocher Thanks! :-) Could you release all fixes ? |
Done, thanks for the contributions! |
If you have some classes with same names in different packages you can set postfix like this:
or by system properties:
or by openapi.properties