guardrail-dev / guardrail

Principled code generation from OpenAPI specifications
https://guardrail.dev
MIT License
526 stars 133 forks source link

proper comments in generated code #569

Open willgu903 opened 4 years ago

willgu903 commented 4 years ago

first of all, kudos to the great package/tool for code gen. it fits our stack of akka-http/circe perfectly.

small suggestion in readability of the generated code. some comments for the functions would be helpful, especially those the require mandatory implementation. For example, I have a use case of handling file uploads with multipart/form-data. I set operationId: getUpload and ended up with function I need to implement

getUpload(respond: UploadResource.getUploadResponse.type)(front: (File, Option[String], ContentType), back: (File, Option[String], ContentType)): scala.concurrent.Future[UploadResource.getUploadResponse]
getUploadMapFileField(fieldName: String, fileName: Option[String], contentType: ContentType): File

the first one is standard, but the second one took me a while to figure out. Some comments in the meaning of this function would be very helpful.

blast-hardcheese commented 4 years ago

Hello @willgu-gdm,

Unfortunately, due to a limitation in scalameta, the way we're currently generating source isn't immediately compatible with comments. If you've got some spare time to look into how to use scalameta extras in order to create (and preserve!) comments during code generation, that would be extraordinarily helpful to the project.

Ideally, we'd have some generated scaladoc that would pop up in the user's IDE, and to generally be useful in cases like you expressed.

Anyway, thank you for bringing this up!