Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger server from schema? #190

Open
Thorium opened this issue Feb 1, 2022 · 6 comments
Open

Swagger server from schema? #190

Thorium opened this issue Feb 1, 2022 · 6 comments

Comments

@Thorium
Copy link
Member

Thorium commented Feb 1, 2022

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?

@sergey-tihon
Copy link
Member

We had discussion about it few years back #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 ;)

@Thorium
Copy link
Member Author

Thorium commented Feb 1, 2022

There are some clear advantages of TP vs any kind of code-generation templates:

  1. 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.

  2. 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.

  3. 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.

@sergey-tihon
Copy link
Member

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?

@Thorium
Copy link
Member Author

Thorium commented Feb 2, 2022

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.

@Eliemer
Copy link
Contributor

Eliemer commented Oct 5, 2023

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?

@sergey-tihon
Copy link
Member

@Eliemer There is no such effort.

read this #81

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants