Open Thorium opened 2 years ago
We had discussion about it few years back https://github.com/fsprojects/SwaggerProvider/discussions/81
It should be possible (just need to choose correct target like Giraffe for example) I do not think that TP is good tools, I personally believe in bright future of https://github.com/Zaid-Ajaj/Hawaii ;)
There are some clear advantages of TP vs any kind of code-generation templates:
Code generation will create you a maintenance-problem, as people modify the generated code and then they cannot update the templates when generator updates. Maintenance is always more expensive than writing new code, so you should optimize maintenance, not initial creation.
There will be abstraction-level mismatch between higher abstraction generation and lower-abstraction generated code. So you can generate something and then you tweak on lower level. Where as in TP the creator has already went through the thought process of creating correct higher level abstractions and compositions, so that you don't need access to the lower level modifications.
Yes TPs are complex machines, but the people contributing to create and fix TPs are also typically very senior level, who can maintain some messy code inside TP, and the end-user-experience is very clean. So the complex messy code is abstracted away from your codebase, and your maintenance. Where as with generators, your next non-senior-hire will cause major damage while not being aware all the dangers of the messy code that the generator templates created.
Code generation will create you a maintenance-problem,
What if you do not commit generated code? It should prevent modification of generated code.
The primary cons of TP is speed, number of times IDE call it and all-time schema availability requirement (like DB connection).
What's may go wrong if codegen generate contract/interface that you have to implement in your controllers and you will not commit these files?
If you don't let modifications to the generated code, then that's a compiler, not a code-generator. Which is nice, if possible.
But typically issues are easier to fix to the generated code, and the hard way to fix is to modify the initial template. (Reverse-engineer the source location, etc.)
Quoting (freely) the book "Microsoft .NET - Architecting Applications for the Enterprise":
If you have an easy way to fix issue, and a hard way by framework, what is the correct thing to do? - At that point it doesn't matter anymore, as the framework has already gone wrong not supporting what users try to do with it.
Is there an ongoing effort to do schema to server? Can I attempt to do this? Any lessons you can share before i lose my sanity trying?
@Eliemer There is no such effort.
read this https://github.com/fsprojects/SwaggerProvider/discussions/81
This might be bit off-topic, but still with Swagger and F#: Right now OpenApiProvider/SwaggerProvider generates the clients from the schema.
Is there a way to generate a server (/server-template) from the schema?
Any kind of Owin/Katana/.NET WebApi, or something F# specific like Giraffe templates?
Current tools seem to be generating a schema from server, but what about generating a server from schema, is there any tools for that? What is the current best practice?