Skip to content

add options parameter to add redoc options and theming capacity.#21

Open
youenchene wants to merge 2 commits intomvrilo:masterfrom
youenchene:master
Open

add options parameter to add redoc options and theming capacity.#21
youenchene wants to merge 2 commits intomvrilo:masterfrom
youenchene:master

Conversation

@youenchene
Copy link

Small contributions to add a options parameter to handle redoc configuration : https://github.com/Redocly/redoc/blob/main/docs/config.md

Also added documentation for understanding quicker the different parameters of go-redoc.

redoc.go Outdated
SpecFS *embed.FS
Title string
Description string
Options string
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of expecting a json string here.
It also seems that json.Valid doesn't ensure the string is an actual object.
https://go.dev/play/p/gmBO0XamJob

I see the redoc's Config type is quite extensive - so supporting all of these in a struct type might be overkill.

So why not use a map[string]any as type then later json.Marshal it?
That would ensure we're always receiving an object.

Your example would look like this:

Options: map[string]any{
  "disableSearch": true,
  "theme": map[string]any{
    "colors": `{"primary":{"main":"#297b21"}}`,
  },
}

Copy link
Owner

@mvrilo mvrilo Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also instead of naming it Options, maybe we could name it Config or Settings?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also instead of naming it Options, maybe we could name it Config or Settings?

Hello?

I've chosen options because this is the name on redocly side : https://redocly.com/docs/redoc/deployment/html#the-redoc-object

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvrilo themap[string]anyis legit and make it stronger.

I have to upgrade to go 1.18 to handle the any type.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvrilo if you have 5mn for the PR. It would be delightful.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvrilo please.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvrilo again pleasE.

…ing.

Updated `Options` field from a JSON string to a `map[string]any` for better type safety and readability. Adjusted related logic, tests, and documentation to reflect this change. Removed redundant test for invalid JSON in options.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants