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);
}
}
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);
}
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;
}
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);
}
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);
}
Aggregations