IlluzionzDev / typespec

MIT License
0 stars 0 forks source link

Generate correct response data for endpoint #22

Closed IlluzionzDev closed 1 month ago

IlluzionzDev commented 1 month ago

The emitted service endpoint needs to properly handle the return models, status codes, error messages etc. So spring equivalent to handle those should be generated.

Response status code if not specified is 200 (need to check typespec graph). If status code is specified, business logic interface only returns body type (if applicable) and controller returns the specified status code. Using inbuilt typespec types such as OkResponse, NotFoundResponse etc just inject the @statusCode prop so this is the same case.

If multiple status codes are declared, create custom Object that has a field (with the body type) per each response status, and constructor for each. Business logic interface must return this object with one status code populate. Controller checks which isn't null and returns type based on that.

If error model is included with @error, generate custom Error class with the data types same as the model, and add a throws clause to the business logic interface to declare what it should throw.

Also need to handle returning possible headers. May generate custom type the interface method can return that has a property for headers, and property for the body object.