@Test public void testAllFilterParameters() throws Exception { Info info = new Info() .title("Test Service"); SwaggerBuilder builder = new SwaggerBuilder(dictionary, info); Swagger swagger = builder.build(); Operation op = swagger.getPaths().get("/book").getGet(); List<String> paramNames = op.getParameters().stream() .filter(param -> param.getName().startsWith("filter")) .map(Parameter::getName) .sorted() .collect(Collectors.toList()); List<String> expectedNames = Arrays.asList("filter", "filter[book.title][ge]", "filter[book.title][gt]", "filter[book.title][in]", "filter[book.title][infix]", "filter[book.title][isnull]", "filter[book.title][le]", "filter[book.title][lt]", "filter[book.title][not]", "filter[book.title][notnull]", "filter[book.title][postfix]", "filter[book.title][prefix]", "filter[book.year][ge]", "filter[book.year][gt]", "filter[book.year][in]", "filter[book.year][infix]", "filter[book.year][isnull]", "filter[book.year][le]", "filter[book.year][lt]", "filter[book.year][not]", "filter[book.year][notnull]", "filter[book.year][postfix]", "filter[book.year][prefix]", "filter[book]"); assertEquals(expectedNames, paramNames); }
public Swagger build() { ModelConverters converters = ModelConverters.getInstance(); converters.addConverter(new JsonApiModelResolver(dictionary)); if (allClasses.isEmpty()) { allClasses = dictionary.getBindings(); } else { allClasses = Sets.intersection(dictionary.getBindings(), allClasses); if (allClasses.isEmpty()) { throw new IllegalArgumentException("None of the provided classes are exported by Elide"); } } Map<String, Model> models = new HashMap<>(); for (Class<?> clazz : allClasses) { models.putAll(converters.readAll(clazz)); } swagger.setDefinitions(models); rootClasses = allClasses.stream() .filter(dictionary::isRoot) .collect(Collectors.toSet()); Set<PathMetaData> pathData = rootClasses.stream() .map(this::find) .flatMap(Collection::stream) .collect(Collectors.toSet()); Set<PathMetaData> toRemove = new HashSet<>(); for (PathMetaData path : pathData) { for (PathMetaData compare : pathData) { if (path.equals(compare) || compare.lineage.isEmpty()) { continue; } if (compare.shorterThan(path)) { toRemove.add(path); break; } } } pathData = Sets.difference(pathData, toRemove); for (PathMetaData pathDatum : pathData) { swagger.path(pathDatum.getCollectionUrl(), pathDatum.getCollectionPath()); swagger.path(pathDatum.getInstanceUrl(), pathDatum.getInstancePath()); if (! pathDatum.lineage.isEmpty()) { swagger.path(pathDatum.getRelationshipUrl(), pathDatum.getRelationshipPath()); } } List<Tag> tags = allClasses.stream() .map((clazz) -> dictionary.getJsonAliasFor(clazz)) .map((alias) -> new Tag().name(alias)) .collect(Collectors.toList()); swagger.tags(tags); return swagger; }
SwaggerBuilder { public Swagger build() { ModelConverters converters = ModelConverters.getInstance(); converters.addConverter(new JsonApiModelResolver(dictionary)); if (allClasses.isEmpty()) { allClasses = dictionary.getBindings(); } else { allClasses = Sets.intersection(dictionary.getBindings(), allClasses); if (allClasses.isEmpty()) { throw new IllegalArgumentException("None of the provided classes are exported by Elide"); } } Map<String, Model> models = new HashMap<>(); for (Class<?> clazz : allClasses) { models.putAll(converters.readAll(clazz)); } swagger.setDefinitions(models); rootClasses = allClasses.stream() .filter(dictionary::isRoot) .collect(Collectors.toSet()); Set<PathMetaData> pathData = rootClasses.stream() .map(this::find) .flatMap(Collection::stream) .collect(Collectors.toSet()); Set<PathMetaData> toRemove = new HashSet<>(); for (PathMetaData path : pathData) { for (PathMetaData compare : pathData) { if (path.equals(compare) || compare.lineage.isEmpty()) { continue; } if (compare.shorterThan(path)) { toRemove.add(path); break; } } } pathData = Sets.difference(pathData, toRemove); for (PathMetaData pathDatum : pathData) { swagger.path(pathDatum.getCollectionUrl(), pathDatum.getCollectionPath()); swagger.path(pathDatum.getInstanceUrl(), pathDatum.getInstancePath()); if (! pathDatum.lineage.isEmpty()) { swagger.path(pathDatum.getRelationshipUrl(), pathDatum.getRelationshipPath()); } } List<Tag> tags = allClasses.stream() .map((clazz) -> dictionary.getJsonAliasFor(clazz)) .map((alias) -> new Tag().name(alias)) .collect(Collectors.toList()); swagger.tags(tags); return swagger; } }
SwaggerBuilder { public Swagger build() { ModelConverters converters = ModelConverters.getInstance(); converters.addConverter(new JsonApiModelResolver(dictionary)); if (allClasses.isEmpty()) { allClasses = dictionary.getBindings(); } else { allClasses = Sets.intersection(dictionary.getBindings(), allClasses); if (allClasses.isEmpty()) { throw new IllegalArgumentException("None of the provided classes are exported by Elide"); } } Map<String, Model> models = new HashMap<>(); for (Class<?> clazz : allClasses) { models.putAll(converters.readAll(clazz)); } swagger.setDefinitions(models); rootClasses = allClasses.stream() .filter(dictionary::isRoot) .collect(Collectors.toSet()); Set<PathMetaData> pathData = rootClasses.stream() .map(this::find) .flatMap(Collection::stream) .collect(Collectors.toSet()); Set<PathMetaData> toRemove = new HashSet<>(); for (PathMetaData path : pathData) { for (PathMetaData compare : pathData) { if (path.equals(compare) || compare.lineage.isEmpty()) { continue; } if (compare.shorterThan(path)) { toRemove.add(path); break; } } } pathData = Sets.difference(pathData, toRemove); for (PathMetaData pathDatum : pathData) { swagger.path(pathDatum.getCollectionUrl(), pathDatum.getCollectionPath()); swagger.path(pathDatum.getInstanceUrl(), pathDatum.getInstancePath()); if (! pathDatum.lineage.isEmpty()) { swagger.path(pathDatum.getRelationshipUrl(), pathDatum.getRelationshipPath()); } } List<Tag> tags = allClasses.stream() .map((clazz) -> dictionary.getJsonAliasFor(clazz)) .map((alias) -> new Tag().name(alias)) .collect(Collectors.toList()); swagger.tags(tags); return swagger; } SwaggerBuilder(EntityDictionary dictionary, Info info); }
SwaggerBuilder { public Swagger build() { ModelConverters converters = ModelConverters.getInstance(); converters.addConverter(new JsonApiModelResolver(dictionary)); if (allClasses.isEmpty()) { allClasses = dictionary.getBindings(); } else { allClasses = Sets.intersection(dictionary.getBindings(), allClasses); if (allClasses.isEmpty()) { throw new IllegalArgumentException("None of the provided classes are exported by Elide"); } } Map<String, Model> models = new HashMap<>(); for (Class<?> clazz : allClasses) { models.putAll(converters.readAll(clazz)); } swagger.setDefinitions(models); rootClasses = allClasses.stream() .filter(dictionary::isRoot) .collect(Collectors.toSet()); Set<PathMetaData> pathData = rootClasses.stream() .map(this::find) .flatMap(Collection::stream) .collect(Collectors.toSet()); Set<PathMetaData> toRemove = new HashSet<>(); for (PathMetaData path : pathData) { for (PathMetaData compare : pathData) { if (path.equals(compare) || compare.lineage.isEmpty()) { continue; } if (compare.shorterThan(path)) { toRemove.add(path); break; } } } pathData = Sets.difference(pathData, toRemove); for (PathMetaData pathDatum : pathData) { swagger.path(pathDatum.getCollectionUrl(), pathDatum.getCollectionPath()); swagger.path(pathDatum.getInstanceUrl(), pathDatum.getInstancePath()); if (! pathDatum.lineage.isEmpty()) { swagger.path(pathDatum.getRelationshipUrl(), pathDatum.getRelationshipPath()); } } List<Tag> tags = allClasses.stream() .map((clazz) -> dictionary.getJsonAliasFor(clazz)) .map((alias) -> new Tag().name(alias)) .collect(Collectors.toList()); swagger.tags(tags); return swagger; } SwaggerBuilder(EntityDictionary dictionary, Info info); SwaggerBuilder withGlobalResponse(int code, Response response); SwaggerBuilder withLegacyFilterDialect(boolean enableLegacyDialect); SwaggerBuilder withRSQLFilterDialect(boolean enableRSQLDialect); SwaggerBuilder withGlobalParameter(Parameter param); SwaggerBuilder withExplicitClassList(Set<Class<?>> classes); SwaggerBuilder withFilterOps(Set<Operator> ops); Swagger build(); static String getDocument(Swagger swagger); }
SwaggerBuilder { public Swagger build() { ModelConverters converters = ModelConverters.getInstance(); converters.addConverter(new JsonApiModelResolver(dictionary)); if (allClasses.isEmpty()) { allClasses = dictionary.getBindings(); } else { allClasses = Sets.intersection(dictionary.getBindings(), allClasses); if (allClasses.isEmpty()) { throw new IllegalArgumentException("None of the provided classes are exported by Elide"); } } Map<String, Model> models = new HashMap<>(); for (Class<?> clazz : allClasses) { models.putAll(converters.readAll(clazz)); } swagger.setDefinitions(models); rootClasses = allClasses.stream() .filter(dictionary::isRoot) .collect(Collectors.toSet()); Set<PathMetaData> pathData = rootClasses.stream() .map(this::find) .flatMap(Collection::stream) .collect(Collectors.toSet()); Set<PathMetaData> toRemove = new HashSet<>(); for (PathMetaData path : pathData) { for (PathMetaData compare : pathData) { if (path.equals(compare) || compare.lineage.isEmpty()) { continue; } if (compare.shorterThan(path)) { toRemove.add(path); break; } } } pathData = Sets.difference(pathData, toRemove); for (PathMetaData pathDatum : pathData) { swagger.path(pathDatum.getCollectionUrl(), pathDatum.getCollectionPath()); swagger.path(pathDatum.getInstanceUrl(), pathDatum.getInstancePath()); if (! pathDatum.lineage.isEmpty()) { swagger.path(pathDatum.getRelationshipUrl(), pathDatum.getRelationshipPath()); } } List<Tag> tags = allClasses.stream() .map((clazz) -> dictionary.getJsonAliasFor(clazz)) .map((alias) -> new Tag().name(alias)) .collect(Collectors.toList()); swagger.tags(tags); return swagger; } SwaggerBuilder(EntityDictionary dictionary, Info info); SwaggerBuilder withGlobalResponse(int code, Response response); SwaggerBuilder withLegacyFilterDialect(boolean enableLegacyDialect); SwaggerBuilder withRSQLFilterDialect(boolean enableRSQLDialect); SwaggerBuilder withGlobalParameter(Parameter param); SwaggerBuilder withExplicitClassList(Set<Class<?>> classes); SwaggerBuilder withFilterOps(Set<Operator> ops); Swagger build(); static String getDocument(Swagger swagger); static final Response UNAUTHORIZED_RESPONSE; static final Response FORBIDDEN_RESPONSE; static final Response NOT_FOUND_RESPONSE; static final Response REQUEST_TIMEOUT_RESPONSE; static final Response TOO_MANY_REQUESTS_RESPONSE; }