Coder Social home page Coder Social logo

Comments (3)

brandur-stripe avatar brandur-stripe commented on August 17, 2024

Oops, yep that's a crash:

$ go install && stripe-mock -port 12112
stripe-mock master
Routing to 115 path(s) and 197 endpoint(s) with 108 validator(s)
Listening on port 12112
Request: GET /v1/charges/ch_123
2018/02/20 12:05:09 http: panic serving [::1]:61521: Responding to /v1/charges/ch_123:
Dereferencing '#/components/schemas/charge':
Using fixture 'charge':
In property 'outcome' of object:
Choosing only branch of anyOf:
Dereferencing '#/components/schemas/charge_outcome':
In property 'rule' of object:
Expanding optional expandable field:
Dereferencing '#/components/schemas/rule':
Cannot find or generate example for: {
  "properties": {
    "action": {
      "type": "string"
    },
    "id": {
      "type": "string"
    },
    "predicate": {
      "type": "string"
    }
  },
  "required": [
    "action",
    "id",
    "predicate"
  ],
  "type": "object",
  "x-expandableFields": []
}
goroutine 8 [running]:
net/http.(*conn).serve.func1(0xc4202bafa0)
        /usr/local/Cellar/go/1.9.1/libexec/src/net/http/server.go:1697 +0xd0
panic(0x134f140, 0xc42012a5d0)
        /usr/local/Cellar/go/1.9.1/libexec/src/runtime/panic.go:491 +0x283
main.(*DataGenerator).generateInternal(0xc4209e5b10, 0xc420180960, 0xc4202ec604, 0x12, 0xc42055b7a0, 0x0, 0xc420096f20, 0x14a, 0x0, 0xc420624280, ...)
        /Users/brandur/Documents/go/src/github.com/stripe/stripe-mock/generator.go:121 +0x192c
main.(*DataGenerator).generateInternal(0xc4209e5b10, 0xc4201805a0, 0xc4202ec604, 0x12, 0xc42055b7a0, 0x0, 0xc42000ad00, 0xfa, 0x134f140, 0xc42085e990, ...)
        /Users/brandur/Documents/go/src/github.com/stripe/stripe-mock/generator.go:72 +0xfba
main.(*DataGenerator).generateInternal(0xc4209e5b10, 0xc420167360, 0xc4202ec604, 0x12, 0xc42055b780, 0xc42055bdf0, 0xc4200e82a0, 0xdc, 0x0, 0xc42085e940, ...)
        /Users/brandur/Documents/go/src/github.com/stripe/stripe-mock/generator.go:187 +0x59c
main.(*DataGenerator).generateInternal(0xc4209e5b10, 0xc420167220, 0xc4202ec604, 0x12, 0xc42055b780, 0xc42055bdf0, 0xc42043dd40, 0x88, 0x134f140, 0xc42085e960, ...)
        /Users/brandur/Documents/go/src/github.com/stripe/stripe-mock/generator.go:93 +0xe5a
main.(*DataGenerator).generateInternal(0xc4209e5b10, 0xc4202981e0, 0xc4202ec604, 0x12, 0xc42055b760, 0xc42055b7e0, 0xc420022af0, 0x67, 0x1, 0xc42021e2a0, ...)
        /Users/brandur/Documents/go/src/github.com/stripe/stripe-mock/generator.go:187 +0x59c
main.(*DataGenerator).Generate(0xc4203a9b10, 0xc4202981e0, 0xc4202ec604, 0x12, 0xc42055b760, 0x1, 0x0, 0x0, 0x160ce01)
        /Users/brandur/Documents/go/src/github.com/stripe/stripe-mock/generator.go:23 +0x120
main.(*StubServer).HandleRequest(0xc42064ef40, 0x159d240, 0xc4206c6000, 0xc42079e300)
        /Users/brandur/Documents/go/src/github.com/stripe/stripe-mock/server.go:203 +0x652
main.(*StubServer).HandleRequest-fm(0x159d240, 0xc4206c6000, 0xc42079e300)
        /Users/brandur/Documents/go/src/github.com/stripe/stripe-mock/main.go:75 +0x48
