-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[REQ] FSharp (F#) server stub based on record types #2342
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
Comments
@viktor-ferenczi Sounds good to me 👍 Would you have time to contribute the new F# server stub generator? We can work with you to create the new generator similar to what we've done before: https://github.com/OpenAPITools/openapi-generator/projects?query=is%3Aclosed |
That's exactly my plan. It is just good practice to add a request first and wait for some discussion, so I start in the right direction. I already have the openapi-generator project set up in IntelliJ IDEA. Hint needed: How can I limit the build to a single backend? (For development speed.) |
@viktor-ferenczi when you recompile the project, use |
@viktor-ferenczi I'm happy to help contribute to this. Have you opened a repository anywhere? |
To facilitate collaboration among F# developers, what about creating a branch "f-sharp-server" in the official OpenAPI Generator repo so that all F# developers can contribute to this branch to move the project forward? |
@wing328 Sounds good to me! |
@viktor-ferenczi are you at a stage where you can push to this branch? I'm starting from a clean slate, and ideally I'd prefer to avoid duplicating work that you've already done. |
@nmfisher I haven't started on this yet. (High workload on my regular job.) |
@viktor-ferenczi no worries. I'll create the base class and the templates so that people can start patching it to support the F# server stub generator. |
No problem @viktor-ferenczi , I am working on this at the moment and aim to have something available on the f-sharp-server branch in the next few days. |
@nmfisher I'll wait for your PR then. |
Fork is at https://github.com/nmfisher/openapi-generator/tree/f-sharp-server if anyone wants to track WIP before issuing a PR. |
@nmfisher I've just cloned your branch. From Model.mustache: module Model =
type Definitions = OpenAPIV3Provider<"openapi.yaml"> Is it a placeholder? The whole point of the |
Right now, it's just a placeholder. I understand your point about IDE restarts (though that seems to be a general issue around type providers - I also experimented with a new type provider for this branch but decided not to bother). Seems a shame to re-do all the good work that OpenAPIV3Provider has already done though? |
Yeah, it is a shame. But there is another reason: A type provider is relatively opaque, while generated source is transparent. It is possible to copy part of the generated type declarations. For example, to come up with an in-memory record containing a subset of fields. This is often useful in practice. |
@nmfisher Good job on starting the backend! In case you would like me to write the template for the model record type generation, please let me know. |
Thanks @viktor-ferenczi - I'm actually going through the model record template at the moment. Will let you know if I have any questions. |
Thanks for the PR by @nmfisher @viktor-ferenczi when you've time, I wonder if you can review. Thanks! |
@wing328 suggest you close this issue as the PR has been merged and no activity since 2019. |
Uh oh!
There was an error while loading. Please reload this page.
F#+Giraffe backend stub generator.
Alternatives attempted:
In the above solutions classes are accessible from F# via the common platform (.NET CLI).
I suggest a new backend generating F# record types like:
Record type would provide familiar access with dot notation, plus being accessible from C# code if needed.
These generated accessors would be composable in functional code:
The updater has the object as its last parameter, which is good practice in functional programming.
Example usage:
Future versions of F# may gain new syntax for convenient property access, which will simplify the getter to:
_.salary
Despite this the composable update functions (like
withSalary
) will remain useful.I suggest using the Giraffe Web framework in the generated backend stub, since it generally results in a clean default implementation. Giraffe has a SampleApp solution which could be used as the basis of the generated one.
The text was updated successfully, but these errors were encountered: