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

How to send an Hash of properties #416

Closed
Nerian opened this issue Mar 7, 2014 · 4 comments
Closed

How to send an Hash of properties #416

Nerian opened this issue Mar 7, 2014 · 4 comments

Comments

@Nerian
Copy link

Nerian commented Mar 7, 2014

Hi,

So my API expects a POST request with params in this manner:
captura de pantalla 2014-03-07 a la s 17 03 52

The problem is that it has a 'Section' field. You are not actually going to use it, but the fact that is required means that you need to pass a value. And if you do, then it breaks everything. If you edit the HTML using Chrome Inspector and remove that field, then everything works fine.

How can I remove the section field? Maybe the schema I am sending is wrong?

The schema data swagger UI is receiving was generated by grape-swagger, and is this:

{
  "apiVersion": "v2",
  "swaggerVersion": "1.2",
  "resourcePath": "",
  "apis": [
    {
      "path": "/api/v2/eclasses/{eclass_id}/roster/sections.{format}",
      "operations": [
        {
          "produces": [
            "application/json"
          ],
          "notes": "",
          "summary": "Add section to a class",
          "nickname": "POST-api--version-eclasses--eclass_id-roster-sections---format-",
          "httpMethod": "POST",
          "parameters": [
            {
              "paramType": "path",
              "name": "eclass_id",
              "description": "Eclass id",
              "type": "Integer",
              "dataType": "Integer",
              "required": true
            },
            {
              "paramType": "form",
              "name": "section",
              "description": null,
              "type": "Hash",
              "dataType": "Hash",
              "required": true
            },
            {
              "paramType": "form",
              "name": "section[name]",
              "description": null,
              "type": "String",
              "dataType": "String",
              "required": true
            }
          ]
        }
      ]
    },
  ],
  "basePath": "http://localhost:9292"
}
@webron
Copy link
Contributor

webron commented Mar 7, 2014

I believe this would be a question to the grape-swagger author(s).
In swagger-core, there's a way to filter out fields you don't want to
expose to your end users. Perhaps it offers something similar?

On Fri, Mar 7, 2014 at 6:36 PM, Gonzalo Rodríguez-Baltanás Díaz <
[email protected]> wrote:

Hi,

So my API expects a POST request with params in this manner:
[image: captura de pantalla 2014-03-07 a la s 17 03 52]https://f.cloud.github.com/assets/259568/2359042/1dce6dee-a613-11e3-904f-2ae07f9675aa.png

The problem is that it has a 'Section' field. You are not actually going
to use it, but the fact that is required means that you need to pass a
value. And if you do, then it breaks everything. If you edit the HTML using
Chrome Inspector and remove that field, then everything works fine.

How can I remove the section field? Maybe the schema I am sending is wrong?

The schema data swagger UI is receiving was generated by grape-swagger,
and is this:

{
"apiVersion": "v2",
"swaggerVersion": "1.2",
"resourcePath": "",
"apis": [
{
"path": "/api/v2/eclasses/{eclass_id}/roster/sections.{format}",
"operations": [
{
"produces": [
"application/json"
],
"notes": "",
"summary": "Add section to a class",
"nickname": "POST-api--version-eclasses--eclass_id-roster-sections---format-",
"httpMethod": "POST",
"parameters": [
{
"paramType": "path",
"name": "eclass_id",
"description": "Eclass id",
"type": "Integer",
"dataType": "Integer",
"required": true
},
{
"paramType": "form",
"name": "section",
"description": null,
"type": "Hash",
"dataType": "Hash",
"required": true
},
{
"paramType": "form",
"name": "section[name]",
"description": null,
"type": "String",
"dataType": "String",
"required": true
}
]
}
]
},
],
"basePath": "http://localhost:9292"}


Reply to this email directly or view it on GitHubhttps://github.com//issues/416
.

@Nerian
Copy link
Author

Nerian commented Mar 7, 2014

I don't think grape-swagger does. But if you point me to how the schema should look like I can make a PR in that project.

@webron
Copy link
Contributor

webron commented Mar 7, 2014

If you don't want the user to see the field, you just need to remove it
from the schema.
On Mar 7, 2014 6:52 PM, "Gonzalo Rodríguez-Baltanás Díaz" <
[email protected]> wrote:

I don't think grape-swagger does. But if you point me to how the schema
should look like I can make a PR in that project.


Reply to this email directly or view it on GitHubhttps://github.com//issues/416#issuecomment-37042971
.

@Nerian
Copy link
Author

Nerian commented Mar 7, 2014

I see. That makes it more clear. Thanks!

For anybody who currently has this issue and want a quick dirty fix, simply modify the onComplete call in index.html like this:

onComplete: function(swaggerApi, swaggerUi){
        log("Loaded SwaggerUI");
        $(".model-signature:contains('Hash')").parents('tr').remove();
        $('pre code').each(function(i, e) {hljs.highlightBlock(e)});
      },

@Nerian Nerian closed this as completed Mar 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants