当前位置: 首页>>代码示例>>Java>>正文


Java Response类代码示例

本文整理汇总了Java中io.swagger.models.Response的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Response类属于io.swagger.models包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: correctResponsesHavePaths

import io.swagger.models.Response; //导入依赖的package包/类
@Test
public void correctResponsesHavePaths() {
  Response response = new Response();

  Operation operation = new Operation();
  operation.addResponse("200", response);

  Path path = new Path();
  path.set("get", operation);

  Swagger swagger = new Swagger();
  swagger.path("/base", path);

  SwaggerUtils.correctResponses(swagger);

  Assert.assertEquals("response of 200", response.getDescription());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:18,代码来源:TestSwaggerUtils.java

示例2: mapEndpointWithoutBasePath

import io.swagger.models.Response; //导入依赖的package包/类
@Test
public void mapEndpointWithoutBasePath() throws IOException {
  // Arrange
  mockDefinition().host(DBEERPEDIA.OPENAPI_HOST).produces(MediaType.TEXT_PLAIN).path("/breweries",
      new Path().get(new Operation().vendorExtensions(
          ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
              DBEERPEDIA.BREWERIES.stringValue())).response(Status.OK.getStatusCode(),
                  new Response().schema(mock(Property.class)))));
  when(informationProductResourceProviderMock.get(DBEERPEDIA.BREWERIES)).thenReturn(
      informationProductMock);

  // Act
  requestMapper.map(httpConfigurationMock);

  // Assert
  verify(httpConfigurationMock).registerResources(resourceCaptor.capture());
  Resource resource = resourceCaptor.getValue();
  assertThat(resource.getPath(), equalTo("/" + DBEERPEDIA.OPENAPI_HOST + "/breweries"));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:20,代码来源:OpenApiRequestMapperTest.java

示例3: map_ThrowsException_EndpointWithoutProduces

import io.swagger.models.Response; //导入依赖的package包/类
@Test
public void map_ThrowsException_EndpointWithoutProduces() throws IOException {
  // Arrange
  mockDefinition().host(DBEERPEDIA.OPENAPI_HOST).path("/breweries",
      new Path().get(new Operation().vendorExtensions(
          ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
              DBEERPEDIA.BREWERIES.stringValue())).response(Status.OK.getStatusCode(),
                  new Response().schema(mock(Property.class)))));

  // Assert
  thrown.expect(ConfigurationException.class);
  thrown.expectMessage(String.format("Path '%s' should produce at least one media type.",
      "/" + DBEERPEDIA.OPENAPI_HOST + "/breweries"));

  // Act
  requestMapper.map(httpConfigurationMock);
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:18,代码来源:OpenApiRequestMapperTest.java

示例4: map_ThrowsException_EndpointWithoutOkResponse

import io.swagger.models.Response; //导入依赖的package包/类
@Test
public void map_ThrowsException_EndpointWithoutOkResponse() throws IOException {
  // Arrange
  mockDefinition().host(DBEERPEDIA.OPENAPI_HOST).path("/breweries",
      new Path().get(new Operation().vendorExtensions(
          ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
              DBEERPEDIA.BREWERIES.stringValue())).response(201,
                  new Response().schema(mock(Property.class)))));

  // Assert
  thrown.expect(ConfigurationException.class);
  thrown.expectMessage(String.format("Resource '%s' does not specify a status %d response.",
      "/" + DBEERPEDIA.OPENAPI_HOST + "/breweries", Status.OK.getStatusCode()));

  // Act
  requestMapper.map(httpConfigurationMock);
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:18,代码来源:OpenApiRequestMapperTest.java

示例5: map_BodyParameter

import io.swagger.models.Response; //导入依赖的package包/类
@Test
public void map_BodyParameter() throws IOException {
  // Arrange
  Property property = mock(Property.class);
  List<Parameter> parameters = createBodyParameter("object");
  Operation newOp = new Operation();
  newOp.setParameters(parameters);
  newOp.vendorExtensions(ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
      DBEERPEDIA.BREWERIES.stringValue()));
  newOp.response(200, new Response().schema(property));
  mockDefinition().host(DBEERPEDIA.OPENAPI_HOST).produces(MediaType.APPLICATION_JSON).path(
      "/breweries", new Path().get(newOp));

  // Act
  requestMapper.map(httpConfigurationMock);

  // Assert
  verify(httpConfigurationMock).registerResources(resourceCaptor.capture());
  Resource resource = resourceCaptor.getValue();
  assertThat(resource.getPath(), equalTo("/" + DBEERPEDIA.OPENAPI_HOST + "/breweries"));

}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:23,代码来源:OpenApiRequestMapperTest.java

示例6: map_BodyParameterWithRefObject

