Azure / autorest

OpenAPI (f.k.a Swagger) Specification code generator. Supports C#, PowerShell, Go, Java, Node.js, TypeScript, Python
MIT License
4.58k stars 731 forks source link

Generate models only (without any other boilerplate) #4456

Open Invertisment opened 2 years ago

Invertisment commented 2 years ago

I was wondering whether I could create only model generated code without any API clients. I want to do this because I don't use REST for my main features of the server.

It's possible that I may have some code that will need to call the back-end via REST but I don't think I want to generate API interation code for that.

Do you think it's a good idea to have a flag that generates only the models (with JSON annotations and so on)?

timotheeguerin commented 2 years ago

This isn't something we have plan for right now. Will keep open for tracking

serbrech commented 2 years ago

I asked the same question recently to @jhendrixMSFT Let me provide a use case to put the feature request in context.

We want to follow an api first design process. since the source of truth is ultimately defined by the swagger definition, that's were we naturally start.

But the swagger definitions for Azure should only be published once the API is public. and for the api to be public, we need to write our service. so we can't rely on the automated sdk generation to have these types :)

so the process is :

  1. define swagger
  2. generate sdk
  3. copy models only
  4. write service, deploy, etc...
  5. merge swagger (trigger sdk generation)

We can generate the sdk to use the datamodels in our service. this way, we ensure that we have no divergence between the generated clients and our service implementation.

Currently, the best we can do is generate the whole sdk for the service, copy the models, and discard the rest. If we could generate the models only, it would help automating our process.