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

A new parameter 'body' gets added for hash type params #67

Closed
arparthasarathi opened this issue Nov 15, 2017 · 10 comments
Closed

A new parameter 'body' gets added for hash type params #67

arparthasarathi opened this issue Nov 15, 2017 · 10 comments
Assignees

Comments

@arparthasarathi
Copy link

arparthasarathi commented Nov 15, 2017

Specs

  • Swagger 2.0
  • Widdershins installation from the branch v3.0

I am using parameters of type hash for our APIs. Swagger generates the JSON as given below

"paths":{"/betaweb/users/sign_in":{"post":{"description":"User Authentication API","produces":["application/json"],"consumes":["application/json"],"parameters":[{"in":"formData","name":"user[email]","description":"User email","type":"string","required":false},{"in":"formData","name":"user[username]","type":"string","required":false},{"in":"formData","name":"user[password]","description":"User Password","type":"string","required":true}],"responses":{"201":{"description":"Created"},"422":{"description":"Invalid Login Credentials"}},"tags":["users"],"operationId":"User Authentication API"}},

But my Slate Markdown adds a parameter body to my request as below.

screen shot 2017-11-15 at 3 01 41 pm

I couldn't figure out to remove the body parameter.

And also, the password parameter required is set to true in the Swagger JSON. But the in the documentation, required field for password is set to false

@MikeRalphson
Copy link
Contributor

This is an artifact of the way the formData parameters are internally converted into the requestBody structure used by OpenAPI 3.0.

I'll add an option to omit the enclosing (fake) body parameter.

@arparthasarathi
Copy link
Author

Is there any way that I could prevent the enclosing from my side?

@MikeRalphson
Copy link
Contributor

You can patch openapix.js in function fakeBodyParameter and comment-out the first instance of the following line:

bodyParams.push(param);

It should be line 275.

@arparthasarathi
Copy link
Author

Perfect ! Thanks for the patch. Works seamlessly. You are awesome Mike, saving us a lots of time.

A quick question, why is that am getting the symbol >> before the parameters? Not a pressing issues, just for getting a deeper understanding of how the parser works.

screen shot 2017-11-15 at 5 19 15 pm

@MikeRalphson
Copy link
Contributor

That's because it's showing a nested properties under the object that we've just hidden.

If you change the offset 0 to -1 on the following line, they should go away:

let props = common.schemaToArray(data.bodyParameter.schema,0,{trim:true},data);

Line 278. Thanks for testing my changes I haven't even written yet!

@arparthasarathi
Copy link
Author

Awesome! Thanks for that :)

Mike, am also facing an issue with the required field as said above. If you take a look at the first screen shot, the parameter password is mentioned as required in the Swagger JSON but in the markdown, the field is set to false. And in the screenshot that I have added in the subsequent comment, every field is a required one. But only the email field is set as required.

Is this an issue or am I doing anything wrong?

@MikeRalphson
Copy link
Contributor

Mike, am also facing an issue with the required field as said above.

This was a bug in the OpenAPI 2.0 to 3.0 converter. When the next beta of widdershins is released (hopefully later today) it will have the updated converter dependency.

Thanks again for the testing and the bug reports!

MikeRalphson added a commit that referenced this issue Nov 15, 2017
@MikeRalphson
Copy link
Contributor

Apologies for the delay, widdershins@3.0.0-beta0.1 has just been released.

@MikeRalphson
Copy link
Contributor

Widdershins v3.0.0 has just been released.

@arparthasarathi
Copy link
Author

Thanks a lot for the update Mike!

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