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

`swagger_url` doesn't seem to get parsed from `extra:` in `mkdocs.yml`

Open zeigerpuppy opened this issue 3 years ago • 2 comments

I have set up the mkdocs-swagger-plugin to call my local https://server.net/swagger.json but the script fails on exception:

TypeError: swagger.paths[path] is undefined

My config in mkdocs.yml is:

plugins:
  - swagger
extra:
   swagger_url: 'https://server.net/swagger.json'

and the page being rendered has:

!!GET /users/{id}!!

looking at the function call, it is:

function findApiFromSwagger(swagger, method, path) {
  'use strict'
  return swagger.paths[path][method.toLowerCase()]
}

this seems to be using the object:

swagger: Object: "2.0", host": "petstore.swagger.io", "basePath": "/v2", ...} 
method: "GET" 
path: "users/{id}"

This suggests that the plugin is not setting SWAGGER_URL properly and instead is using the default:

const SWAGGER_URL = 'https://petstore.swagger.io/v2/swagger.json'

I'm not quite sure how I should fix it?

zeigerpuppy avatar Apr 14 '21 05:04 zeigerpuppy

I have tried manually replacing the SWAGGER_URL in ./site/javascript_swagger/swagger_plugin.js

That allows the script to progress but then it gets stuck on:

Uncaught (in promise) SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

I have double checked that the JSON file can be read with curl. It is readable at the URL I have specified.

zeigerpuppy avatar Apr 14 '21 05:04 zeigerpuppy

Hi! thanks for trying this repo! Are you sure that the returned content is a valid JSON? If yes, would you investigate more and try to fix it? I'm open for PR! 😄

allevo avatar Apr 14 '21 16:04 allevo