io.swagger.models.HttpMethod Java Examples
The following examples show how to use
io.swagger.models.HttpMethod.
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: TestTreeRouter.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 6 votes |
@Test // produces the correct tree when given a single route with a single static path element public void treeTest2() { Route r = newRoute("/hello"); router.add(r); TreeNode root = router.getRoot(); assertEquals("^/$", root.toString()); assertNull(root.getRoute(HttpMethod.GET)); assertEquals(1, root.getChildren().size()); TreeNode child = root.getChildren().get(0); assertEquals("^hello$", child.toString()); assertEquals(r, child.getRoute(HttpMethod.GET)); assertNull(route("/")); assertEquals(r, route("/hello")); assertNull(route("/hello/")); assertNull(route("/blah")); }
Example #2
Source File: SpecificationDiff.java From swagger-diff with Apache License 2.0 | 6 votes |
private static List<Endpoint> convert2EndpointList(Map<String, Path> map) { List<Endpoint> endpoints = new ArrayList<Endpoint>(); if (null == map) return endpoints; map.forEach((url, path) -> { Map<HttpMethod, Operation> operationMap = path.getOperationMap(); operationMap.forEach((httpMethod, operation) -> { Endpoint endpoint = new Endpoint(); endpoint.setPathUrl(url); endpoint.setMethod(httpMethod); endpoint.setSummary(operation.getSummary()); endpoint.setPath(path); endpoint.setOperation(operation); endpoints.add(endpoint); }); }); return endpoints; }
Example #3
Source File: TestTreeRouter.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 6 votes |
@Test // produces the correct tree when given a sigle route with a single named path element public void treeTest8() { Route r1 = newRoute("/:name"); router.add(r1); TreeNode root = router.getRoot(); assertEquals("^/$", root.toString()); assertNull(root.getRoute(HttpMethod.GET)); assertEquals(1, root.getChildren().size()); TreeNode child = root.getChildren().get(0); assertEquals("^([^/]+)$", child.toString()); assertEquals(r1, child.getRoute(HttpMethod.GET)); assertEquals(0, child.getChildren().size()); assertNull(route("/")); assertEquals(r1, route("/john")); assertNull(route("/john/doe")); assertNull(route("/john/")); }
Example #4
Source File: SwaggerDiffTest.java From swagger-diff with Apache License 2.0 | 6 votes |
@Test public void testResponseBodyArray() { SwaggerDiff diff = SwaggerDiff.compareV2(SWAGGER_V2_DOC1, SWAGGER_V2_DOC2); Map<String, ChangedEndpoint> changedEndpointMap = diff.getChangedEndpoints().stream().collect(Collectors.toMap(ChangedEndpoint::getPathUrl, e -> e)); Lists.newArrayList("/pet/findByStatus", "/pet/findByTags").forEach(name -> { Assert.assertTrue("Expecting changed endpoint " + name, changedEndpointMap.containsKey(name)); ChangedEndpoint endpoint = changedEndpointMap.get(name); Assert.assertEquals(1, endpoint.getChangedOperations().size()); Assert.assertTrue("Expecting GET method change", endpoint.getChangedOperations().containsKey(HttpMethod.GET)); // assert changed property counts ChangedOperation changedOutput = endpoint.getChangedOperations().get(HttpMethod.GET); Assert.assertEquals(3, changedOutput.getAddProps().size()); Assert.assertEquals(3, changedOutput.getMissingProps().size()); Assert.assertEquals(1, changedOutput.getChangedProps().size()); // assert embedded array change is one of the missing properties List<ElProperty> missingProperties =changedOutput.getMissingProps(); Set<String> elementPaths = missingProperties.stream().map(ElProperty::getEl).collect(Collectors.toSet()); Assert.assertTrue(elementPaths.contains("tags.removedField")); }); }
Example #5
Source File: ExtensionHelper.java From swurg with Apache License 2.0 | 6 votes |
private List<String> buildHeaders( Swagger swagger, Map.Entry<String, Path> path, Map.Entry<HttpMethod, Operation> operation ) { List<String> headers = new ArrayList<>(); headers.add( operation.getKey().toString() + " " + nullEmptyString(swagger.getBasePath()) + path.getKey() + " HTTP/1.1"); headers.add("Host: " + swagger.getHost().split(":")[0]); if (CollectionUtils.isNotEmpty(operation.getValue().getProduces())) { headers.add("Accept: " + String.join(",", operation.getValue().getProduces())); } else if (CollectionUtils.isNotEmpty(swagger.getProduces())) { headers.add("Accept: " + String.join(",", swagger.getProduces())); } if (CollectionUtils.isNotEmpty(operation.getValue().getConsumes())) { headers.add("Content-Type: " + String.join(",", operation.getValue().getConsumes())); } else if (CollectionUtils.isNotEmpty(swagger.getConsumes())) { headers.add("Content-Type: " + String.join(",", swagger.getConsumes())); } return headers; }
Example #6
Source File: TestTreeRouter.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 6 votes |
@Test // produces the correct tree when given a single route with a single named parameter with custom regex public void treeTest10() { Route r1 = newRoute("/:id<[0-9]+>"); router.add(r1); TreeNode root = router.getRoot(); assertEquals("^/$", root.toString()); assertNull(root.getRoute(HttpMethod.GET)); assertEquals(1, root.getChildren().size()); TreeNode child = root.getChildren().get(0); assertEquals("^([0-9]+)$", child.toString()); assertEquals(r1, child.getRoute(HttpMethod.GET)); assertEquals(0, child.getChildren().size()); assertNull(route("/")); assertEquals(r1, route("/123")); assertNull(route("/123/456")); assertNull(route("/123/")); }
Example #7
Source File: TestTreeRouter.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 6 votes |
@Test // produces the correct tree when given the root route public void treeTest1() { Route r = newRoute("/"); router.add(r); TreeNode root = router.getRoot(); assertEquals("^/$", root.toString()); assertEquals(r, root.getRoute(HttpMethod.GET)); assertEquals(0, root.getChildren().size()); assertEquals(r, route("/")); assertNull(route("/*")); assertNull(route("/blah")); }
Example #8
Source File: SwaggerGeneratorTest.java From endpoints-java with Apache License 2.0 | 6 votes |
private void checkDuplicateOperations(Swagger actual) { Multimap<String, String> operationIds = HashMultimap.create(); for (Entry<String, Path> pathEntry : actual.getPaths().entrySet()) { for (Entry<HttpMethod, Operation> opEntry : pathEntry.getValue().getOperationMap() .entrySet()) { operationIds .put(opEntry.getValue().getOperationId(), pathEntry.getKey() + "|" + opEntry.getKey()); } } int duplicateOperationIdCount = 0; for (Entry<String, Collection<String>> entry : operationIds.asMap().entrySet()) { if (entry.getValue().size() > 1) { System.out.println("Duplicate operation id: " + entry); duplicateOperationIdCount++; } } assertThat(duplicateOperationIdCount).named("Duplicate operation ids").isEqualTo(0); }
Example #9
Source File: SwaggerOperations.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
public SwaggerOperations(Swagger swagger) { this.swagger = swagger; Map<String, Path> paths = swagger.getPaths(); if (paths == null) { return; } for (Entry<String, Path> pathEntry : paths.entrySet()) { for (Entry<HttpMethod, Operation> operationEntry : pathEntry.getValue().getOperationMap().entrySet()) { Operation operation = operationEntry.getValue(); if (StringUtils.isEmpty(operation.getOperationId())) { throw new IllegalStateException(String .format("OperationId can not be empty, path=%s, httpMethod=%s.", pathEntry.getKey(), operationEntry.getKey())); } SwaggerOperation swaggerOperation = new SwaggerOperation(swagger, pathEntry.getKey(), operationEntry.getKey(), operation); if (operations.putIfAbsent(operation.getOperationId(), swaggerOperation) != null) { throw new IllegalStateException( "please make sure operationId is unique, duplicated operationId is " + operation.getOperationId()); } } } }
Example #10
Source File: TestTreeRouter.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 6 votes |
@Test // produces the correct tree when given a single route with a splat that matches all paths public void treeTest12() { Route r1 = newRoute("/*"); router.add(r1); TreeNode root = router.getRoot(); assertEquals("^/$", root.toString()); assertNull(root.getRoute(HttpMethod.GET)); assertEquals(1, root.getChildren().size()); TreeNode child = root.getChildren().get(0); assertEquals("^(.*)$", child.toString()); assertEquals(r1, child.getRoute(HttpMethod.GET)); assertEquals(0, child.getChildren().size()); assertEquals(r1, route("/")); assertEquals(r1, route("/123")); assertEquals(r1, route("/123/456")); assertEquals(r1, route("/123/")); }
Example #11
Source File: TestTreeRouter.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 6 votes |
@Test // produces the correct tree when given the same route twice public void treeTest3() { Route r1 = newRoute("/hello"); Route r2 = newRoute("/hello"); router.add(r1); router.add(r2); TreeNode root = router.getRoot(); assertEquals("^/$", root.toString()); assertNull(root.getRoute(HttpMethod.GET)); assertEquals(1, root.getChildren().size()); TreeNode child = root.getChildren().get(0); assertEquals("^hello$", child.toString()); assertEquals(r1, child.getRoute(HttpMethod.GET)); assertNull(route("/")); assertEquals(r1, route("/hello")); assertNull(route("/hello/")); assertNull(route("/blah")); }
Example #12
Source File: SOAPOperationBindingTestCase.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testVendorExtensions() throws Exception { String swaggerStr = SOAPOperationBindingUtils.getSoapOperationMappingForUrl( Thread.currentThread().getContextClassLoader().getResource("wsdls/simpleCustomerService.wsdl") .toExternalForm()); Swagger swagger = new SwaggerParser().parse(swaggerStr); Assert.assertNotNull( swagger.getPath("/getCustomer").getOperationMap().get(HttpMethod.GET).getVendorExtensions()); Assert.assertNotNull(swagger.getPath("/getCustomer").getOperationMap().get(HttpMethod.GET).getVendorExtensions() .get("x-wso2-soap")); Map<String, Object> vendorExtensions = swagger.getPath("/getCustomer").getOperationMap().get(HttpMethod.GET) .getVendorExtensions(); for (String s : vendorExtensions.keySet()) { if (s.equals("soap-action")) { Assert.assertEquals(vendorExtensions.get("soap-action"), "getCustomer"); } if (s.equals("soap-operation")) { Assert.assertEquals(vendorExtensions.get("soap-operation"), "getCustomer"); } if (s.equals("namespace")) { Assert.assertEquals(vendorExtensions.get("namespace"), "http://service.test.com/"); } } }
Example #13
Source File: TestTreeRouter.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 6 votes |
@Test // produces the correct tree when given a single route with a splat that matches all paths, and the root route public void treeTest13() { Route r0 = newRoute("/"); Route r1 = newRoute("/*"); router.add(r0); router.add(r1); TreeNode root = router.getRoot(); assertEquals("^/$", root.toString()); assertEquals(r0, root.getRoute(HttpMethod.GET)); assertEquals(1, root.getChildren().size()); TreeNode child = root.getChildren().get(0); assertEquals("^(.*)$", child.toString()); assertEquals(r1, child.getRoute(HttpMethod.GET)); assertEquals(0, child.getChildren().size()); assertEquals(r0, route("/")); assertEquals(r1, route("/123")); assertEquals(r1, route("/123/456")); assertEquals(r1, route("/123/")); }
Example #14
Source File: TestTreeRouter.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 6 votes |
@Test // produces the correct tree when given the root route and a route with a single static path element public void treeTest6() { Route r1 = newRoute("/"); Route r2 = newRoute("/hello"); router.add(r1); router.add(r2); TreeNode root = router.getRoot(); assertEquals("^/$", root.toString()); assertEquals(r1, root.getRoute(HttpMethod.GET)); assertEquals(1, root.getChildren().size()); TreeNode child = root.getChildren().get(0); assertEquals("^hello$", child.toString()); assertEquals(r2, child.getRoute(HttpMethod.GET)); assertEquals(r1, route("/")); assertEquals(r2, route("/hello")); assertNull(route("/hello/")); assertNull(route("/blah")); }
Example #15
Source File: TestTreeRouter.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 6 votes |
@Test // produces the correct tree when given a single route with a single static path element with a regex symbol public void treeTest5() { Route r = newRoute("/hello$.html"); router.add(r); TreeNode root = router.getRoot(); assertEquals("^/$", root.toString()); assertNull(root.getRoute(HttpMethod.GET)); assertEquals(1, root.getChildren().size()); TreeNode child = root.getChildren().get(0); assertEquals("^hello\\$\\.html$", child.toString()); assertEquals(r, child.getRoute(HttpMethod.GET)); assertNull(route("/")); assertEquals(r, route("/hello$.html")); assertNull(route("/hello/")); assertNull(route("/blah")); }
Example #16
Source File: SwaggerHandler.java From light-rest-4j with Apache License 2.0 | 5 votes |
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { final NormalisedPath requestPath = new ApiNormalisedPath(exchange.getRequestURI()); final Optional<NormalisedPath> maybeApiPath = SwaggerHelper.findMatchingApiPath(requestPath); if (!maybeApiPath.isPresent()) { setExchangeStatus(exchange, STATUS_INVALID_REQUEST_PATH, requestPath.normalised()); return; } final NormalisedPath swaggerPathString = maybeApiPath.get(); final Path swaggerPath = SwaggerHelper.swagger.getPath(swaggerPathString.original()); final HttpMethod httpMethod = HttpMethod.valueOf(exchange.getRequestMethod().toString()); final Operation operation = swaggerPath.getOperationMap().get(httpMethod); if (operation == null) { setExchangeStatus(exchange, STATUS_METHOD_NOT_ALLOWED); return; } // This handler can identify the swaggerOperation and endpoint only. Other info will be added by JwtVerifyHandler. final SwaggerOperation swaggerOperation = new SwaggerOperation(swaggerPathString, swaggerPath, httpMethod, operation); String endpoint = swaggerPathString.normalised() + "@" + httpMethod.toString().toLowerCase(); Map<String, Object> auditInfo = new HashMap<>(); auditInfo.put(Constants.ENDPOINT_STRING, endpoint); auditInfo.put(Constants.SWAGGER_OPERATION_STRING, swaggerOperation); exchange.putAttachment(AttachmentConstants.AUDIT_INFO, auditInfo); Handler.next(exchange, next); }
Example #17
Source File: OAS2Parser.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Remove MG related information * * @param swagger Swagger */ private void removePublisherSpecificInfo(Swagger swagger) { Map<String, Object> extensions = swagger.getVendorExtensions(); OASParserUtil.removePublisherSpecificInfo(extensions); for (String pathKey : swagger.getPaths().keySet()) { Path path = swagger.getPath(pathKey); Map<HttpMethod, Operation> operationMap = path.getOperationMap(); for (Map.Entry<HttpMethod, Operation> entry : operationMap.entrySet()) { Operation operation = entry.getValue(); OASParserUtil.removePublisherSpecificInfofromOperation(operation.getVendorExtensions()); } } }
Example #18
Source File: TestTreeRouter.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 5 votes |
@Test // produces the correct tree when given a single route with multiple named path elements public void treeTest9() { Route r1 = newRoute("/:name/:id"); router.add(r1); TreeNode root = router.getRoot(); assertEquals("^/$", root.toString()); assertNull(root.getRoute(HttpMethod.GET)); assertEquals(1, root.getChildren().size()); TreeNode child = root.getChildren().get(0); assertEquals("^([^/]+)$", child.toString()); assertNull(child.getRoute(HttpMethod.GET)); assertEquals(1, child.getChildren().size()); child = child.getChildren().get(0); assertEquals("^([^/]+)$", child.toString()); assertEquals(r1, child.getRoute(HttpMethod.GET)); assertEquals(0, child.getChildren().size()); assertNull(route("/")); assertNull(route("/john")); assertEquals(r1, route("/john/doe")); assertNull(route("/john/")); assertNull(route("/john/doe/")); }
Example #19
Source File: RouteImpl.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 5 votes |
public RouteImpl(HttpMethod method, String pathPattern, boolean implemented, DataProvider dataProvider) { this.method = notEmpty(method, "method cannot be null"); this.path = notEmpty(pathPattern, "pathPattern cannot be null"); this.implemented = implemented; this.dataProvider = notEmpty(dataProvider, "dataProvider cannot be null"); this.allPathElements = new ArrayList<>(); this.splatParamElements = new ArrayList<>(); this.staticPathElements = new ArrayList<>(); this.namedParamElements = new ArrayList<>(); extractPathElements(pathPattern); }
Example #20
Source File: PathUtils.java From swagger2markup with Apache License 2.0 | 5 votes |
/** * Returns the operations of a path as a map which preserves the insertion order. * * @param path the path * @return the operations of a path as a map */ private static Map<HttpMethod, Operation> getOperationMap(Path path) { Map<HttpMethod, Operation> result = new LinkedHashMap<>(); if (path.getGet() != null) { result.put(HttpMethod.GET, path.getGet()); } if (path.getPut() != null) { result.put(HttpMethod.PUT, path.getPut()); } if (path.getPost() != null) { result.put(HttpMethod.POST, path.getPost()); } if (path.getDelete() != null) { result.put(HttpMethod.DELETE, path.getDelete()); } if (path.getPatch() != null) { result.put(HttpMethod.PATCH, path.getPatch()); } if (path.getHead() != null) { result.put(HttpMethod.HEAD, path.getHead()); } if (path.getOptions() != null) { result.put(HttpMethod.OPTIONS, path.getOptions()); } return result; }
Example #21
Source File: SpecificationDiff.java From swagger-diff with Apache License 2.0 | 5 votes |
private static Collection<? extends Endpoint> convert2EndpointList(String pathUrl, Map<HttpMethod, Operation> map) { List<Endpoint> endpoints = new ArrayList<Endpoint>(); if (null == map) return endpoints; map.forEach((httpMethod, operation) -> { Endpoint endpoint = new Endpoint(); endpoint.setPathUrl(pathUrl); endpoint.setMethod(httpMethod); endpoint.setSummary(operation.getSummary()); endpoint.setOperation(operation); endpoints.add(endpoint); }); return endpoints; }
Example #22
Source File: SwaggerDiffTest.java From swagger-diff with Apache License 2.0 | 5 votes |
@Test public void testInputBodyArray() { SwaggerDiff diff = SwaggerDiff.compareV2(SWAGGER_V2_DOC1, SWAGGER_V2_DOC2); Map<String, ChangedEndpoint> changedEndpointMap = diff.getChangedEndpoints().stream().collect(Collectors.toMap(ChangedEndpoint::getPathUrl, e -> e)); Lists.newArrayList("/user/createWithArray", "/user/createWithList").forEach(name -> { Assert.assertTrue("Expecting changed endpoint " + name, changedEndpointMap.containsKey(name)); ChangedEndpoint endpoint = changedEndpointMap.get(name); Assert.assertEquals(1, endpoint.getChangedOperations().size()); Assert.assertTrue("Expecting POST method change", endpoint.getChangedOperations().containsKey(HttpMethod.POST)); Assert.assertEquals(0, endpoint.getChangedOperations().get(HttpMethod.POST).getMissingParameters().size()); Assert.assertEquals(0, endpoint.getChangedOperations().get(HttpMethod.POST).getAddParameters().size()); Assert.assertEquals(1, endpoint.getChangedOperations().get(HttpMethod.POST).getChangedParameter().size()); // assert changed property counts ChangedParameter changedInput = endpoint.getChangedOperations().get(HttpMethod.POST).getChangedParameter().get(0); Assert.assertTrue(changedInput.getLeftParameter() instanceof BodyParameter); Assert.assertTrue(changedInput.getRightParameter() instanceof BodyParameter); Assert.assertEquals(3, changedInput.getIncreased().size()); Assert.assertEquals(3, changedInput.getMissing().size()); Assert.assertEquals(1, changedInput.getChanged().size()); // assert embedded array change is one of the missing properties List<ElProperty> missingProperties = changedInput.getMissing(); Set<String> elementPaths = missingProperties.stream().map(ElProperty::getEl).collect(Collectors.toSet()); Assert.assertTrue(elementPaths.contains("body.favorite.tags.removedField")); }); }
Example #23
Source File: SwaggerDiffTest.java From swagger-diff with Apache License 2.0 | 5 votes |
@Test public void testDetectProducesAndConsumes() { SwaggerDiff diff = SwaggerDiff.compareV2(SWAGGER_V2_DOC1, SWAGGER_V2_DOC2); Map<String, ChangedEndpoint> changedEndpointMap = diff.getChangedEndpoints().stream().collect(Collectors.toMap(ChangedEndpoint::getPathUrl, e -> e)); Assert.assertTrue("Expecting changed endpoint " + "/store/order", changedEndpointMap.containsKey("/store/order")); ChangedEndpoint endpoint = changedEndpointMap.get("/store/order"); Assert.assertTrue("Expecting POST method change", endpoint.getChangedOperations().containsKey(HttpMethod.POST)); ChangedOperation changedOperation = endpoint.getChangedOperations().get(HttpMethod.POST); Assert.assertEquals(1, changedOperation.getAddConsumes().size()); Assert.assertEquals(1, changedOperation.getMissingConsumes().size()); Assert.assertEquals(0, changedOperation.getAddProduces().size()); Assert.assertEquals(1, changedOperation.getMissingProduces().size()); }
Example #24
Source File: RouteFactoryImpl.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Route create(HttpMethod method, String pathPattern, boolean implemented, DataProvider dataProvider) { return new RouteImpl(method, pathPattern, implemented, dataProvider); }
Example #25
Source File: SwaggerValidator.java From mdw with Apache License 2.0 | 5 votes |
public SwaggerValidator(HttpMethod method, String path) throws ValidationException { this.method = method; this.path = path.startsWith("/") ? path : "/" + path; Swagger swagger = MdwSwaggerCache.getSwagger(this.path); if (swagger == null) throw new ValidationException(Status.NOT_FOUND.getCode(), "Swagger not found for path: " + this.path); io.swagger.models.Path swaggerPath = swagger.getPath(this.path); if (swaggerPath == null) throw new ValidationException(Status.NOT_FOUND.getCode(), "Swagger path not found: " + this.path); Operation swaggerOp = swaggerPath.getOperationMap().get(this.method); if (swaggerOp == null) throw new ValidationException(Status.NOT_FOUND.getCode(), "Swagger operation not found: " + method + " " + this.path); validator = new SwaggerModelValidator(method.toString(), this.path, swagger); }
Example #26
Source File: ParameterContributor.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
public ParameterContributor(final Collection<HttpMethod> httpMethods, final Collection<String> paths, final Collection<T> params) { this.httpMethods = checkNotNull(httpMethods); this.paths = checkNotNull(paths); this.params = checkNotNull(params); this.contributed = httpMethods.stream() .flatMap(httpMethod -> paths.stream().map(path -> getKey(httpMethod, path))) .collect(toMap(p -> (String) p, p -> false)); }
Example #27
Source File: ParameterContributor.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public void contribute(final Swagger swagger) { if (allContributed) { return; } for (HttpMethod httpMethod : httpMethods) { for (String path : paths) { contributed.compute(getKey(httpMethod, path), (key, value) -> value || contributeGetParameters(swagger, httpMethod, path, params)); } } allContributed = contributed.entrySet().stream().allMatch(Entry::getValue); }
Example #28
Source File: TestTreeRouter.java From binder-swagger-java with BSD 2-Clause "Simplified" License | 5 votes |
@Test // produces the correct tree when given a single route with multiple splat elements public void treeTest16() { Route r1 = newRoute("/say/*/to/*"); router.add(r1); TreeNode root = router.getRoot(); assertEquals("^/$", root.toString()); assertNull(root.getRoute(HttpMethod.GET)); assertEquals(1, root.getChildren().size()); TreeNode child = root.getChildren().get(0); assertEquals("^say$", child.toString()); assertNull(child.getRoute(HttpMethod.GET)); assertEquals(1, child.getChildren().size()); child = child.getChildren().get(0); assertEquals("^(.*)$", child.toString()); assertNull(child.getRoute(HttpMethod.GET)); assertEquals(1, child.getChildren().size()); child = child.getChildren().get(0); assertEquals("^to$", child.toString()); assertNull(child.getRoute(HttpMethod.GET)); assertEquals(1, child.getChildren().size()); child = child.getChildren().get(0); assertEquals("^(.*)$", child.toString()); assertEquals(r1, child.getRoute(HttpMethod.GET)); assertEquals(0, child.getChildren().size()); assertNull(route("/hello")); assertEquals(r1, route("/say/hello/to/world")); assertEquals(r1, route("/say/bye/to/Tim")); assertNull(route("/say/bye/bye/to/Tim")); assertEquals(r1, route("/say/bye/to/John/Doe")); assertNull(route("/say/hello/to")); assertEquals(r1, route("/say/hello/to/")); }
Example #29
Source File: ParameterContributor.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private Optional<Operation> getOperation(final Swagger swagger, final HttpMethod httpMethod, final String path) { return Optional.ofNullable(swagger.getPaths()) .orElseGet(Collections::emptyMap) .entrySet().stream() .filter(e -> path.equals(e.getKey())) .findFirst() .map(Entry::getValue) .map(Path::getOperationMap) .map(m -> m.get(httpMethod)); }
Example #30
Source File: OperationDocumentNameResolverTest.java From swagger2markup with Apache License 2.0 | 5 votes |
@Before public void setUp() { String method = HttpMethod.GET.name(); String path = "/test"; operation = new SwaggerPathOperation(method, path, path + " " + method.toLowerCase(), method + " " + path, new Operation()); }