Certain POST configurations result in an action creator that doesn't work
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.