swagger-core
swagger-core copied to clipboard
Embed and shade needed dependencies to make swagger as self contained utility and not cause version conflicts.
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.
- embed, repackage them and shade
SnakeYaml
2*. same + wrap with own API forJackson
(ObjectMapper
s for dataformats (Json
andYaml
) as I remember) - this one is not the core of this issue, so less relevant.
backword compatible constructors were added by @yborovikov in pr see https://github.com/FasterXML/jackson-dataformats-text/issues/81
I see Gradle and Maven plugins released and fits this now! Great! Generation at build time makes all that perfect.
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.