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

Embed and shade needed dependencies to make swagger as self contained utility and not cause version conflicts. #2925

Open
soberich opened this issue Aug 23, 2018 · 3 comments

Comments

@soberich
Copy link

Currently I am unable to use both spring-boot 5.1.0.M1 (with JAX-RS setup) and swagger-core 2.0.3 / swagger-jaxrs2 2.0.3 because swagger declares dependencies for such libraries like snakeyaml which (! think of it) ONLY needed ONCE when the app starts (to be more precise - when you first time access the swagger endpoints) BUT forces whether usage of compatible libraries versions or simply not using 5.1.0.M1 or swagger itself.. which seems very very obligative and tightening. As in this particular case spring boot 5.1.0.M1 uses 1.2+ version of snakeyaml and swagger - 1.18 and they are not compatible.
this would be quiet consistent to embed, repackage them and shade as they are needed for internal usage not to invent the bicycle but right now this regard seems completely out of proper setup as it literally forces a version regardless does one-time job for to generate openapi desc.

P.S. stacktrace

Caused by: java.lang.NoSuchMethodError: org.yaml.snakeyaml.events.MappingStartEvent.<init>(Ljava/lang/String;Ljava/lang/
String;ZLorg/yaml/snakeyaml/error/Mark;Lorg/yaml/snakeyaml/error/Mark;Ljava/lang/Boolean;)V
        at com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.writeStartObject(YAMLGenerator.java:504)
        at com.fasterxml.jackson.core.base.GeneratorBase.writeStartObject(GeneratorBase.java:286)
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:151)
        at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
        at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:31
9)
        at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1396)
        at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:1120)
        at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:993)
        at io.swagger.v3.core.util.Yaml.pretty(Yaml.java:23)
        at io.swagger.v3.jaxrs2.integration.resources.BaseOpenApiResource.getOpenApi(BaseOpenApiResource.java:74)
        at io.swagger.v3.jaxrs2.integration.resources.OpenApiResource.getOpenApi(OpenApiResource.java:32)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
        at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:509)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:399)
        at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$0(ResourceMethodInvoker.java:363)
        at org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.j
ava:361)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:365)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:337)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:310)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:443)
        ... 100 common frames omitted

I would also extend the issue to the fact that it uses Jackson the same way, and the same logic as I expressed above relevant to jackson libraries as well, It already has a certain amount of confusion from users when you have swagger's ObjectMapper which is also "a kind of" configurable but those configurations are not intuatively limited to a subset as only such as naming strategies and some other settings would apply and not serialization/deserialization which are only runtime modifications, of course. But again this is not intuitive. Maybe create a wrapper around Jackson's ObjectMapper and expose just some relevant settings in swagger spesific more descriptive way etc.

  1. embed, repackage them and shade SnakeYaml
    2*. same + wrap with own API for Jackson (ObjectMappers for dataformats (Json and Yaml) as I remember) - this one is not the core of this issue, so less relevant.
@soberich
Copy link
Author

backword compatible constructors were added by @yborovikov in pr
see
FasterXML/jackson-dataformats-text#81

@soberich
Copy link
Author

I see Gradle and Maven plugins released and fits this now! Great! Generation at build time makes all that perfect.

@Randgalt
Copy link

Swagger could produce an alternate shaded dependency (with the shaded classifier) for those that need it. We ended up building one for ourselves internally. It's unfortunate that we have to do it ourselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants