Java Code Examples for io.swagger.models.parameters.Parameter#setName()

The following examples show how to use io.swagger.models.parameters.Parameter#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestPath.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testUrlPathBuilder() throws Exception {
  Map<String, RestParam> paramMap = new HashMap<>();

  Parameter pathParameter = new PathParameter();
  pathParameter.setName("id");
  RestParam oRestParam = new RestParam(pathParameter, int.class);
  paramMap.put(oRestParam.getParamName(), oRestParam);

  Parameter queryParameter = new QueryParameter();
  queryParameter.setName("q");
  oRestParam = new RestParam(queryParameter, String.class);
  paramMap.put(oRestParam.getParamName(), oRestParam);

  URLPathBuilder oURLPathBuilder = new URLPathBuilder("/root/{id}", paramMap);
  Map<String, Object> parameters = new HashMap<>();
  parameters.put("id", 100);
  parameters.put("q", "query");
  Assert.assertEquals("/root/100?q=query", oURLPathBuilder.createRequestPath(parameters));
  Assert.assertEquals("/root/100", oURLPathBuilder.createPathString(parameters));
}
 
Example 2
Source File: TestQueryProcessorCreator.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreate() {
  ParamValueProcessorCreator creator =
      ParamValueProcessorCreatorManager.INSTANCE.findValue(QueryProcessorCreator.PARAMTYPE);
  Parameter parameter = new QueryParameter();
  parameter.setName("query");

  ParamValueProcessor processor = creator.create(parameter, String.class);

  Assert.assertEquals(QueryProcessor.class, processor.getClass());

  String result = (String) processor.convertValue("Hello", TypeFactory.defaultInstance().constructType(String.class));
  Assert.assertEquals("Hello", result);

  result = (String) processor.convertValue("", TypeFactory.defaultInstance().constructType(String.class));
  Assert.assertEquals("", result);

  result = (String) processor.convertValue(null, TypeFactory.defaultInstance().constructType(String.class));
  Assert.assertEquals(null, result);
}
 
Example 3
Source File: FlaskConnexionCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
@Override
public void preprocessSwagger(Swagger swagger) {
    // need vendor extensions for x-swagger-router-controller
    Map<String, Path> paths = swagger.getPaths();
    if(paths != null) {
        for(String pathname : paths.keySet()) {
            Path path = paths.get(pathname);
            Map<HttpMethod, Operation> operationMap = path.getOperationMap();
            if(operationMap != null) {
                for(HttpMethod method : operationMap.keySet()) {
                    Operation operation = operationMap.get(method);
                    String tag = "default";
                    if(operation.getTags() != null && operation.getTags().size() > 0) {
                        tag = operation.getTags().get(0);
                    }
                    String operationId = operation.getOperationId();
                    if(operationId == null) {
                        operationId = getOrGenerateOperationId(operation, pathname, method.toString());
                    }
                    operation.setOperationId(toOperationId(operationId));
                    if(operation.getVendorExtensions().get("x-swagger-router-controller") == null) {
                        operation.getVendorExtensions().put(
                                "x-swagger-router-controller",
                                controllerPackage + "." + toApiFilename(tag)
                        );
                    }
                    for (Parameter param: operation.getParameters()) {
                        // sanitize the param name but don't underscore it since it's used for request mapping
                        String name = param.getName();
                        String paramName = sanitizeName(name);
                        if (!paramName.equals(name)) {
                            LOGGER.warn(name + " cannot be used as parameter name with flask-connexion and was sanitized as " + paramName);
                        }
                        param.setName(paramName);
                    }
                }
            }
        }
    }
}
 
Example 4
Source File: TestRestCodec.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() {
  Parameter hp = new HeaderParameter();
  hp.setName("header");
  RestParam restParam = new RestParam(hp, int.class);

  restOperation = Mockito.mock(RestOperationMeta.class);
  //        clientRequest = Mockito.mock(RestClientRequest.class);
  paramList = new ArrayList<>();


  paramList.add(restParam);
  when(restOperation.getParamList()).thenReturn(paramList);
  when(restOperation.getParamByName("test")).thenReturn(restParam);
}
 
