express-openapi
express-openapi copied to clipboard
Add express-openapi types
Hey @wesleytodd! 👋
I noticed that you had an open issue #25 for adding typescript types to this library. Fortunately there was already a base to start with, which I used here.
I've tested the types so hopefully they are 1 to 1 match with the runtime data. However there could be some things I missed.
Let me know if you want any changes or clarification!
This commit includes typing all the public facing signatures. The types also include API documentation in JSDoc format that is available in the root README of the repository. Most of the types were deduced by hand from the source code and tested with actual runtime data to make sure that the written types match with the runtime data.
The component methods use function overloading to provide better code completion of the expected parameters and return values. For example giving a type and a name to component("examples", "FooExample")
returns the expected type of ReferenceObject
conforming to the API documentation.
Similarly setting the type for the component function affects what it will return or take as an input. The input parameter and return type will conform to the expected type. For example:
const schemas = openapi.component("schemas");
// ^? { [key: string]: SchemaObject | ReferenceObject }
const examples = openapi.component("examples");
// ^? { [key: string]: ExampleObject | ReferenceObject }
The types utilize existing types defined in "openapi-types" and most of the public facing API functions rely on these types.
The initial typings file was derived from the work presented here: https://github.com/wesleytodd/express-openapi/issues/25#issuecomment-2309444521