Replies: 2 comments 5 replies
-
Update on this: started writing some prototype code this weekend consuming |
Beta Was this translation helpful? Give feedback.
4 replies
-
This has my vote. (I'm the founder of Redocly and definitely biased and I appreciate your kind words above.) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Proposal
Over the course of v6 (3.1 support), this library has had to solve for quite a few challenges when it comes to complex schemas. Especially with the increased usage, more bugs have been uncovered. Which is great for stability, but it’s taken on a maintenance impact.
If I had to characterize the biggest challenge facing this library, it’s divided concerns. At its core, this library should be focused on converting an OpenAPI document to TypeScript. However, an unexpected challenge has been dealing with complex schema compositions (resolving
$ref
s) and a lot of time, energy, and bugfixes have gone into that. If the latter were able to be offloaded to a more reliable solution, it would be a huge win in stability and maintenance for this library.I’ve been using the Redocly CLI in other projects for over a year. And for almost as long, I‘ve been recommending the Redocly CLI in this library’s docs as the best validator for OpenAPI schemas. It’s an amazing OpenAPI toolkit for any OpenAPI spec, and it recently released its
1.0
stable release in August 2023. It does all of the following, but is not limited to:While people may be familiar with Redocly’s doc generation (“doc” is in the name, after all), I’m more interested in the validation and bundling capabilities of the CLI. Validation has been a sticking point of this library as openapi-typescript requires valid schemas but does not validate itself. This leads to many issues being opened reporting a bug when really it’s a malformed schema. Similarly, bundling would solve many resolution bugs from this library’s custom resolvers that Redocly CLI frankly handles better.
Pros
oneOf
/allOf
/anyOf
are deeply-nested and reach across paths and components. Though many have been fixed, they’ve been fixed at the cost of codebase complexity and after being an open issue for a while. There are likely more bugs unreported.Cons
@redocly/openapi-core
(which is pretty lightweight, but just pointing out)external
interface will likely go away, along with some other minor changes)Additional Info
Alternatives
*Why use the Redocly bundler?
There are quite a few historic bugs with composition and complex references that have been a burden on this library since its inception. They all revolve around resolution and interpreting OpenAPI’s flexible, loose format into explicit TypeScript types.
In between the OpenAPI source schema and the final TypeScript types lies a third, undocumented “intermediary” format (that mostly exists in ctx). While some may think of this as mere “context” needed to generate types, it really is more complex than just arbitrary metadata, and involves building quite a few ad-hoc structures through deep scanning that become its own format, in a sense. This library tries to do as little as possible in building this intermediary layer and instead rely on predictable TS references. In simple cases, we can bypass this layer by doing simple string conversion (e.g.
$ref: "#/components/schemas/foo"
→components["schemas"]["foo"]
). This is not only performant, but also reduces bugs by relying on TypeScript to resolve things for us.However, for complex examples, we need this intermediary context layer, which is built upon hacky implementations such as deep parameter and discriminator scanning and hinting (which was a mistake). For example, when using discriminator.propertyName + oneOf, its child
oneOf
objects need to have apropertyName
key added when there is no hint on the object itself it should be there. So we can’t simply deal with that when we come to it; we have to build the context mapping ahead-of-time on schema load. Every time we add another pass of deep-scanning, it’s slow at best, and buggy at worst.Bundling flattens this and makes deep-scanning not only cheaper but more predictable, as we only have a single schema with a predictable structure to deal with and not myriad complex, nested, partial schemas that are either linked through brittle string references or hacky ad-hoc context objects. Redocly also does a ton of work in handling conflicts, normalizing values, and simplifying the structure to make this task as easy as it can be.
🙏 Welcoming any thoughts or strong opinions on this topic
Beta Was this translation helpful? Give feedback.
All reactions