|
10 | 10 | import io.swagger.models.Operation;
|
11 | 11 | import io.swagger.models.Path;
|
12 | 12 | import io.swagger.models.Swagger;
|
| 13 | +import io.swagger.models.auth.AbstractSecuritySchemeDefinition; |
| 14 | +import io.swagger.models.auth.SecuritySchemeDefinition; |
13 | 15 | import io.swagger.models.parameters.Parameter;
|
14 | 16 | import io.swagger.models.properties.*;
|
15 | 17 | import io.swagger.util.Yaml;
|
@@ -342,6 +344,7 @@ public void preprocessSwagger(Swagger swagger) {
|
342 | 344 | }
|
343 | 345 | }
|
344 | 346 | }
|
| 347 | + addSecurityExtensions(swagger.getSecurityDefinitions()); |
345 | 348 | }
|
346 | 349 |
|
347 | 350 | @SuppressWarnings("unchecked")
|
@@ -681,6 +684,27 @@ public void postProcessParameter(CodegenParameter parameter){
|
681 | 684 | postProcessPattern(parameter.pattern, parameter.vendorExtensions);
|
682 | 685 | }
|
683 | 686 |
|
| 687 | + protected void addSecurityExtensions(Map<String, SecuritySchemeDefinition> securitySchemes) { |
| 688 | + if (securitySchemes == null || securitySchemes.isEmpty()) { |
| 689 | + return; |
| 690 | + } |
| 691 | + for (String securityName : securitySchemes.keySet()) { |
| 692 | + final AbstractSecuritySchemeDefinition securityScheme = (AbstractSecuritySchemeDefinition) securitySchemes.get(securityName); |
| 693 | + final String functionName = controllerPackage + ".authorization_controller.check_" + securityName; |
| 694 | + |
| 695 | + if ("oauth2".equalsIgnoreCase(securityScheme.getType())) { |
| 696 | + securityScheme.getVendorExtensions().put("x-tokenInfoFunc", functionName); |
| 697 | + securityScheme.getVendorExtensions().put("x-scopeValidateFunc", controllerPackage + ".authorization_controller.validate_scope_" + securityName); |
| 698 | + } else if ("basic".equalsIgnoreCase(securityScheme.getType())) { |
| 699 | + securityScheme.getVendorExtensions().put("x-basicInfoFunc", functionName); |
| 700 | + } else if ("apiKey".equalsIgnoreCase(securityScheme.getType())) { |
| 701 | + securityScheme.getVendorExtensions().put("x-apikeyInfoFunc", functionName); |
| 702 | + } else { |
| 703 | + LOGGER.warn("Security type " + securityScheme.getType().toString() + " is not supported."); |
| 704 | + } |
| 705 | + } |
| 706 | + } |
| 707 | + |
684 | 708 | /*
|
685 | 709 | * The swagger pattern spec follows the Perl convention and style of modifiers. Python
|
686 | 710 | * does not support this in as natural a way so it needs to convert it. See
|
|
0 commit comments