-
Notifications
You must be signed in to change notification settings - Fork 100
Improvements for authorization classes generation. #2132
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
base: 6.16.x
Are you sure you want to change the base?
Improvements for authorization classes generation. #2132
Conversation
So, what has changed:
The final configuration will look something like this: openapi {
version = ver.openapi
client("client1", file("swagger.yml")) {
clientId = "client1"
apiPackageName = "com.generated.client1.api"
modelPackageName = "com.generated.client1.model"
invokerPackageName = "com.generated.client1.auth"
useAuth = true
}
client("client2", file("swagger2.yml")) {
clientId = "client2"
authorizationFilterPattern = "/test;/different/simple/path/**;/something/else"
apiPackageName = "com.generated.client2.api"
modelPackageName = "com.generated.client2.model"
invokerPackageName = "com.generated.client2.auth"
useAuth = true
}
}
To do this, generate the configuration and filter only in one of the clients, in all the others, disable the generation of Authorization classes. Next, set a single invockerPackage package in all clients. This way, the configuration and filter will be in a single instance, and in the other clients, only the @authorization annotation will be set above the methods in the client. The final configuration will look something like this: openapi {
version = ver.openapi
client("client", file("swagger.yml")) {
apiPackageName = "com.generated.client1.api"
modelPackageName = "com.generated.client1.model"
invokerPackageName = "com.generated.auth"
useAuth = true
}
client("client2", file("swagger2.yml")) {
authorizationFilterPattern = "/test;/different/simple/path/**;/something/else"
apiPackageName = "com.generated.client2.api"
modelPackageName = "com.generated.client2.model"
invokerPackageName = "com.generated.auth"
useAuth = true
additionalProperties = [
generateAuthClasses: false
]
}
} As you see
To do this, generate the configuration and filter only in one of the clients, in all the others, disable the generation of Authorization classes. Next, set a single invockerPackage package in all clients. This way, the configuration and filter will be in a single instance, and in the other clients, only the @authorization annotation will be set above the methods in the client. The final configuration will look something like this: openapi {
version = ver.openapi
client("client", file("swagger.yml")) {
clientId = "client1"
apiPackageName = "com.generated.client1.api"
modelPackageName = "com.generated.client1.model"
invokerPackageName = "com.generated.auth"
useAuth = true
additionalProperties = [
authFilterClientIds : ["client1", "client2"]
]
}
client("client2", file("swagger2.yml")) {
clientId = "client2"
authorizationFilterPattern = "/test;/different/simple/path/**;/something/else"
apiPackageName = "com.generated.client2.api"
modelPackageName = "com.generated.client2.model"
invokerPackageName = "com.generated.auth"
useAuth = true
additionalProperties = [
generateAuthClasses: false
]
}
} Also I've added some helpfull properties: useOauth = true // Generate AuthorizationFilter with support OAuth2.0 or not.
useBasicAuth = true // Generate HttpBasicAuthConfig class or not
useApiKeyAuth = true // Generate ApiKeyAuthConfigclass or not
authFilter = true // Generate AuthorizationFilter or not
generateAuthClasses = true // Generate authorization classes or not. If "false" annotaion will be added only in Client class, but you need to create annotation class yourself
authConfigName = test // This value will be used in generated configuration path and `AUTHORIZATION_NAMES` request attribute. This is useful, if you use this AuthFilter for several clients
authFilterClientIds = client1;client2 // List of client IDs for which this filter will be applied. This is useful if you use multiple clients to different internal microservices that share common authentication, such as an API KEY.
authFilterExcludedClientIds = "client3", "client4" // List client IDs for which this filter will NOT be applied
authorizationFilterPatternStyle = regex // Pattern style for Authorization filter. Available options: ANT (default), REGEX |
c2fd906
to
5b3cc27
Compare
5b3cc27
to
118d94d
Compare
Fixed #2115