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

Certain POST configurations result in an action creator that doesn't work #21

Open
shankie-codes opened this issue Oct 18, 2017 · 0 comments

Comments

@shankie-codes
Copy link

Let me see how well I can explain this!

If I have a Swagger spec that contains this:

operationId: addOpportunity
x-swagger-router-controller: opportunity.controller
description: Add a new opportunity. Returns a complete representation of the added opportunity.
tags:
  - opportunity
security: 
  - auth0:
    - openid
parameters:
  - name: opportunity
    description: Properties to add to the opportunity
    in: body
    required: true
    schema:
      $ref: "./Opportunity.yaml"
responses:
  "200":
    description: Success
    schema:
      allOf:
      - $ref: '../shared/newObject.yaml'
      - $ref: './Opportunity.yaml'
  default:
    description: Error
    schema:
      $ref: "../shared/errorResponse.yaml"

I get:

export function addOpportunity(opportunity, info) {
  return dispatch => {
    dispatch({ type: ADD_OPPORTUNITY_START, meta: { info } })
    return opportunity.addOpportunity(opportunity)
      .then(response => dispatch({
        type: ADD_OPPORTUNITY,
        payload: response.data,
        error: response.error,
        meta: {
          res: response.raw,
          info
        }
      }))
  }
}

As you can see, this isn't going to work: return opportunity.addOpportunity(opportunity). It's because the parameter passed to addOpportunity (opportunity, in this case) is also the same as the named import at the top of the file:

import * as opportunity from '../opportunity'

... and badness ensues. It's because my tags and params both have a thing called opportunity. I can work around this by changing the name of my param, but it's not unreasonable to name the parameter for a 'new opportunity' as opportunity.

Is this a quick/obvious fix for you? I'm happy to look into it, but I don't currently understand the guts of your templating system, so it might take me a while to get up to speed.

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

No branches or pull requests

2 participants