.orElseGet(() -> { Path path = new Path(); swagger.path(pattern, path); return path; });
protected void addOperationToSwagger() { if (StringUtils.isEmpty(httpMethod)) { return; } Path pathObj = swagger.getPath(path); if (pathObj == null) { pathObj = new Path(); swagger.path(path, pathObj); } HttpMethod hm = HttpMethod.valueOf(httpMethod.toUpperCase(Locale.US)); if (pathObj.getOperationMap().get(hm) != null) { throw new Error(String.format("Only allowed one default path. %s:%s", swaggerGenerator.getCls().getName(), providerMethod.getName())); } pathObj.set(httpMethod, operation); } }
protected void updatePath(String operationPath, String httpMethod, Operation operation) { if (httpMethod == null) { return; } Path path = swagger.getPath(operationPath); if (path == null) { path = new Path(); swagger.path(operationPath, path); } path.set(httpMethod, operation); }
private void addIndividualPath(String resourceParentName, String resourceName, Path path, String pathSuffix) { if (!path.getOperations().isEmpty()) { if (resourceParentName == null) { swagger.path("/" + resourceName + pathSuffix, path); } else { swagger.path("/" + resourceParentName + "/{parent-uuid}/" + resourceName + pathSuffix, path); } } }
private void addFactory(String uri, ServiceDocument doc) { this.swagger.path(uri, path2Factory(doc)); if (!this.excludeUtilities) { this.swagger.path(uri + ServiceHost.SERVICE_URI_SUFFIX_STATS, path2UtilStats(null)); this.swagger.path(uri + ServiceHost.SERVICE_URI_SUFFIX_CONFIG, path2UtilConfig(null)); this.swagger.path(uri + ServiceHost.SERVICE_URI_SUFFIX_SUBSCRIPTIONS, path2UtilSubscriptions(null)); this.swagger .path(uri + ServiceHost.SERVICE_URI_SUFFIX_TEMPLATE, path2UtilTemplate(null)); this.swagger .path(uri + ServiceHost.SERVICE_URI_SUFFIX_AVAILABLE, path2UtilAvailable(null)); } Parameter idParam = paramId(); this.swagger.path(uri + PREFIX_ID, path2Instance(doc)); if (!this.excludeUtilities) { this.swagger.path(uri + PREFIX_ID + ServiceHost.SERVICE_URI_SUFFIX_STATS, path2UtilStats(idParam)); this.swagger.path(uri + PREFIX_ID + ServiceHost.SERVICE_URI_SUFFIX_CONFIG, path2UtilConfig(idParam)); this.swagger.path(uri + PREFIX_ID + ServiceHost.SERVICE_URI_SUFFIX_SUBSCRIPTIONS, path2UtilSubscriptions(idParam)); this.swagger.path(uri + PREFIX_ID + ServiceHost.SERVICE_URI_SUFFIX_TEMPLATE, path2UtilTemplate(idParam)); this.swagger.path(uri + PREFIX_ID + ServiceHost.SERVICE_URI_SUFFIX_AVAILABLE, path2UtilAvailable(idParam)); } }
private void addOperation(String uri, Operation op) { ServiceDocumentQueryResult q = op.getBody(ServiceDocumentQueryResult.class); if (q.documents != null) { Object firstDoc = q.documents.values().iterator().next(); addFactory(uri, Utils.fromJson(firstDoc, ServiceDocument.class)); this.swagger.addTag(this.currentTag); } else if (q.documentDescription != null && q.documentDescription.serviceRequestRoutes != null && !q.documentDescription.serviceRequestRoutes.isEmpty()) { this.swagger .path(uri, pathByRoutes(q.documentDescription.serviceRequestRoutes.values())); this.swagger.addTag(this.currentTag); } }
protected void addOperationToSwagger() { if (StringUtils.isEmpty(httpMethod)) { return; } Path pathObj = swagger.getPath(path); if (pathObj == null) { pathObj = new Path(); swagger.path(path, pathObj); } HttpMethod hm = HttpMethod.valueOf(httpMethod.toUpperCase(Locale.US)); if (pathObj.getOperationMap().get(hm) != null) { throw new Error(String.format("Only allowed one default path. %s:%s", swaggerGenerator.getCls().getName(), providerMethod.getName())); } pathObj.set(httpMethod, operation); } }
public ExOperation mkOperation(HttpMethod method, String path) { notEmpty(path, "'path' CAN'T be null or empty!!!"); notEmpty(method, "'method' CAN'T be null or empty!!!"); synchronized (swagger) { String origPath = path; path = path.replaceAll("<[^>]+>", "").replaceAll("/:([^/]+)", "/{$1}"); // replace `/:id<[0-9]+>` with `/{id}` if (swagger.getPath(path) == null) { logger.info(">>> adding path - '" + path + "'"); swagger.path(path, new Path()); } Path pathObj = swagger.getPath(path); if (pathObj.getOperationMap().get(method) != null) { throw new IllegalArgumentException("DUPLICATED operation - " + method + " '" + path + "'"); } logger.info(">>> adding operation - " + method + " '" + path + "'"); pathObj.set(method.name().toLowerCase(), new ExOperation(this, method, path)); implemented.put(entry(method, path), true); // set implemented by default String prevPath = origPaths.put(entry(method, path), origPath); if (prevPath != null) throw new IllegalArgumentException( "`" + path + "` was repeatedly defined by `" + prevPath + "` and `" + origPath + "`!!!"); return (ExOperation) pathObj.getOperationMap().get(method); } }
throw new UnsupportedOperationException("Unsupported method type " + methodType); swagger.path(key, path);
throw new UnsupportedOperationException("Unsupported method type " + methodType); swagger.path(key, path);
this.swagger.path(path, new io.swagger.models.Path());
@Test public void shouldMakeNonUniqueOperationIdsUnique() { final Swagger swagger = new Swagger().path("/path", new Path().get(new Operation().operationId("foo")) .post(new Operation().operationId("foo")).put(new Operation().operationId("bar"))); final Connector generated = generator.configureConnector(SWAGGER_TEMPLATE, new Connector.Builder().id("connector1").build(), createSettingsFrom(swagger)); final List<ConnectorAction> actions = generated.getActions(); assertThat(actions).hasSize(3); assertThat(actions.get(0).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("foo")); assertThat(actions.get(1).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("foo1")); assertThat(actions.get(2).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("bar")); }
@Test public void shouldMakeNonUniqueOperationIdsUnique() { final Swagger swagger = new Swagger().path("/path", new Path().get(new Operation().operationId("foo")) .post(new Operation().operationId("foo")).put(new Operation().operationId("bar"))); final Connector generated = generator.configureConnector(SWAGGER_TEMPLATE, new Connector.Builder().id("connector1").build(), createSettingsFrom(swagger)); final List<ConnectorAction> actions = generated.getActions(); assertThat(actions).hasSize(3); assertThat(actions.get(0).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("foo")); assertThat(actions.get(1).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("foo1")); assertThat(actions.get(2).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("bar")); }
if (path == null) { path = new SwaggerPath(); swagger.path(parsedPath, path);
@Test public void shouldValidateOperationUniqueness() { final Swagger swagger = new Swagger() .path("/path", new Path().get(new Operation().operationId("o1")).post(new Operation().operationId("o2"))) .path("/other", new Path().patch(new Operation().operationId("o2")).put(new Operation().operationId("o3"))) .path("/more", new Path().options(new Operation().operationId("o4")).delete(new Operation().operationId("o3"))); final SwaggerModelInfo info = new SwaggerModelInfo.Builder().model(swagger).build(); final SwaggerModelInfo validated = SyndesisSwaggerValidationRules.validateUniqueOperationIds(info); final List<Violation> warnings = validated.getWarnings(); assertThat(warnings).hasSize(1); final Violation nonUniqueWarning = warnings.get(0); assertThat(nonUniqueWarning.error()).isEqualTo("non-unique-operation-ids"); assertThat(nonUniqueWarning.property()).isNull(); assertThat(nonUniqueWarning.message()).isEqualTo("Found operations with non unique operationIds: o2, o3"); } }
@Test public void shouldValidateOperationUniqueness() { final Swagger swagger = new Swagger() .path("/path", new Path().get(new Operation().operationId("o1")).post(new Operation().operationId("o2"))) .path("/other", new Path().patch(new Operation().operationId("o2")).put(new Operation().operationId("o3"))) .path("/more", new Path().options(new Operation().operationId("o4")).delete(new Operation().operationId("o3"))); final SwaggerModelInfo info = new SwaggerModelInfo.Builder().model(swagger).build(); final SwaggerModelInfo validated = SyndesisSwaggerValidationRules.validateUniqueOperationIds(info); final List<Violation> warnings = validated.getWarnings(); assertThat(warnings).hasSize(1); final Violation nonUniqueWarning = warnings.get(0); assertThat(nonUniqueWarning.error()).isEqualTo("non-unique-operation-ids"); assertThat(nonUniqueWarning.property()).isNull(); assertThat(nonUniqueWarning.message()).isEqualTo("Found operations with non unique operationIds: o2, o3"); } }
@Test public void shouldNormalizeSwaggerBasePaths() { final Swagger swagger = new Swagger().path("/path", new Path().get(new Operation())); assertThat(ProjectGeneratorHelper.normalizePaths(swagger).getPaths()).containsOnlyKeys("/path"); assertThat(ProjectGeneratorHelper.normalizePaths(swagger.basePath("/api")).getPaths()).containsOnlyKeys("/api/path"); } }
public SwaggerHelperOperationDescriptionGenerationTest(final String operationSummary, final String operationDescription, final String expectedName, final String expectedDescription) { operation = new Operation().description(operationDescription).summary(operationSummary); swagger = new Swagger().path("/test", new Path().get(operation)); expected = new OperationDescription(expectedName, expectedDescription); }
public SwaggerHelperOperationDescriptionGenerationTest(final String operationSummary, final String operationDescription, final String expectedName, final String expectedDescription) { operation = new Operation().description(operationDescription).summary(operationSummary); swagger = new Swagger().path("/test", new Path().get(operation)); expected = new OperationDescription(expectedName, expectedDescription); }