import io.swagger.models.Response; //导入依赖的package包/类
@Test
public void map_BodyParameterWithRefObject() throws IOException {
  // Arrange
  Property property = mock(Property.class);
  List<Parameter> parameters = createBodyRefParameter();
  Operation newOp = new Operation();
  newOp.setParameters(parameters);
  newOp.vendorExtensions(ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
      DBEERPEDIA.BREWERIES.stringValue()));
  newOp.response(200, new Response().schema(property));
  mockDefinition().host(DBEERPEDIA.OPENAPI_HOST).produces(MediaType.APPLICATION_JSON).path(
      "/breweries", new Path().post(newOp));

  // Assert
  thrown.expect(ConfigurationException.class);
  thrown.expectMessage(String.format("No object property in body parameter"));

  // Act
  requestMapper.map(httpConfigurationMock);

}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:22,代码来源:OpenApiRequestMapperTest.java

示例7: map_BodyParameterNoObject

import io.swagger.models.Response; //导入依赖的package包/类
@Test
public void map_BodyParameterNoObject() throws IOException {
  // Arrange
  Property property = mock(Property.class);
  List<Parameter> parameters = createBodyParameter("object2");
  Operation newOp = new Operation();
  newOp.setParameters(parameters);
  newOp.vendorExtensions(ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
      DBEERPEDIA.BREWERIES.stringValue()));
  newOp.response(200, new Response().schema(property));
  mockDefinition().host(DBEERPEDIA.OPENAPI_HOST).produces(MediaType.APPLICATION_JSON).path(
      "/breweries", new Path().get(newOp));

  // Assert
  thrown.expect(ConfigurationException.class);
  thrown.expectMessage(String.format("No object property in body parameter"));

  // Act
  requestMapper.map(httpConfigurationMock);

}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:22,代码来源:OpenApiRequestMapperTest.java

示例8: map_ThrowsException_EndpointWithoutOkResponseSchema

import io.swagger.models.Response; //导入依赖的package包/类
@Test
public void map_ThrowsException_EndpointWithoutOkResponseSchema() throws IOException {
  // Arrange
  mockDefinition().produces(MediaType.TEXT_PLAIN).host(DBEERPEDIA.OPENAPI_HOST).path("/breweries",
      new Path().get(new Operation().vendorExtensions(
          ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
              DBEERPEDIA.BREWERIES.stringValue())).response(Status.OK.getStatusCode(),
                  new Response())));

  // Assert
  thrown.expect(ConfigurationException.class);
  thrown.expectMessage(
      String.format("Resource '%s' does not specify a schema for the status %d response.",
          "/" + DBEERPEDIA.OPENAPI_HOST + "/breweries", Status.OK.getStatusCode()));

  // Act
  requestMapper.map(httpConfigurationMock);
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:19,代码来源:OpenApiRequestMapperTest.java

示例9: map_ProducesPrecedence_WithValidData

import io.swagger.models.Response; //导入依赖的package包/类
@Test
public void map_ProducesPrecedence_WithValidData() throws IOException {
  // Arrange
  mockDefinition().host(DBEERPEDIA.OPENAPI_HOST).produces(MediaType.TEXT_PLAIN).path("/breweries",
      new Path().get(new Operation().vendorExtensions(
          ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
              DBEERPEDIA.BREWERIES.stringValue())).produces(MediaType.APPLICATION_JSON).response(
                  Status.OK.getStatusCode(), new Response().schema(mock(Property.class)))));
  when(informationProductResourceProviderMock.get(DBEERPEDIA.BREWERIES)).thenReturn(
      informationProductMock);

  // Act
  requestMapper.map(httpConfigurationMock);

  // Assert
  verify(httpConfigurationMock).registerResources(resourceCaptor.capture());
  ResourceMethod method = resourceCaptor.getValue().getResourceMethods().get(0);
  assertThat(method.getProducedTypes(), hasSize(1));
  assertThat(method.getProducedTypes().get(0), equalTo(MediaType.APPLICATION_JSON_TYPE));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:21,代码来源:OpenApiRequestMapperTest.java

示例10: mergeOperationPaths

import io.swagger.models.Response; //导入依赖的package包/类
private Map<HttpMethod, Operation> mergeOperationPaths(Path target, Path source) {
	Map<HttpMethod, Operation> mergedOperations = target.getOperationMap();

	for (Entry<HttpMethod, Operation> entry : source.getOperationMap().entrySet()) {
		if (!mergedOperations.containsKey(entry.getKey())) {
			logger.info("source operation %s is not present in existing Swagger JSON path", entry.getKey());
			mergedOperations.put(entry.getKey(), entry.getValue());
		} else {
			logger.info("source operation %s is present in existing Swagger JSON path, we shall merge operation responses", entry.getKey());
			Map<String, Response> modifiedResponses = mergeOperationResponse(mergedOperations.get(entry.getKey()),
					entry.getValue());
			mergedOperations.get(entry.getKey()).getResponses().putAll(modifiedResponses);
			mergedOperations.get(entry.getKey()).setParameters(entry.getValue().getParameters());
			logger.info("source operation %s is present in existing Swagger JSON path, merging of operation responses completed", entry.getKey());
		}
	}
	return mergedOperations;
}
 
