redoc icon indicating copy to clipboard operation
redoc copied to clipboard

Reports unsupported specification when supplying it directly

Open elvanja opened this issue 2 years ago • 1 comments

The OpenAPI 3.0.3 API definition I am trying to integrate into a project is served from API server as yaml. That yml file is valid, e.g. it opens and renders without issues when I try it online via https://redocly.github.io/redoc/. I am using internal http tools to fetch it's raw content due to JWT authentication. So, I am trying to render the docs via React component, like this:

import { observer } from 'mobx-react'
import { useViewModelFactory } from 'mobx-react-viewmodel'

import { ApiDocPageViewModel } from './api_doc.page.vm.ts'
import { RedocStandalone } from 'redoc';

export const ApiDocPage = observer(function ApiDocPage() {
  const { spec } = useViewModelFactory(() => new ApiDocPageViewModel())

  return (
    <RedocStandalone spec={spec} />
  )
})

The important part is the <RedocStandalone spec={spec} /> section. I checked the spec value and indeed it is a string that contains the API specification, e.g. starts like this:

openapi: 3.0.3
info:
  title: API
  version: '1.0'
servers:
  - url: '{server}/api/v1'
....

However, this results in:

Error: Unsupported specification
    at detectSpec (http://localhost:4010/node_modules/.vite/deps/redoc.js?v=7192a3a7:21531:13)
    at http://localhost:4010/node_modules/.vite/deps/redoc.js?v=7192a3a7:36716:56
    at Generator.next (<anonymous>)
    at http://localhost:4010/node_modules/.vite/deps/redoc.js?v=7192a3a7:36632:71
    at new Promise (<anonymous>)
    at __awaiter (http://localhost:4010/node_modules/.vite/deps/redoc.js?v=7192a3a7:36614:14)
    at bundleDocument (http://localhost:4010/node_modules/.vite/deps/redoc.js?v=7192a3a7:36714:14)
    at http://localhost:4010/node_modules/.vite/deps/redoc.js?v=7192a3a7:36701:16
    at Generator.next (<anonymous>)
    at http://localhost:4010/node_modules/.vite/deps/redoc.js?v=7192a3a7:36632:71
image

I kind of traced this error to https://github.com/Redocly/redocly-cli/blob/main/packages/core/src/oas-types.ts#L103, but not sure if it applies here. Seems it indeed can not recognize the API doc/spec flavor. Which is odd given it works correctly on https://redocly.github.io/redoc. I am using "redoc": "^2.1.3" dependency.

Any idea on what may be wrong in my setup?

elvanja avatar Jan 29 '24 15:01 elvanja

it's possible it wants explicit string value. wrap the number in quotes

jeremyfiel avatar Jul 04 '24 00:07 jeremyfiel