Search in sources :

Example 46 with Parameter

use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.

the class OpMeta method init.

protected void init() {
    Class<?> swaggerInterface = ClassUtils.getOrCreateInterface(swagger, null, null);
    for (OperationGenerator operationGenerator : providerGenerator.getOperationGeneratorMap().values()) {
        String methodName = operationGenerator.getProviderMethod().getName();
        Method swaggerMethod = ReflectUtils.findMethod(swaggerInterface, methodName);
        List<Parameter> swaggerParameters = findParameter(swagger, methodName);
        List<Parameter> providerParameters = findParameter(providerGenerator, methodName);
        ARGS_MAPPER argsMapper = factory.createArgumentsMapper(swagger, swaggerMethod, swaggerParameters, operationGenerator.getProviderMethod(), providerParameters);
        swaggerMethodMap.put(methodName, swaggerMethod);
        operationArgsMapperMap.put(methodName, argsMapper);
    }
}
Also used : Parameter(io.swagger.models.parameters.Parameter) Method(java.lang.reflect.Method) OperationGenerator(io.servicecomb.swagger.generator.core.OperationGenerator)

Example 47 with Parameter

use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.

the class RestOperationMeta method init.

public void init(OperationMeta operationMeta) {
    this.operationMeta = operationMeta;
    Swagger swagger = operationMeta.getSchemaMeta().getSwagger();
    Operation operation = operationMeta.getSwaggerOperation();
    this.produces = operation.getProduces();
    if (produces == null) {
        this.produces = swagger.getProduces();
    }
    setAbsolutePath(concatPath(swagger.getBasePath(), operationMeta.getOperationPath()));
    this.createProduceProcessors();
    Method method = operationMeta.getMethod();
    Type[] genericParamTypes = method.getGenericParameterTypes();
    if (genericParamTypes.length != operation.getParameters().size()) {
        throw new Error("Param count is not equal between swagger and method,  path=" + absolutePath);
    }
    // 初始化所有rest param
    for (int idx = 0; idx < genericParamTypes.length; idx++) {
        Parameter parameter = operation.getParameters().get(idx);
        Type genericParamType = genericParamTypes[idx];
        RestParam param = new RestParam(idx, parameter, genericParamType);
        addParam(param);
    }
    this.pathBuilder = new URLPathBuilder(absolutePath, paramMap);
}
Also used : MediaType(javax.ws.rs.core.MediaType) Type(java.lang.reflect.Type) Swagger(io.swagger.models.Swagger) Parameter(io.swagger.models.parameters.Parameter) URLPathBuilder(io.servicecomb.common.rest.definition.path.URLPathBuilder) Operation(io.swagger.models.Operation) Method(java.lang.reflect.Method)

Example 48 with Parameter

use of io.swagger.models.parameters.Parameter in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20 method getParameters.

public static List<Parameter> getParameters(String uriTemplate) {
    List<Parameter> parameters = new ArrayList<>();
    StringTokenizer stringTokenizer = new StringTokenizer(uriTemplate, "/");
    while (stringTokenizer.hasMoreElements()) {
        String part1 = stringTokenizer.nextToken();
        if (part1.contains("{")) {
            String pathParam = part1.replace("{", "").replace("}", "");
            PathParameter parameter = new PathParameter();
            parameter.setName(pathParam);
            parameter.setType("string");
            parameters.add(parameter);
        }
    }
    return parameters;
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter)

Example 49 with Parameter

use of io.swagger.models.parameters.Parameter in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20 method generateSwaggerFromResources.

@Override
public String generateSwaggerFromResources(CompositeAPI.Builder api) {
    Swagger swagger = new Swagger();
    Info info = new Info();
    info.setTitle(api.getName());
    info.setDescription(api.getDescription());
    info.setVersion(api.getVersion());
    swagger.setInfo(info);
    Map<String, Path> stringPathMap = new HashMap();
    for (UriTemplate uriTemplate : api.getUriTemplates().values()) {
        String uriTemplateString = uriTemplate.getUriTemplate();
        List<Parameter> parameterList = getParameters(uriTemplateString);
        if (!HttpMethod.GET.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.DELETE.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.OPTIONS.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.HEAD.toString().equalsIgnoreCase(uriTemplate.getHttpVerb())) {
            parameterList.add(getDefaultBodyParameter());
        }
        Operation operation = new Operation();
        operation.setParameters(parameterList);
        operation.setOperationId(uriTemplate.getTemplateId());
        operation.addResponse("200", getDefaultResponse());
        if (stringPathMap.containsKey(uriTemplateString)) {
            Path path = stringPathMap.get(uriTemplateString);
            path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
        } else {
            Path path = new Path();
            path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
            stringPathMap.put(uriTemplateString, path);
        }
    }
    swagger.setPaths(stringPathMap);
    swagger.setPaths(stringPathMap);
    return Json.pretty(swagger);
}
Also used : Path(io.swagger.models.Path) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Swagger(io.swagger.models.Swagger) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) ServiceMethodInfo(org.wso2.msf4j.ServiceMethodInfo) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate)

Example 50 with Parameter

use of io.swagger.models.parameters.Parameter in project carbon-apimgt by wso2.

the class DynamicHtmlGenTestCase method testFromParameter.

@Test
public void testFromParameter() throws Exception {
    Parameter parameter = new QueryParameter();
    parameter.setName("query");
    final String description = "Sample parameter description";
    parameter.setDescription(description);
    DynamicHtmlGen htmlGen = new DynamicHtmlGen();
    CodegenParameter modified = htmlGen.fromParameter(parameter, new HashSet<>());
    Assert.assertEquals(modified.description, description);
}
Also used : CodegenParameter(io.swagger.codegen.CodegenParameter) QueryParameter(io.swagger.models.parameters.QueryParameter) DynamicHtmlGen(org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) CodegenParameter(io.swagger.codegen.CodegenParameter) Test(org.testng.annotations.Test)

Aggregations

Parameter (io.swagger.models.parameters.Parameter)92 BodyParameter (io.swagger.models.parameters.BodyParameter)54 QueryParameter (io.swagger.models.parameters.QueryParameter)53 PathParameter (io.swagger.models.parameters.PathParameter)51 Test (org.testng.annotations.Test)51 HeaderParameter (io.swagger.models.parameters.HeaderParameter)38 Swagger (io.swagger.models.Swagger)33 FormParameter (io.swagger.models.parameters.FormParameter)27 Operation (io.swagger.models.Operation)20 SerializableParameter (io.swagger.models.parameters.SerializableParameter)15 Type (java.lang.reflect.Type)14 ArrayList (java.util.ArrayList)14 Annotation (java.lang.annotation.Annotation)10 Path (io.swagger.models.Path)9 Method (java.lang.reflect.Method)9 JavaType (com.fasterxml.jackson.databind.JavaType)7 ContextParameter (io.servicecomb.swagger.extend.parameter.ContextParameter)6 Property (io.swagger.models.properties.Property)6 HashMap (java.util.HashMap)6 AnnotatedParameter (com.fasterxml.jackson.databind.introspect.AnnotatedParameter)5