开发者ID:pegasystems,项目名称:api2swagger,代码行数:19,代码来源:SwaggerUpdater.java

示例11: getResponseList

import io.swagger.models.Response; //导入依赖的package包/类
/**
 * @param responseMap
 */
private MyResponse getResponseList(Map.Entry<String, Response> responseMap) {
	MyResponse response;
	String resName = responseMap.getKey();
	Response resValue = responseMap.getValue();
	Property property = resValue.getSchema();

	if(property == null){
		//Response has no schema
		response = createEmptyResponse();
		response.setDescription(resValue.getDescription());
		response.setResponseNumber(resName);
	}
	else {
		if (property instanceof ArrayProperty) {
			ArrayProperty ap = (ArrayProperty) property;
			Property p2 = ap.getItems();
			response = extractSimple(resName, resValue, p2);
		} else {
			response = extractSimple(resName, resValue, property);
		}

	} 
	return response;
}
 
开发者ID:AmadeusITGroup,项目名称:docu.me,代码行数:28,代码来源:ApiData.java

示例12: createMethodResponses

import io.swagger.models.Response; //导入依赖的package包/类
private void createMethodResponses(RestApi api, Method method, String modelContentType, Map<String, Response> responses) {
    if (responses == null) {
        return;
    }

    // add responses from swagger
    responses.entrySet().forEach(e -> {
        if (e.getKey().equals("default")) {
            LOG.warn("Default response not supported, skipping");
        } else {
            LOG.info(format("Creating method response for api %s and method %s and status %s",
                            api.getId(), method.getHttpMethod(), e.getKey()));

            method.putMethodResponse(getCreateResponseInput(api, modelContentType, e.getValue()), e.getKey());
        }
    });
}
 
开发者ID:awslabs,项目名称:aws-apigateway-importer,代码行数:18,代码来源:ApiGatewaySdkSwaggerApiImporter.java

示例13: getModel

import io.swagger.models.Response; //导入依赖的package包/类
private Optional<Model> getModel(RestApi api, Response response) {

        String modelName;

        // if the response references a proper model, look for a model matching the model name
        if (response.getSchema() != null && response.getSchema().getType().equals("ref")) {
            modelName = ((RefProperty) response.getSchema()).getSimpleRef();
        } else {
            // if the response has an embedded schema, look for a model matching the generated name
            modelName = generateModelName(response);
        }

        try {
            Model model = api.getModelByName(modelName);
            if (model.getName() != null) {
                return Optional.of(model);
            }
        } catch (Exception ignored) {}

        return Optional.empty();
    }
 
开发者ID:awslabs,项目名称:aws-apigateway-importer,代码行数:22,代码来源:ApiGatewaySdkSwaggerApiImporter.java

示例14: processRestMethodReturnValue

import io.swagger.models.Response; //导入依赖的package包/类
/**
 * Processes the return value of a RequestMapping annotated method.
 *
 * @param returnType the return type.
 * @param operation the operation.
 * @param returnDescription the description of the return value.
 *
 * @throws MojoExecutionException if the return type isn't an XmlType.
 */
private void processRestMethodReturnValue(Class<?> returnType, Operation operation, String returnDescription) throws MojoExecutionException
{
    log.debug("Processing REST method return value \"" + returnType.getName() + "\".");

    // Add the class name to the list of classes which we will create an example for.
    exampleClassNames.add(returnType.getSimpleName());

    // Add the success response
    operation.response(200, new Response().description(returnDescription == null ? "Success" : returnDescription)
        .schema(new RefProperty(getXmlType(returnType).name().trim())));

    // If we have an error class, add that as the default response.
    if (modelErrorClass != null)
    {
        operation.defaultResponse(new Response().description("General Error").schema(new RefProperty(getXmlType(modelErrorClass).name().trim())));
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:27,代码来源:RestControllerProcessor.java

示例15: addResponse

import io.swagger.models.Response; //导入依赖的package包/类
private void addResponse(Operation operation, ApiResponse apiResponse) {
    Map<String, Property> responseHeaders = parseResponseHeaders(apiResponse.responseHeaders());

    Response response = new Response().description(apiResponse.message()).headers(responseHeaders);

    if (apiResponse.code() == 0) {
        operation.defaultResponse(response);
    } else {
        operation.response(apiResponse.code(), response);
    }

    if (StringUtils.isNotEmpty(apiResponse.reference())) {
        response.schema(new RefProperty(apiResponse.reference()));
    } else if (!isVoid(apiResponse.response())) {
        Type responseType = apiResponse.response();
        final Property property = ModelConverters.getInstance().readAsProperty(responseType);
        if (property != null) {
            response.schema(ContainerWrapper.wrapContainer(apiResponse.responseContainer(), property));
            appendModels(responseType);
        }
    }
}
 
开发者ID:wso2,项目名称:msf4j,代码行数:23,代码来源:ExtendedSwaggerReader.java


注:本文中的io.swagger.models.Response类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。