mkdocs-render-swagger-plugin icon indicating copy to clipboard operation
mkdocs-render-swagger-plugin copied to clipboard

Swagger file in relative path

Open miquelis opened this issue 3 years ago • 2 comments

I am having difficulty adding the Swagger file when it is in another directory. The plugin only recognizes the file when it is in the same directory as the file.md

Example of my structure

project
│   test.md
│
└───assets
│   │   └───swagger
│   │       |  openapi.json

image

Attempts to add openapi.json:

  • ./assets/swagger/openapi.json
  • /assets/swagger/openapi.json
  • assets/swagger/openapi.json

miquelis avatar May 28 '22 00:05 miquelis

@miquelis I created another MkDocs plugin to render Swagger UI https://github.com/blueswen/mkdocs-swagger-ui-tag. Which could include OpenAPI Spec file cross directories like include image in MkDocs. Maybe my plugin could fit your requirement.

blueswen avatar Jun 21 '22 15:06 blueswen

As written in the docs:

Place an OpenAPI json file in the same folder as the .md file.

That's actually a security feature, to prevent LFI/RFI attacks. We don't want someone to write ../../../../etc/passwd would we 😉

While we have the !!swagger-http!! to compensate, adding a config option to disable the security and allow accessing arbitrary files might be an option.

bharel avatar Jul 31 '22 08:07 bharel

@bharel the way dotnet webserver handles this is that by default it won't allow a relative path to navigate past the "base" directory. So for example, for mkdocs this would be the same as not allowing navigation beyond the folder with the mkdocs file in it. The check is done by "depth" from the base directory, so if your mkdocs file directoory (base directory) was one directory back from your markdown file, a relative path is only allowed to navigate back 1 directory at most. e.g "../foo.md" would be valid (a foo.md file next to the mkdocs file). Any relative path that attempts to navigate up more than 1 directory would be invalid, for example: "../../foo.md" or "../foo/bar/../../../bat.md" are both invalid. Also even if the full expansion of such a path ends up resolving to a valid subdirectory of the base directory, if it attempts to navigate beyond the base directory it makes it invalid regardless.

dazinator avatar Sep 12 '23 08:09 dazinator

We can add that as a separate feature

bharel avatar Sep 17 '23 18:09 bharel

Let's try it. I now allow it using a configuration option.

bharel avatar Oct 07 '23 04:10 bharel