本文整理匯總了Java中io.swagger.models.Path類的典型用法代碼示例。如果您正苦於以下問題:Java Path類的具體用法?Java Path怎麽用?Java Path使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Path類屬於io.swagger.models包,在下文中一共展示了Path類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: correctResponsesHavePaths
import io.swagger.models.Path; //導入依賴的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());
}
示例2: setup
import io.swagger.models.Path; //導入依賴的package包/類
@Before
public void setup() {
BeanUtils.setContext(applicationContext);
MicroserviceMeta mm = new MicroserviceMeta("app:ms");
Swagger swagger = UnitTestSwaggerUtils.generateSwagger(TestServicePathManagerSchemaImpl.class).getSwagger();
Map<String, Path> paths = swagger.getPaths();
swagger.setBasePath("");
Path path = paths.remove("/static1");
paths.put("/root/rest/static1", path);
path = paths.remove("/dynamic1");
paths.put("/dynamic1/{id}", path);
path = paths.remove("/dynamic2");
paths.put("/dynamic2/{id}", path);
SchemaMeta schemaMeta = new SchemaMeta(swagger, mm, "sid");
spm = new ServicePathManager(mm);
spm.addSchema(schemaMeta);
spm.sortPath();
}
示例3: getOperation
import io.swagger.models.Path; //導入依賴的package包/類
public Operation getOperation() {
Path p = swagger.getPath(path.toString());
if (p != null) {
switch (method) {
case GET:
return p.getGet();
case POST:
return p.getPost();
case PUT:
return p.getPut();
case DELETE:
return p.getDelete();
case PATCH:
return p.getPatch();
default:
return null;
}
}
return null;
}
示例4: testApplyParameters
import io.swagger.models.Path; //導入依賴的package包/類
@SuppressWarnings({ "serial" })
@Test
public void testApplyParameters(){
Swagger swagger = new Swagger();
Reader.read(swagger, new HashMap<Class<?>, Object>(){{
put(InterfaceServiceTest.class, new InterfaceServiceImplTest());
}}, "/h");
// System.out.println(Json.pretty(swagger));
Path path = swagger.getPaths().get("/h/com.deepoove.swagger.dubbo.api.InterfaceServiceTest/test");
Assert.assertNotNull(path);
Operation operation = path.getOperationMap().get(HttpMethod.POST);
Assert.assertNotNull(operation);
Assert.assertNotNull(operation.getParameters());
List<Parameter> parameters = operation.getParameters();
Assert.assertTrue(parameters.get(0).getName().equals("para"));
Assert.assertTrue(parameters.get(1).getName().equals("code"));
}
示例5: path2UtilSubscriptions
import io.swagger.models.Path; //導入依賴的package包/類
private Path path2UtilSubscriptions(Parameter idParam) {
Path path = new Path();
if (idParam != null) {
path.setParameters(Collections.singletonList(paramId()));
}
ServiceDocument subscriptionState = template(ServiceSubscriptionState.class);
path.setGet(opDefault(subscriptionState));
io.swagger.models.Operation deleteOrPost = new io.swagger.models.Operation();
deleteOrPost.addParameter(paramBody(template(ServiceSubscriber.class)));
deleteOrPost.addTag(this.currentTag.getName());
deleteOrPost.setResponses(responseMap(
Operation.STATUS_CODE_OK, responseOk(subscriptionState)));
path.setDelete(deleteOrPost);
path.setPost(deleteOrPost);
return path;
}
示例6: path2UtilConfig
import io.swagger.models.Path; //導入依賴的package包/類
private Path path2UtilConfig(Parameter idParam) {
Path path = new Path();
if (idParam != null) {
path.setParameters(Collections.singletonList(paramId()));
}
io.swagger.models.Operation op = new io.swagger.models.Operation();
op.addTag(this.currentTag.getName());
op.setResponses(responseMap(
Operation.STATUS_CODE_OK, responseOk(template(ServiceConfiguration.class)),
Operation.STATUS_CODE_NOT_FOUND, responseGenericError()));
path.setGet(op);
op = new io.swagger.models.Operation();
op.addTag(this.currentTag.getName());
op.setParameters(
Collections.singletonList(paramBody(ServiceConfigUpdateRequest.class)));
op.setResponses(responseMap(
Operation.STATUS_CODE_OK, responseOk(template(ServiceConfiguration.class)),
Operation.STATUS_CODE_NOT_FOUND, responseGenericError()));
path.setPatch(op);
return path;
}
示例7: path2Instance
import io.swagger.models.Path; //導入依賴的package包/類
private Map<String, Path> path2Instance(ServiceDocument doc) {
if (doc.documentDescription != null
&& doc.documentDescription.serviceRequestRoutes != null
&& !doc.documentDescription.serviceRequestRoutes.isEmpty()) {
return pathByRoutes(doc.documentDescription.serviceRequestRoutes.values(),
this::defaultInstancePath);
} else {
io.swagger.models.Operation op = new io.swagger.models.Operation();
op.addTag(this.currentTag.getName());
op.setParameters(Collections.singletonList(paramBody(ServiceDocument.class)));
op.setResponses(responseMap(
Operation.STATUS_CODE_OK, responseOk(doc),
Operation.STATUS_CODE_NOT_FOUND, responseGenericError()));
// service definition should be introspected to better
// describe which actions are supported
Path path = this.defaultInstancePath();
path.setGet(opDefault(doc));
path.setPost(op);
path.setPut(op);
path.setPatch(op);
path.setDelete(op);
return Collections.singletonMap("", path);
}
}
示例8: processUris
import io.swagger.models.Path; //導入依賴的package包/類
private void processUris(final Map<String, Path> swagger,
final Map<String, Model> definitionsMap,
final Map<String, SecuritySchemeDefinition> securityDefinitionsMap,
final int i) {
int j = 0;
while (env.containsProperty(String.format("swagger[%d].uris[%d].swagger", i, j))) {
try {
final URL swaggerUrl = env.getProperty(String.format("swagger[%d].uris[%d].swagger", i, j), URL.class);
final Swagger remoteSwagger = io.swagger.util.Json.mapper().readerFor(Swagger.class).readValue(swaggerUrl.openConnection().getInputStream());
processPaths(swagger, definitionsMap, securityDefinitionsMap, remoteSwagger, i, j);
++j;
} catch (final IOException e) {
throw new UncheckedIOException(e);
}
}
}
示例9: parse
import io.swagger.models.Path; //導入依賴的package包/類
public static Swagger parse(String requestUrl, Collection<UrlMapper> collection) {
Swagger swagger = parseCommon(requestUrl, null);
List<Tag> tags = new ArrayList<Tag>();
Map<String, Path> paths = new HashMap<String, Path>();
Map<String, Model> models = new HashMap<String, Model>();
for (UrlMapper urlMapper : collection) {
if (urlMapper != null) {
Swagger p_swagger = parse(requestUrl, urlMapper);
if (p_swagger != null) {
if (p_swagger != null) {
tags.addAll(p_swagger.getTags());
paths.putAll(p_swagger.getPaths());
models.putAll(p_swagger.getDefinitions());
}
}
}
}
swagger.setTags(tags);
swagger.setPaths(paths);
swagger.setDefinitions(models);
return swagger;
}
示例10: testReadPath
import io.swagger.models.Path; //導入依賴的package包/類
public static void testReadPath() throws JsonProcessingException, IOException {
String data = "{"
+ "\"post\": { \"tags\": [\"pet\"], \"summary\": \"add a new pet to the store\", \"description\": \"\", \"operationid\": \"addpet\", \"consumes\": [\"application/json\", \"application/xml\"], \"produces\": [\"application/xml\", \"application/json\"], \"parameters\": [{ \"in\": \"body\", \"name\": \"body\", \"description\": \"pet object that needs to be added to the store\", \"required\": true, \"schema\": { \"$ref\": \"#/definitions/pet\" } }], \"responses\": { \"405\": { \"description\": \"invalid input\" } }, \"security\": [{ \"petstore_auth\": [\"write:pets\", \"read:pets\"] }] },"
+ "\"put\": { \"tags\": [\"pet\"], \"summary\": \"update an existing pet\", \"description\": \"\", \"operationid\": \"updatepet\", \"consumes\": [\"application/json\", \"application/xml\"], \"produces\": [\"application/xml\", \"application/json\"], \"parameters\": [{ \"in\": \"body\", \"name\": \"body\", \"description\": \"pet object that needs to be added to the store\", \"required\": true, \"schema\": { \"$ref\": \"#/definitions/pet\" } }], \"responses\": { \"400\": { \"description\": \"invalid id supplied\" }, \"404\": { \"description\": \"pet not found\" }, \"405\": { \"description\": \"validation exception\" } }, \"security\": [{ \"petstore_auth\": [\"write:pets\", \"read:pets\"] }] }"
+ "}";
ObjectMapper mapper = Json.mapper();
JsonNode pathNode = mapper.readTree(data);
Path path = mapper.convertValue(pathNode, Path.class);
Json.prettyPrint(path);
}
示例11: extractApiOperation
import io.swagger.models.Path; //導入依賴的package包/類
/**
* @param swagger Swagger specification
* @param path path of the requested operation
* @param apiPath path of
* @return {@link ApiOperation} if the provided swagger does contain the requested method at the
* provided path, <code>null</code> otherwise
*/
public static ApiOperation extractApiOperation(@NonNull Swagger swagger, @NonNull String path,
@NonNull Path apiPath) {
Method realMethod = Method.GET;
if (apiPath.getGet() != null) {
realMethod = Method.GET;
}
if (apiPath.getPost() != null) {
realMethod = Method.POST;
}
ApiOperationMatch apiOperationMatch =
new ApiOperationResolver(swagger, null).findApiOperation(path, realMethod);
return apiOperationMatch.isPathFound() && apiOperationMatch.isOperationAllowed()
? apiOperationMatch.getApiOperation()
: null;
}
示例12: mapEndpointWithoutBasePath
import io.swagger.models.Path; //導入依賴的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"));
}
示例13: map_ThrowsException_EndpointWithoutProduces
import io.swagger.models.Path; //導入依賴的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);
}
示例14: map_ThrowsException_EndpointWithoutResponses
import io.swagger.models.Path; //導入依賴的package包/類
@Test
public void map_ThrowsException_EndpointWithoutResponses() throws IOException {
// Arrange
mockDefinition().host(DBEERPEDIA.OPENAPI_HOST).path("/breweries",
new Path().get(new Operation().vendorExtensions(
ImmutableMap.of(OpenApiSpecificationExtensions.INFORMATION_PRODUCT,
DBEERPEDIA.BREWERIES.stringValue()))));
// 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);
}
示例15: map_ThrowsException_EndpointWithoutOkResponse
import io.swagger.models.Path; //導入依賴的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);
}