2 * Copyright © 2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.sdc.workflow.api.swagger;
19 import static org.onap.sdc.workflow.api.RestParams.USER_ID_HEADER;
21 import com.fasterxml.classmate.TypeResolver;
22 import java.util.Optional;
23 import org.onap.sdc.workflow.services.annotations.UserId;
24 import org.springframework.core.annotation.Order;
25 import org.springframework.stereotype.Component;
26 import springfox.documentation.service.ResolvedMethodParameter;
27 import springfox.documentation.spi.DocumentationType;
28 import springfox.documentation.spi.service.ParameterBuilderPlugin;
29 import springfox.documentation.spi.service.contexts.ParameterContext;
30 import springfox.documentation.swagger.common.SwaggerPluginSupport;
33 * This component is neccesary because swagger cannot find a custom annotations in API.
34 * This is needed to find specifically the {@link UserId} annotation
37 @Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER + 1000)
38 public class UserIdReader implements ParameterBuilderPlugin {
40 private static final String HEADER = "header";
41 private final TypeResolver resolver;
43 public UserIdReader(TypeResolver resolver) {
44 this.resolver = resolver;
48 public void apply(ParameterContext parameterContext) {
49 ResolvedMethodParameter methodParameter = parameterContext.resolvedMethodParameter();
50 Optional<UserId> requestParam = methodParameter.findAnnotation(UserId.class);
51 if (requestParam.isPresent()) {
52 parameterContext.parameterBuilder().parameterType(HEADER).name(USER_ID_HEADER)
53 .type(resolver.resolve(String.class));
58 public boolean supports(DocumentationType documentationType) {