OK, progress... Yes, I had an auto-scan set on 'org.apache.cxf.jaxrs.swagger'
in my Spring Boot application.yaml. I removed it, and also removed the
setBasePath.  I'm down to this:


 @Bean
    public Swagger2Feature swagger2Feature() {
        Swagger2Feature feature = new Swagger2Feature();
        feature.setResourcePackage("x.y.z.v1.rs");
        feature.setTitle("My API");
        return feature;
    }

which is quite nice.   All the server-side errors are gone, and only one
endpoint in the service list:

Available RESTful services:
Endpoint address: http://localhost:8080/context/
Swagger : http://localhost:8080/context/api-docs?url=/context/swagger.json

However, I'm still seeing a bunch of errors in my browser console on the
client side when I go to that URL, all like this:

Refused to execute script from '
http://localhost:8080/context/lib/shred.bundle.js' because its MIME type
('application/octet-stream') is not executable, and strict MIME type
checking is enabled.

So close!



On Tue, Aug 16, 2016 at 11:57 AM, Sergey Beryozkin [via CXF] <
ml-node+s547215n5771639...@n5.nabble.com> wrote:

> Can you check you have no SpringBoot configuration scanning
> 'org.apache.cxf.jaxrs.swagger' - the CXF demo does it and picks up
> Swagger2Feature automatically - that will explain these warnings.
>
> Can you also remove
> feature.setBasePath("/api-docs") ?
>
> FYI, Swagger UI resource does listen on this path but this will be
> configurable.
>
> Cheers, Sergey
>
> On 16/08/16 16:35, jcrump wrote:
>
> >
> > Yes, I am using a SpringBoot starter.  So I took out the @Bean code and
> > replaced it with this:
> >
> > @Bean
> > public Swagger2Feature swagger2Feature() {
> >    Swagger2Feature feature = new Swagger2Feature();
> >    feature.setResourcePackage("x.y.z.v1.rs");
> >    feature.setTitle("My API");
> >    feature.setBasePath("/api-docs");
> >    return feature;
> > }
> >
> > The JSON is being generated correctly and I'm only seeing one endpoint
> on
> > the services list:
> >
> > Available RESTful services:
> > Endpoint address: http://localhost:8080/context/
> > Swagger : http://localhost:8080/context/api-docs?url=/context/swagger.
> json
> >
> > When I click on the link, I get the Swagger UI but with no content.  I
> get a
> > whole bunch of messages like this:
> >
> > WARNING: Both
> > org.apache.cxf.jaxrs.swagger.Swagger2Feature$SwaggerUIService#getResource
>
> > and
> > org.apache.cxf.jaxrs.swagger.Swagger2Feature$SwaggerUIService#getResource
>
> > are equal candidates for handling the current request which can lead to
> > unpredictable results
> >
> > and a FileNotFoundException:
> >
> > Caused by: java.io.FileNotFoundException: JAR entry
> > META-INF/resources/webjars/swagger-ui/2.1.8-M1/api-docs/lib/swagger-oauth.js
>
> > not found in
> > /Users/jcrump/.m2/repository/org/webjars/swagger-ui/2.1.8-M1/swagger-ui-2.1.8-M1.jar
>
> > at
> > sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:142)
>
> >
> >
> > The problem is the "api-docs" in the META-INF path.  I traced this in
> the
> > debugger to Swagger2Feature.SwaggerUIService#getResource; the
> resourcePath
> > being passed in is prefixed with api-docs whereas the jar entry path is
> not.
> > I tried removing the 'setBasePath' call in my @Bean method but it didn't
> > change anything.
> >
> > BTW, I'm also getting the warning message when called to generate the
> JSON,
> > but the warning is this:
> >
> > WARNING: Both io.swagger.jaxrs.listing.ApiListingResource#getListing
> and
> > io.swagger.jaxrs.listing.ApiListingResource#getListing are equal
> candidates
> > for handling the current request which can lead to unpredictable results
> >
> > Same warning but different class. Sounds like a configuration or
> classpath
> > thing, but I couldn't detect any libraries duplicated on my classpath.
> >
> > Thanks.
> >
> >
> >> Thanks for making it work so far.
> >>
> >> The question is, where is the first endpoint coming from, or rather why
> >> do you see two endpoints as opposed to the one you create ?
> >>
> >> Do use a SpringBoot starter with the auto-scan enabled ? That may
> create
> >> the endpoint at the "/" address (note for me - make sure this is also
> >> configurable in the auto-scan case)
> >>
> >> I'll need to sign off now as it is getting late but please try to get
> >> the only endpoint shown first and then we'll see what happens.
> >>
> >> FYI, if you use the auto-scan then you can usually remove all the code
> >> below but only keep a @Bean code returning Swagger2Feature because it
> is
> >> configured, would not be needed otherwise (another note to myself - how
> >> to auto-configure Swagger2Feature in SpringBoot given that
> >> Swagger2Feature can be used without Spring too)
> >
> >
> >
> >
> >
> > --
> > View this message in context: http://cxf.547215.n5.nabble.
> com/Swagger2Feature-not-finding-Api-annotations-in-
> interfaces-tp5771115p5771637.html
> > Sent from the cxf-user mailing list archive at Nabble.com.
> >
>
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://cxf.547215.n5.nabble.com/Swagger2Feature-not-
> finding-Api-annotations-in-interfaces-tp5771115p5771639.html
> To unsubscribe from Swagger2Feature not finding @Api annotations in
> interfaces, click here
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5771115&code=amNydW1wQGNvbnN0YW50Y29udGFjdC5jb218NTc3MTExNXwtMTU1OTE5MTQ3NA==>
> .
> NAML
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: 
http://cxf.547215.n5.nabble.com/Swagger2Feature-not-finding-Api-annotations-in-interfaces-tp5771115p5771644.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to