Skip to content

OpenApiClientProvider with Stripe's open API hangs (3MB json) #150

Closed

Description

@vrescobar

Description

The autocompletion hangs and stops working when using OpenApiClientProvider with Stripe's open API. No visible error happens anywhere.

Repro steps

  1. Try to use OpenApiClientProvider with the stripe API
open SwaggerProvider

let [<Literal>] Schema = "https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.sdk.json"
// __SOURCE_DIRECTORY__ + "/openapi/stripe.spec3.json"
type Stripe = OpenApiClientProvider<Schema>

let main argv =
    let stripe = Stripe.Client()
    // the autocompletion dies or stops working at this point

That JSON file is about 3MB

Expected behaviour

I would expect to work as with any other open API or to get a visible error somewhere

Actual behavior

The autocompletion dies or stops working and doesn't seem to recover. To wait a large amount of time does not help.

Known workarounds

None:

  • All F# IDEs behave in the same way.
  • Serving the schema from the localhost doesn't make any difference.

Related information

Activity

  1. Thorium commented on Jun 2, 2020

    @Thorium
    Member

    A workaround I use is using the Stripe .NET library.
    But it's not painless. It's quite low-level library, I have over 500 lines of F# code around it. They change and rename and release new versions all the time, and don't mind the backward compatibility:
    Not keeping up

    A payment system should be a generic component. That would be so nice to have an out-of-box working payment solution for new F# projects. There is nothing project specific, "I just want to make an online-payment". I would be willing to help creating this kind of library...

    But the workflows are more complex than you initially think: A customer may want to store a card (Stripe PaymentApiCardId), but the card will expire. A customer can call to you and ask for a (partial) refund. A customer can call to the card company and dispute the transaction. Stripe can respond to a webhook, but you have to have the transaction state-fully stored. And another topic is the EU PSD2 SCA regulations... and local country specific payment regulations.

    A generic library is hard to make if you have to include a data storage (some kind of database) and a web-server endpoint for webhooks and also a way of redirecting users to 3D Secure. Suddenly you have to make decisions about technology and that is not generic anymore.

  2. Thorium commented on Jun 2, 2020

    @Thorium
    Member

    Digging a bit this, it seems to me that the reading of the network schema, parsing it, etc, takes only 2.5 seconds total. But after that, there is some background process, involving ProvidedTypes.fs, that generates a temp-dll (like \AppData\Local\Temp\tmp434F.dll) of having the types. It will finish in around 50 seconds in my computer, and then it's actually done.

    This is my little FSI script I used to test what happens:

    #I @"C:\git\SwaggerProvider\src\SwaggerProvider.DesignTime\obj\Debug\netstandard2.0\"
    #r @"C:\git\SwaggerProvider\src\SwaggerProvider.Runtime\bin\Debug\netstandard2.0\SwaggerProvider.Runtime.dll"
    let [<Literal>] Schema = "https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.sdk.json";;
    let t = System.DateTime.Now;; //#time didn't give correct results so let's user the old way...
    type Stripe = SwaggerProvider.OpenApiClientProvider<Schema, PreferAsync = true>;;
    printfn "%f" (System.DateTime.Now-t).TotalSeconds;;

    What could be done to fix this, is lazy schema exploration:

    • Also cache the schema type (OpenApiDocument) and use .AddMembersDelayed (.AddXmlDocDelayed, ...) instead of .AddMembers
    • ...to compile the types from the parsed tree only when the user explores the type, not all at the beginning.
    • And the recursive type generations should yield lazily recursion, not all at once. And they should be cached (e.g. with lazy-keyword) to avoid resolving them many times.
    • That way the slowness would at least divide evenly over the whole user experience, but with e.g. Stripe API, most of the users use actually only tiny bit of the whole API.
    • I guess FSharp.Data (its also generative type-provider like this) does it with World Bank provider, I'm expecting they don't download the whole bank at once...
    • That would be quite a big change for non-major use-case.
  3. toburger commented on Dec 16, 2020

    @toburger
    Contributor

    I'm also experiencing a substantial slow down when consuming a bigger OpenApi file like https://api.tourism.testingmachine.eu/swagger/v1/swagger.json.

  4. Thorium commented on Feb 6, 2021

    @Thorium
    Member

    We have a solution for Stripe now:
    https://github.com/simontreanor/FunStripe

  5. toburger commented on Feb 6, 2021

    @toburger
    Contributor

    Nice! But I've experienced those issues also with other OpenAPI services (not 3MB though) and it would be nice to have a solution for those performance problems.

  6. jkone27 commented on Jun 12, 2021

    @jkone27
    Contributor

    I also had issues of slowdown with bigger openapi files, would be great if there could be some perf optimization, or improve caching (or generate some offline schema that could be re-used from file system, once the generation has happened already?) This type provider is awesome 💌

  7. Thorium commented on May 20, 2024

    @Thorium
    Member

    There are a lot of nested types. The time is spent on ProvidedTypes.fs on method .Compile(isHostedExecution)
    This takes 7 seconds wait:
    // phase 2 - emit member definitions
    This takes 45 seconds wait:
    // phase 3 - emit member code
    Most of the time in these 2:
    // Emit the constructor (if any)
    // Emit the methods

    If iterateTypes function could just run parallel on nestedTypes, that could help a lot. However the parameter f is doing operations on non-theadsafe manner. So using Array.Parallel.iter would need a major refactor to avoid causing erros.

  8. Thorium commented on May 20, 2024

    @Thorium
    Member

    As this is TP issue in general, I did open issue for the SDK: fsprojects/FSharp.TypeProviders.SDK#341

  9. github-actions commented on Apr 7, 2026

    @github-actions
    Contributor

    🤖 This is an automated response from Repo Assist.

    Good news on the performance front! Two recent commits have improved type provider compilation speed for large schemas like Stripe's:

    1. #355 — Updated FSharp.TypeProviders.SDK to include a fix that reduces ILMethodDefs lookup from O(n²) to O(n). For large schemas with hundreds of operations, this can cut type-generation time significantly.

    2. #356 — Reduced repeated string allocations in the DLL-emit path (shared ToString helper + dictionary caching).

    These improvements target exactly the phases @Thorium identified — "phase 2 - emit member definitions" and "phase 3 - emit member code" — where the bulk of the time was being spent.

    If you get a chance to retry with the Stripe spec on the latest version, it would be great to hear whether the wait time has dropped noticeably. The lazy/on-demand exploration approach @Thorium described would reduce startup time further still, and remains open for a future contribution.

    Generated by 🌈 Repo Assist, see workflow run. Learn more.

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/repo-assist.md@7ee2b60744abf71b985bead4599640f165edcd93
    
  10. sergey-tihon commented on Apr 16, 2026

    @sergey-tihon
    Member

    I've released bunch of improvements for compile time and the size of the resulting assembly. If you still have an issue with stripe schema or have an ideas for futher optimizations please open new issue.

  11. Thorium commented on Aug 1, 2026

    @Thorium
    Member

    Ok, SwaggerProvider 4.2:

    #r "nuget:SwaggerProvider";;
    let [<Literal>] Schema = "https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.sdk.json";;
    let t = System.DateTime.Now;; //#time didn't give correct results so let's user the old way...
    type Stripe = SwaggerProvider.OpenApiClientProvider<Schema, PreferAsync = true>;;
    printfn "%f" (System.DateTime.Now-t).TotalSeconds;;

    On my laptop, we are down from the original 50+ seconds -> 13 seconds!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions