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

bugfix: Example json Payload generated as plain value but should be array #486

Merged
Merged
Changes from 4 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
Yauhenikapl marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.xml.datatype.DatatypeFactory;
Expand Down Expand Up @@ -222,8 +223,16 @@ private Map<String, Object> transformCollectionProperty( final BasicProperty pro
final List<Object> collectionValues = getCollectionValues( property, (Collection) characteristic );
return toMap( property.getName(), collectionValues );
} else if ( isConstrainedCollection( characteristic ) ) {
return toMap( property.getName(), getCollectionValues( property, characteristic.as( Trait.class ).getBaseCharacteristic().as( Collection.class ),
(LengthConstraint) characteristic.as( Trait.class ).getConstraints().get( 0 ) ) );

Collection collection = characteristic.as( Trait.class ).getBaseCharacteristic().as( Collection.class );
Yauhenikapl marked this conversation as resolved.
Show resolved Hide resolved

List<Constraint> constraints = characteristic.as( Trait.class ).getConstraints().stream().filter( trait -> trait.is( LengthConstraint.class ) )
.toList();

return !constraints.isEmpty() ?
toMap( property.getName(), getCollectionValues( property, collection,
(LengthConstraint) characteristic.as( Trait.class ).getConstraints().get( 0 ) ) ) :
Yauhenikapl marked this conversation as resolved.
Show resolved Hide resolved
toMap( property.getName(), getCollectionValues( property, collection ) );
}
return ImmutableMap.of();
}
Expand All @@ -233,8 +242,7 @@ private boolean isConstrainedCollection( final Characteristic characteristic ) {
return false;
}
final Trait trait = characteristic.as( Trait.class );
return trait.getBaseCharacteristic().is( Collection.class ) && (trait.getConstraints().size() == 1) &&
trait.getConstraints().get( 0 ).is( LengthConstraint.class );
return trait.getBaseCharacteristic().is( Collection.class ) && (!trait.getConstraints().isEmpty());
}

private Map<String, Object> transformAbstractEntityProperty( final BasicProperty property, final boolean useModelExampleValue ) {
Expand Down