net/http.HandlerFunc.ServeHTTP(0xc42055b640, 0x159d240, 0xc4206c6000, 0xc42079e300)
        /usr/local/Cellar/go/1.9.1/libexec/src/net/http/server.go:1918 +0x44
net/http.(*ServeMux).ServeHTTP(0x15ec5e0, 0x159d240, 0xc4206c6000, 0xc42079e300)
        /usr/local/Cellar/go/1.9.1/libexec/src/net/http/server.go:2254 +0x130
net/http.serverHandler.ServeHTTP(0xc4202efad0, 0x159d240, 0xc4206c6000, 0xc42079e300)
        /usr/local/Cellar/go/1.9.1/libexec/src/net/http/server.go:2619 +0xb4
net/http.(*conn).serve(0xc4202bafa0, 0x159d8c0, 0xc420662c80)
        /usr/local/Cellar/go/1.9.1/libexec/src/net/http/server.go:1801 +0x71d
created by net/http.(*Server).Serve
        /usr/local/Cellar/go/1.9.1/libexec/src/net/http/server.go:2720 +0x288

Shouldn't be too hard to shore this up. I'll take a look.

from stripe-mock.

brandur-stripe avatar brandur-stripe commented on August 17, 2024

Just as a quick update: I looked into this one, and the reason this fails where other places don't is that right now we'll attempt to use fixture that's usually pre-specified in fixtures3 most of the time and generate a few special types of objects (like lists), but right now we fail with the message above if we can't do one of those.

Outcome and rule are a special case because they're API resources that we don't have a top-level resource for, and so the generator balks when it gets to them.

Solutions might include:

  1. Try to include even these types of nested resources in fixtures3.
  2. Allow stripe-mock to generate dummy data in this sort of case where just introspect each field and try to generate the minimum viable object (i.e., empty strings, zeroed integers and decimals, etc.).

The better approach is probably the latter so — it'd shore things up for now, and still allow us to generate higher fidelity subresource fixtures for fixtures3 that will supersede the dummy data when it's available.

from stripe-mock.

brandur-stripe avatar brandur-stripe commented on August 17, 2024

I ended up going with option (2) above.

Confirmed that #48 fixes this problem:

$ curl -vvvv -g "http://localhost:12112/v1/charges/ch_123?expand[]=outcome.rule" -u sk_test_123:
* Couldn't find host localhost in the .netrc file; using defaults
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 12112 (#0)
* Server auth using Basic with user 'sk_test_123'
> GET /v1/charges/ch_123?expand[]=outcome.rule HTTP/1.1
> Host: localhost:12112
> Authorization: Basic c2tfdGVzdF8xMjM6
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Request-Id: req_123
< Stripe-Mock-Version: master
< Date: Sat, 14 Apr 2018 00:12:13 GMT
< Content-Length: 966
< Content-Type: text/plain; charset=utf-8
<
{
  "amount": 100,
  "amount_refunded": 0,
  "balance_transaction": "txn_1CDJmuCLWM6HLS3K1JZYeh6X",
  "captured": false,
  "created": 1234567890,
  "currency": "usd",
  "description": "My First Test Charge (created for API docs)",
  "fraud_details": {},
  "id": "ch_123",
  "livemode": false,
  "metadata": {},
  "object": "charge",
  "outcome": {
    "rule": {
      "action": "",
      "id": "",
      "predicate": ""
    },
    "type": ""
  },
  "paid": true,
  "refunded": false,
  "refunds": {
    "data": [
      {
        "amount": 100,
        "charge": "ch_123",
        "created": 1234567890,
        "currency": "usd",
        "id": "re_1CDJmuCLWM6HLS3KE6PhPJEl",
        "metadata": {},
        "object": "refund",
        "status": "succeeded"
      }
    ],
    "has_more": false,
    "object": "list",
    "url": "/v1/charges/ch_123/refunds"
  },
  "source": {
    "id": "acct_1CDJjyCLWM6HLS3K",
    "object": "account"
  },
  "status": "succeeded"
}
* Connection #0 to host localhost left intact

from stripe-mock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.