-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Hello,
My use case is that I'm using 1.5.10 with a version of CXF with Jax-RS 1.X. I have two API versions running in the same servlet like so:
<jaxrs:server id="jaxrsRestService" address="/v1">
<jaxrs:serviceBeans>
...
<ref bean="swaggerResource" />
</jaxrs:serviceBeans>
<jaxrs:providers>
...
<ref bean="swaggerSerializers" />
</jaxrs:providers>
</jaxrs:server>
<jaxrs:server id="jaxrsRestService2" address="/v2">
<jaxrs:serviceBeans>
...
<ref bean="swaggerResource" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="swaggerSerializers" />
...
</jaxrs:providers>
</jaxrs:server>
It wasn't clear from the docs if this is a supported configuration because BeanConfig
looks like a Singleton (it's not referenced anywhere, so how do I wire it into just my one jax-rs service?) which would imply it only supports one API:
<bean id="swaggerConfigV1" class="io.swagger.jaxrs.config.BeanConfig">
<property name="resourcePackage" value="com....v1"/>
<property name="version" value="1.0"/>
<property name="basePath" value="/myservice/v1"/>
<property name="title" value="My Service"/>
<property name="description" value="REST API."/>
<property name="scan" value="true"/>
<property name="schemes" value="https,http"/>
</bean>
I eventually found #1656, which adds support for my situation, but the docs at https://github.com/swagger-api/swagger-samples/tree/master/java/java-jersey-jaxrs-multi-use-basepath don't quite work for me because I'm using BeanConfig
, and I'm not on Jersey.
The trick ended up being having two BeanConfigs (as I expected) with
<property name="usePathBasedConfig" value="true"/>
(which is not documented) in addition to
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<init-param>
<param-name>swagger.use.path.based.config</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
in my web.xml (which is documented in the original pull request), but the usePathBasedConfig property of BeanConfig must be set before its scan property! I think this is likely a bug due to setScan
not working like a bean (it's a big function call), but I figure that's not worth changing this late in the life of 1.x.
Ultimately, if the docs at https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-1.X-Project-Setup-1.5#using-swaggers-beanconfig specified that usePathBasedConfig
is an available bean property and needs to go before scan
, and must also be set in the init-param for the servlet I probably would've gotten this working much faster. It doesn't seem possible for me to edit the wiki...
Regards,
Corey