micronaut-openapi icon indicating copy to clipboard operation
micronaut-openapi copied to clipboard

redoc path requires trailing slash to properly resolve .js artifacts

Open dshick-nydig opened this issue 3 years ago • 6 comments

https://github.com/micronaut-projects/micronaut-openapi/blob/78ae9dd5b5fe928a0430efb9e5fafcf2e3e28eb5/openapi/src/main/java/io/micronaut/openapi/view/OpenApiViewConfig.java#L51

https://github.com/micronaut-projects/micronaut-openapi/blob/78ae9dd5b5fe928a0430efb9e5fafcf2e3e28eb5/openapi/src/main/java/io/micronaut/openapi/view/RedocConfig.java#L32

Due to this script tag's src being relative, a URL such as https://service:port/redoc will not load the redoc.standalone.js file correctly as it will look for it in https://service:port/res/redoc.standalone.js rather than https://service:port/redoc/res/redoc.standalone.js. In order to remain irreverent of the trailing slash, the route without the trailing slash should redirect to include it, or the script src should be expanded to be relative only to the TLD, e.g. ...

private static final String DEFAULT_REDOC_JS_PATH = "/" + OpenApiViewConfig.REDOC + "/" + OpenApiViewConfig.RESOURCE_DIR + "/redoc.standalone.js";

dshick-nydig avatar Oct 19 '22 15:10 dshick-nydig

@dshick-nydig Hi! Could you give me simple service example with your configuration? I already fixed something in PR #824 and I need to understand your case, maybe this is solved using the current micronaut-openapi properties.

altro3 avatar Oct 19 '22 20:10 altro3

You can work around this by adding res to your mappings, but this should be either added to the documentation or fixed.

      res:
        paths:
          - classpath:META-INF/swagger/views/swagger-ui/res
          - classpath:META-INF/swagger/views/rapidoc/res
          - classpath:META-INF/swagger/views/redoc/res
        mapping: /res/**

(obviously you don't need all 3, just wanted to include all 3 as an example)

edeesis avatar Oct 21 '22 13:10 edeesis

@dshick-nydig Hi! Could you give me simple service example with your configuration? I already fixed something in PR #824 and I need to understand your case, maybe this is solved using the current micronaut-openapi properties.

Sure, I won't have time until next week, but will do.

dshick-nydig avatar Oct 21 '22 21:10 dshick-nydig

@edeesis Yeah, I agree, need to document it. But I haven't time to it. Just so you understand - I'm not on the micronaut team and I fix bugs simply because I like the project. I would be grateful if you describe this part in the documentation :-)

altro3 avatar Oct 22 '22 15:10 altro3

@altro3 Understood, I share your passion for this project 😄

I do feel like it's a bug because in previous versions of micronaut-openapi, we didn't have to add this additional section to the application.yml file.

edeesis avatar Oct 22 '22 17:10 edeesis

@edeesis no, this is not a bug. This is feature :-). See https://github.com/micronaut-projects/micronaut-openapi/issues/779

altro3 avatar Oct 23 '22 09:10 altro3

Sorry @altro3, I disagree. Before that issue was closed, users could add to the application.yml without having to specify the res folders. Now that they're there (which I think is a good thing), they're not working without additional (unnecessary imo) configuration.

The fix that @dshick-nydig will indeed fix the issue, and I'm happy to put up the PR to fix it.

Here's an example project that reproduces the issue: https://github.com/edeesis/openapi-test

You can also download your own by running the micronaut launch command. mn create-app --build=gradle --jdk=17 --lang=kotlin --test=kotest --features=openapi com.example.openapi-test.

edeesis avatar Oct 23 '22 18:10 edeesis

PR Opened: https://github.com/micronaut-projects/micronaut-openapi/pull/832

edeesis avatar Oct 23 '22 19:10 edeesis

Turns out the fix that @dshick-nydig suggested wasn't enough to work with RapiPDF generation, ended up going with a slightly different approach.

edeesis avatar Oct 23 '22 19:10 edeesis

Turns out the fix that @dshick-nydig suggested wasn't enough to work with RapiPDF generation...

Yeah, figured this issue would be more widespread than just redoc, but only tested what I'm using. Thanks for digging deeper.

dshick-nydig avatar Oct 23 '22 19:10 dshick-nydig

Thanks @edeesis and @altro3!

dshick-nydig avatar Nov 02 '22 13:11 dshick-nydig