Skip to content

OpenAPI: all OpenApiMappers in scope are used, even if they don't apply to the protocol #2668

@kubukoz

Description

@kubukoz

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions