openapi-typescript icon indicating copy to clipboard operation
openapi-typescript copied to clipboard

Generate a separate interface for each omponents.schemas model

Open alex-aveva opened this issue 2 years ago • 3 comments

Description

Generate a separate interface for each components.schemas model to provide a better development experience and easier models consumption.

Proposal

I've created a diff PR with the proposed changes, showing how the final result would look. As you can see, it's a fairly straightforward change, but it can make a significant difference in how VSCode provides hints. You can compare the before and after screenshots below.

Before: image

After image image

In real-world environments, having anonymous classes & hints is not very useful. Models often tend to be large, and in the many of cases, it's not even possible to determine which model you're looking at just by examining its shape. Providing a model interface name addresses this issue. It also enables referencing models by their interface names throughout the codebase, which is very convenient,

This perhaps can be an optional generator switch.

Checklist

alex-aveva avatar Oct 30 '23 23:10 alex-aveva

@drwpow I wonder how you feel about this? I'm trying to convince my teammates to adopt this library, and this feature is the only show-stopper for us. We're looking to use this for dozens of services we built (soon to be public) with a rather extensive model structure. Thank you!

alex-aveva avatar Nov 02 '23 20:11 alex-aveva

Upon reading your proposal, this sounds like what’s in-progress here https://github.com/drwpow/openapi-typescript/pull/1260?

I’m slightly-against this in general, because v1 of this library (long ago) took this approach and it quickly became untenable for many schemas. I wrote some thoughts here on some drawbacks of trying to generate separate interfaces for every schema object: https://github.com/drwpow/openapi-typescript/pull/1260#issuecomment-1658694431

And this is off-topic, but a related thought: embrace snake_case (i.e. sometimes trying to get APIs to conform to JS/TS syntax standards can be an unnecessary timesink in general).

drwpow avatar Nov 02 '23 20:11 drwpow

@drwpow linked PR will work, I'll try to reach author and see if I can help. Your comments make sense, will make sure to test those cases.

alex-aveva avatar Nov 07 '23 01:11 alex-aveva