Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Java Client Library (beta)
### v0.3.3
### v0.3.4

## Introduction
Welcome my friends! This is the Poly API Java client GitHub page. If you are here, then it means you're familiar with what we do at Poly. If you aren't, you can always check [here](https://github.com/polyapi/poly-alpha).
Expand Down Expand Up @@ -347,6 +347,8 @@ Comparing to its Typescript counterpart, the Java library is still missing the f
These features will be added in the future releases.

## Changelog
### v0.3.4
- Added validation to avoid duplicate specifications based on context and name.
### v0.3.3
- Fixed 'type' property for Server variables
- Added missing 'type' property to specs.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.fasterxml.jackson.databind.type.TypeFactory.defaultInstance;
import static java.lang.String.format;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.joining;

public class SpecificationServiceImpl extends PolyApiService implements SpecificationService {
Expand All @@ -25,8 +31,19 @@ public List<Specification> getJsonSpecs() {
List<Specification> specifications = get("specs", defaultInstance().constructCollectionType(List.class, Specification.class));
logger.info("{} specifications retrieved.", specifications.size());
if (logger.isDebugEnabled()) {
logger.trace("Retrieved specifications the following IDs: [{}]", specifications.stream().map(Specification::getId).collect(joining(", ")));
logger.trace("Retrieved specifications with the following IDs: [{}]", specifications.stream().map(Specification::getId).collect(joining(", ")));
}
return specifications;
logger.debug("Validating for duplicate context/name pairs.");
Map<String, Specification> uniquenessValidationMap = new HashMap<>();
specifications.forEach(specification -> {
String key = format("%s.%s", specification.getContext(), specification.getName());
if (uniquenessValidationMap.containsKey(key)) {
logger.warn("Skipping {} specification '{}' in context '{}' as it clashes with {} specification with the same name and context.", specification.getType(), specification.getName(), specification.getContext(), uniquenessValidationMap.get(key).getType());
} else {
logger.debug("Specification key '{}' not repeated (yet).", key);
uniquenessValidationMap.put(key, specification);
}
});
return uniquenessValidationMap.values().stream().toList();
}
}