question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

compile-time safety for api call parameters and types

See original GitHub issue

The current java api provides no compile-time safety for api call parameters. Neither the names of the parameters nor the types being passed as values are checked at compile time. It would be beneficial to users of the API to have a fluent style api for Stripe api calls. For example:

    final Refund refund = 
        stripe.refund()
        .create(chargeId)
        .reverseTransfer(true)
        .metadata("reason", "refund due to cancellation")
        .idempotencyKey(stripeRefundNonce)
        .get();

This might seem like a lot of work, however the official Stripe API reference is structured so well that such an API can be generated directly from the HTML. In fact, I know it can be done because that’s what I’m doing in my project. A little bit of Javascript, jQuery, and Mustache is all that’s needed to create a fluent style api directly from the official reference documentation. Every time the API changes, the corresponding java code can be regenerated automatically. Additionally, because it comes directly from the documentation, we can also incorporate Javadoc:

    /**
     * A cursor for use in pagination. <code>ending_before</code> is an
     * object ID that defines your place in the list. For instance, if
     * you make a list request and receive 100 objects, starting with
     * <code>obj_bar</code>, your subsequent call can include
     * <code>ending_before=obj_bar</code> in order to fetch the previous
     * page of the list.
     */
    public final AllMethod endingBefore(final String endingBefore) {
        return set("ending_before", endingBefore);
    }

If this is something that should be in the official Stripe API then I can create a pull request for it, otherwise I can create a separate project that builds on top of stripe-java.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:6
  • Comments:23 (16 by maintainers)

github_iconTop GitHub Comments

4reactions
Argodaycommented, Sep 17, 2015

+1 - the current design of this library is horribly non-object-oriented, this type of change would be much appreciated

3reactions
ob-stripecommented, Apr 10, 2019

Hi everyone. I know it’s been a long time since this issue was opened, but I’m happy to report that as of stripe-java v9.0.0, the library finally has support for fully typed request parameters!

You can see an example of the new syntax in our migration guide here. Over the next few weeks, the examples on Stripe’s site will also be updated to use the new syntax.

Thanks a lot for your patience. I’m closing the issue, but please do feel free to share your feedback.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type Phantoms and Safe APIs - /dev/solita
Types in TS are compile-time only but can be derived from the runtime code ... We might want to pass more parameters to...
Read more >
What doess compile time safety and run time safety mean?
Compile -time safety means that the compiler can analyze your code and guarantee that certain kinds of errors are not present. In Java,...
Read more >
Increased compile-time safety with phantom types
Introduction Using phantom types is a very simple technique that can be used to increase the compile-time safety of code.
Read more >
Take control of unexpected data at runtime with TypeScript
Runtime safety. TypeScript provides compile time safety. If you refer to a familiar value in a wrong way in the code, you'll get...
Read more >
Type Parameters Proposal
Since Print has a type parameter, any call of Print must provide a ... to provide a compile-time type-safe wrapper around an existing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found