Example 5
Source File: TestPathProcessorCreator.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreate() {
  ParamValueProcessorCreator creator =
      ParamValueProcessorCreatorManager.INSTANCE.findValue(PathProcessorCreator.PARAMTYPE);
  Parameter parameter = new PathParameter();
  parameter.setName("path");

  ParamValueProcessor processor = creator.create(parameter, String.class);

  Assert.assertEquals(PathProcessor.class, processor.getClass());
}
 
Example 6
Source File: TestQueryProcessorCreator.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("UnusedAssignment")
@Test
public void testCreateNullAsEmpty() throws Exception {
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  ArchaiusUtils.setProperty("servicecomb.rest.parameter.query.emptyAsNull", "true");
  ParamValueProcessorCreator creator =
      ParamValueProcessorCreatorManager.INSTANCE.findValue(QueryProcessorCreator.PARAMTYPE);
  Parameter parameter = new QueryParameter();
  parameter.setName("query");

  ParamValueProcessor processor = creator.create(parameter, String.class);

  Assert.assertEquals(QueryProcessor.class, processor.getClass());

  Mockito.when(request.getParameter("query")).thenReturn("Hello");
  String result = (String) processor.getValue(request);
  Assert.assertEquals("Hello", result);

  Mockito.when(request.getParameter("query")).thenReturn("");
  result = (String) processor.getValue(request);
  Assert.assertEquals(null, result);

  Mockito.when(request.getParameter("query")).thenReturn(null);
  result = (String) processor.convertValue(null, TypeFactory.defaultInstance().constructType(String.class));
  result = (String) processor.getValue(request);
  Assert.assertEquals(null, result);
}
 
Example 7
Source File: URLPathBuilderTest.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
private void addParam(String paramName, Type paramType,
    ParameterConstructor constructor, Map<String, RestParam> paramMap) {
  Parameter parameter = constructor.construct();
  parameter.setName(paramName);
  paramMap.put(paramName, new RestParam(parameter, paramType));
}
 
Example 8
Source File: PlayReader.java    From swagger-play with Apache License 2.0 4 votes vote down vote up
private List<Parameter> getParameters(Class<?> cls, Method method, Route route) {
    // TODO now consider only parameters defined in route, excluding body parameters
    // understand how to possibly infer body/form params e.g. from @BodyParser or
    // other annotation

    List<Parameter> parameters = new ArrayList<>();
    if (!route.call().parameters().isDefined()) {
        return parameters;
    }
    scala.collection.Iterator<play.routes.compiler.Parameter> iter = route.call().parameters().get().iterator();

    int fieldPosition = 0;
    while (iter.hasNext()) {
        play.routes.compiler.Parameter p = iter.next();
        if (!p.fixed().isEmpty())
            continue;
        Parameter parameter;
        String def = CrossUtil.getParameterDefaultField(p);
        if (def.startsWith("\"") && def.endsWith("\"")) {
            def = def.substring(1, def.length() - 1);
        }
        Type type = getParamType(cls, method, p.typeName(), fieldPosition);
        Property schema = createProperty(type);
        if (route.path().has(p.name())) {
            // it's a path param
            parameter = new PathParameter();
            ((PathParameter) parameter).setDefaultValue(def);
            if (schema != null)
                ((PathParameter) parameter).setProperty(schema);
        } else {
            // it's a query string param
            parameter = new QueryParameter();
            ((QueryParameter) parameter).setDefaultValue(def);
            if (schema != null)
                ((QueryParameter) parameter).setProperty(schema);
        }
        parameter.setName(p.name());
        List<Annotation> annotations = getParamAnnotations(cls, method, p.typeName(), fieldPosition);
        ParameterProcessor.applyAnnotations(getSwagger(), parameter, type, annotations);
        parameters.add(parameter);
        fieldPosition++;
    }
    return parameters;
}