Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer scrubTraitDefinitions for JsonSchema #2435

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.logging.Logger;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -60,24 +61,30 @@ final class DeconflictingStrategy implements RefStrategy {
// to make the result deterministic. Eliminate trait definitions
// ahead of that computation to eliminate potential conflicts with
// shapes that won't go into JSON Schema anyway.
Model scrubbedModel = ModelTransformer.create().scrubTraitDefinitions(model);
scrubbedModel.shapes()
.filter(shapePredicate.and(FunctionalUtils.not(this::isIgnoredShape)))
.sorted()
.forEach(shape -> {
Model scrubbedModel = null;
for (Shape shape : new TreeSet<>(model.toSet())) {
if (!shapePredicate.and(FunctionalUtils.not(this::isIgnoredShape)).test(shape)) {
continue;
}

String pointer = delegate.toPointer(shape.getId());
if (!reversePointers.containsKey(pointer)) {
pointers.put(shape.getId(), pointer);
reversePointers.put(pointer, shape.getId());
} else {
String deconflictedPointer = deconflict(shape, pointer, reversePointers);
LOGGER.info(() -> String.format(
"De-conflicted `%s` JSON schema pointer from `%s` to `%s`",
shape.getId(), pointer, deconflictedPointer));
pointers.put(shape.getId(), deconflictedPointer);
reversePointers.put(deconflictedPointer, shape.getId());
if (scrubbedModel == null) {
scrubbedModel = ModelTransformer.create().scrubTraitDefinitions(model);
}
if (scrubbedModel.getShape(reversePointers.get(pointer)).isPresent()) {
String deconflictedPointer = deconflict(shape, pointer, reversePointers);
LOGGER.info(() -> String.format(
"De-conflicted `%s` JSON schema pointer from `%s` to `%s`",
shape.getId(), pointer, deconflictedPointer));
pointers.put(shape.getId(), deconflictedPointer);
reversePointers.put(deconflictedPointer, shape.getId());
}
}
});
}
}

// Some shapes aren't converted to JSON schema at all because they
Expand Down
Loading