-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Swagger UI endpoint #1144
Add Swagger UI endpoint #1144
Conversation
…i-express to support Swagger UI
What about on |
General observations:
edit: |
Yeah, the Swagger UI will increase the packages size but does offer quite a bit of functionality as a tradeoff.
I'm open to converting the YAML OpenAPI file to JSON, but I have found it more commonly stored as a YAML format. Maybe there's another package I can use to load it without adding another dep.
Sure, I can change that! |
don't worry about it, it probably isn't worth investigating it, it was just something that popped up, while reading it. |
Yeah, we would need the |
src/routes/api_docs.ts
Outdated
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
const swaggerDocument = yaml.load( | ||
await readFile(join(__dirname, "../etapi/etapi.openapi.yaml"), "utf8") | ||
) as object; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bit of a nitpicking comment:
the swaggerUI types seem to suggest that it takes a JsonObject
type
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/84e6da3397915d415adf7ef5b636affd8638b447/types/swagger-ui-express/index.d.ts#L38
the js-yaml types suggest that "load" returns an unknown
type
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/84e6da3397915d415adf7ef5b636affd8638b447/types/js-yaml/index.d.ts#L3
So I think if we do a typecast here, it should be OK to typecast this to "JsonObject" instead.
what do you think?
(you might need to use import type
to import the definition)
that last commit was more about making the it looks good for me now, thank you (and sorry for nitpicking ;-)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine for now, however in the future I would hope to generate the documentation statically and serve that instead if it reduces the binary size.
Currently it's just
/api-docs
...but I'm open to changing it since that's not the "best looking" endpoint lolGot the idea from #1123.