io.swagger.models.parameters.HeaderParameter Java Examples

The following examples show how to use io.swagger.models.parameters.HeaderParameter. 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: AbstractOperationGenerator.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
protected Parameter createParameter(HttpParameterType httpParameterType) {
  switch (httpParameterType) {
    case PATH:
      return new PathParameter();
    case QUERY:
      return new QueryParameter();
    case HEADER:
      return new HeaderParameter();
    case FORM:
      return new FormParameter();
    case COOKIE:
      return new CookieParameter();
    case BODY:
      return new BodyParameter();
    default:
      throw new IllegalStateException("not support httpParameterType " + httpParameterType);
  }
}
 
Example #2
Source File: JaxrsReaderTest.java    From swagger-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void createCommonParameters() throws Exception {
    reader = new JaxrsReader(new Swagger(), Mockito.mock(Log.class));
    Swagger result = reader.read(CommonParametersApi.class);
    Parameter headerParam = result.getParameter("headerParam");
    assertTrue(headerParam instanceof HeaderParameter);
    Parameter queryParam = result.getParameter("queryParam");
    assertTrue(queryParam instanceof QueryParameter);

    result = reader.read(ReferenceCommonParametersApi.class);
    Operation get = result.getPath("/apath").getGet();
    List<Parameter> parameters = get.getParameters();
    for (Parameter parameter : parameters) {
        assertTrue(parameter instanceof RefParameter);
    }

    ObjectMapper mapper = Json.mapper();
    ObjectWriter jsonWriter = mapper.writer(new DefaultPrettyPrinter());
    String json = jsonWriter.writeValueAsString(result);
    JsonNode expectJson = mapper.readTree(this.getClass().getResourceAsStream("/expectedOutput/swagger-common-parameters.json"));
    JsonAssert.assertJsonEquals(expectJson, json);
}
 
Example #3
Source File: OperationsTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private io.swagger.models.parameters.Parameter createOasHeader(com.github.jrcodeza.schema.v2.generator.model.Header header) {
	io.swagger.models.parameters.HeaderParameter parameter = new io.swagger.models.parameters.HeaderParameter();
	parameter.setType("string");
	parameter.setIn("header");
	parameter.setName(header.getName());
	parameter.setDescription(header.getDescription());
	parameter.setRequired(header.isRequired());
	return parameter;
}
 
Example #4
Source File: EmptyHeaderRule.java    From swagger-coverage with Apache License 2.0 5 votes vote down vote up
@Override
public Condition processParameter(Parameter parameter) {
    if (parameter instanceof HeaderParameter) {
        ConditionPredicate predicate = new DefaultParameterConditionPredicate(true, parameter.getName(), parameter.getIn());
        return new SinglePredicateCondition(
                String.format("header «%s» is empty", parameter.getName()),
                "",
                predicate
        );
    }

    return null;
}
 
Example #5
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 #6
Source File: TestHeaderProcessor.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private HeaderProcessor createProcessor(String name, Type type, String defaultValue, boolean required) {
  JavaType javaType = TypeFactory.defaultInstance().constructType(type);

  HeaderParameter headerParameter = new HeaderParameter();
  headerParameter.name(name)
      .required(required)
      .setDefaultValue(defaultValue);

  if (javaType.isContainerType()) {
    headerParameter.type(ArrayProperty.TYPE);
  }
  return new HeaderProcessor(headerParameter, javaType);
}
 
Example #7
Source File: TestHeaderProcessorCreator.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(HeaderProcessorCreator.PARAMTYPE);
  HeaderParameter hp = new HeaderParameter();
  hp.setName("h1");

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

  Assert.assertEquals(HeaderProcessor.class, processor.getClass());
}
 
Example #8
Source File: HeaderParameterExtractor.java    From vertx-swagger with Apache License 2.0 5 votes vote down vote up
@Override
public Object extract(String name, Parameter parameter, RoutingContext context) {
    HeaderParameter headerParam = (HeaderParameter) parameter;
    if ("array".equals(headerParam.getType())) {
        return context.request().headers().getAll(name);
    }
    return this.extract(name, parameter, context.request().headers());
}
 
Example #9
Source File: ResourceReaderExtension.java    From mdw with Apache License 2.0 5 votes vote down vote up
private Parameter createParam(String paramType) {
    if ("path".equals(paramType))
        return new PathParameter();
    else if ("query".equals(paramType))
        return new QueryParameter();
    else if ("form".equals(paramType))
        return new FormParameter();
    else if ("formData".equals(paramType))
        return new FormParameter();
    else if ("header".equals(paramType))
        return new HeaderParameter();
    else if ("body".equals(paramType))
        return new BodyParameter();
    return null;
}
 
Example #10
Source File: SwaggerWorkflowReader.java    From mdw with Apache License 2.0 5 votes vote down vote up
private io.swagger.models.parameters.Parameter createParam(ParameterType paramType) {
    if (paramType == ParameterType.Path)
        return new PathParameter();
    else if (paramType == ParameterType.Query)
        return new QueryParameter();
    else if (paramType == ParameterType.Form)
        return new FormParameter();
    else if (paramType == ParameterType.Header)
        return new HeaderParameter();
    else if (paramType == ParameterType.Body)
        return new BodyParameter();
    return null;
}
 
Example #11
Source File: HeaderProcessorCreator.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
public HeaderProcessor(HeaderParameter headerParameter, JavaType targetType) {
  super(headerParameter.getName(), targetType, headerParameter.getDefaultValue(), headerParameter.getRequired());

  this.repeatedType = ArrayProperty.isType(headerParameter.getType());
}
 
Example #12
Source File: HeaderProcessorCreator.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Override
public ParamValueProcessor create(Parameter parameter, Type genericParamType) {
  JavaType targetType =
      genericParamType == null ? null : TypeFactory.defaultInstance().constructType(genericParamType);
  return new HeaderProcessor((HeaderParameter) parameter, targetType);
}