-
Notifications
You must be signed in to change notification settings - Fork 236
Description
Hi! My team has noticed that during an OpenAPI conversion, all the mappers in our ClassLoader are applied.
This seems strange to me, because I assumed mappers are protocol-specific. But the implementation takes them all:
smithy/smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/OpenApiConverter.java
Lines 252 to 259 in 48ccceb
private static OpenApiMapper createComposedMapper( | |
List<Smithy2OpenApiExtension> extensions, | |
List<OpenApiMapper> mappers | |
) { | |
return OpenApiMapper.compose(Stream.concat( | |
extensions.stream().flatMap(extension -> extension.getOpenApiMappers().stream()), | |
mappers.stream()).collect(Collectors.toList())); | |
} |
I'm talking about a scenario where config
has a protocol set, meaning loadOrDeriveProtocolTrait
was able to unambiguously derive a protocol trait.
Why this seems problematic: multiple protocols may handle the same trait differently. If they're both on the same classpath, it appears that the mappers of both protocols will be applied, which would result in unpredictable outcomes.
Or, maybe a protocol wants to ignore @jsonName
, and another one has a mapper for that. You get the gist :)
If this was intentional: should there be a config option to only pick up mappers from the protocol that's been found / configured (rather than all protocols on the classpath)?
If this was unintentional: is that something that can be changed in a minor version? Happy to contribute.