osgi-jax-rs-connector icon indicating copy to clipboard operation
osgi-jax-rs-connector copied to clipboard

swagger.json is missing basePath property from Swagger Configuration

Open grgshfr opened this issue 8 years ago • 12 comments

We are noticing that swagger.json lacks the basePath property in addition to other properties from the configuration. We have used a bundle activator and see that the settings are set properly in the OSGI configuration under the services PID for com.eclipsesource.jaxrs.swagger.config. All bundles are activated as required.

This is leading to the "Try it Out" button not working in Swagger UI.

We are implementing this in Apache Felix.

We are using the following:

<dependency>
    <groupId>com.eclipsesource.jaxrs</groupId>
    <artifactId>swagger-all</artifactId>
    <version>1.5.7</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.eclipsesource.jaxrs</groupId>
    <artifactId>publisher</artifactId>
    <version>5.3.1</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.eclipsesource.jaxrs</groupId>
    <artifactId>jersey-all</artifactId>
    <version>2.22.2</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.eclipsesource.jaxrs</groupId>
    <artifactId>provider-swagger</artifactId>
    <version>1.1.1</version>
    <scope>provided</scope>
</dependency>

grgshfr avatar Mar 08 '16 19:03 grgshfr

hmm, sounds weird. See here: https://github.com/hstaudacher/osgi-jax-rs-connector/blob/master/bundles/com.eclipsesource.jaxrs.provider.swagger/src/com/eclipsesource/jaxrs/provider/swagger/internal/OSGiJaxRsScanner.java#L47

The base path is set form the config.

hstaudacher avatar Mar 09 '16 06:03 hstaudacher

@hstaudacher we added the config for the PID, and made sure it loaded correctly in the OSGi, but the swagger.json file doesn't show the basePath value. We applied the config by editing in the Felix console, and also by entering it in via the bundle activator, and it does not show the basePath in the JSON.

bearcherian avatar Mar 09 '16 17:03 bearcherian

I can confirm that the swagger configuration parameters never get applied.

Digging a bit into the source I found that the "updated" method of the SwaggerConfiguration class does get called with the proper dictionary. However the "configure" method of OSGiJaxRsScanner never gets called.

ctron avatar Jun 09 '16 11:06 ctron

I just found a workaround, at least for the "swagger.info" part. It is possible to add a @SwaggerDefinition annotation to any service registered with the OSGi connector. This gets picked up by swagger.

ctron avatar Jun 09 '16 12:06 ctron

Spent days on this before giving up and deciding to generate an issue. Turns out I should have checked here earlier in the process to save some time. I am encountering the same bug and can confirm ctron's workaround does indeed work. +1 to get this fixed. Thank you!

jmacauley avatar Jun 20 '16 19:06 jmacauley

@hstaudacher Are you going to be able to look at this?

BryanHunt avatar Aug 01 '16 17:08 BryanHunt

I've got the same issue. Digging around a bit, this is what I currently find.

The activator calls io.swagger.config.ScannerFactory.setScanner. However the corresponding getScanner method never gets called.

Stepping through the swagger code, if goes into SwaggerContextService.getScanner, which calls SwaggerScannerLocator,getScanner. Only if that returns null does it then fall back to ScannerFactory.getScanner(). However, SwaggerScannerLocator,getScanner, as a fallback, returns new DefaultJaxrsScanner(), and never returns null. So we end up not using the OSGiJaxRsScanner class, which is the thing that applies the configuration.

So a fix is to change the Activator so that it does:

    SwaggerScannerLocator.getInstance().putScanner("swagger.scanner.id.default", new OSGiJaxRsScanner(swaggerConfiguration));

instead of

    ScannerFactory.setScanner(new OSGiJaxRsScanner(swaggerConfiguration));

Now I class this as a bit of a hack at the moment, since I don't really know were the "swagger.scanner.id.default" value comes from. However it does cause the configuration to be applied.

tomq42 avatar Aug 08 '16 14:08 tomq42

@hstaudacher @BryanHunt Is there a plan to incorporate the fix for this issue anytime soon?

madhugarimilla avatar Feb 23 '17 17:02 madhugarimilla

@hstaudacher Could you please quote whether you are still actively maintaining this project and considering pull requests? Thank you very much!

col-panic avatar Mar 12 '17 21:03 col-panic

I'm working toward maintaining this project. I'll work on pull requests once #181 is complete. Things are going a bit slow right now because I have other higher priority side projects (I can only work on this in my free time).

BryanHunt avatar Mar 12 '17 21:03 BryanHunt

Thank you @BryanHunt for clarifying this! 👍

col-panic avatar Mar 12 '17 21:03 col-panic

I just could verify, that the provided patch from xeagle2 works for me. I pulled it into my upgraded fork on https://github.com/MEDEVIT/osgi-jax-rs-connector

col-panic avatar Dec 11 '17 13:12 col-panic