scalar / scalar

Beautiful API references from OpenAPI/Swagger files ✨
https://scalar.com/swagger-editor
MIT License
5.17k stars 147 forks source link

Docusaurus plugin not working with YAML file #1959

Closed jesuspaletaisl closed 1 week ago

jesuspaletaisl commented 1 month ago

What happens?

Using the Docusaurus plugin with a YAML file shows this error: SyntaxError: Unexpected token 'o', "openapi: 3"... is not valid JSON

I have tried the same YAML file in the Scalar website and with others plugins and it is working correctly but with the Docusaurus plugin it asks for a JSON file.

The plugin is working well with JSON files.

What did you expect to happen?

The plugin should accept both URLs for YAML and JSON files.

How can we reproduce the issue?

Add the plugin configuration in the file "docusaurus.config.ts" as explained in the docs:

`import type { ScalarOptions } from '@scalar/docusaurus'

plugins: [ [ '@scalar/docusaurus', { label: 'Scalar', route: '/scalar', configuration: { spec: { url: 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml', }, }, } as ScalarOptions, ], ], `

After starting the project with "npm start" the terminal logs print this error: [ERROR] Site reload failure SyntaxError: Unexpected token 'o', "openapi: 3"... is not valid JSON at JSON.parse (<anonymous>)

OpenAPI Document

No response

marclave commented 1 month ago

@jesuspaletaisl ! great report

https://github.com/scalar/scalar/blob/main/packages/docusaurus/src/index.ts#L24

this line will defs do it, we should just load it as text and pass it in :)

edit will get this fixed up!

jesuspaletaisl commented 1 month ago

Perfect!

BTW, is configuration.spec.content not an option in this plugin?

Using directly Scalar I see two options spec.url and spec.content (for files),

will be the "content" option added in the future to load files directly ?

hanspagel commented 1 month ago

I think you’re right, we should just pass the configuration and fetch the specification in the frontend.

Maybe there’s a reason we do this in the plugin @amritk? If we have to do it in the plugin, we chould use the fetchSpecFromUrl helper: https://github.com/scalar/scalar/blob/main/packages/oas-utils/src/helpers/fetchSpecFromUrl.ts

amritk commented 1 month ago

no reason! We can change it @hanspagel

hanspagel commented 1 week ago

This was fixed in #2159 :)