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

curl "Accept" header issue in relation to the "Response Content Type" selection #2003

Closed
kchsieh opened this issue Feb 29, 2016 · 16 comments
Closed
Milestone

Comments

@kchsieh
Copy link

kchsieh commented Feb 29, 2016

I am using v2.1.4, for some reason the "Response Content Type" does not show up with the spec below and the generated curl command is this (notice the --header 'Accept: text/html' which is strange and nowhere to be found in my spec):

curl -X GET --header 'Accept: text/html' --header 'app_id: my_id_here' --header 'app_key: my_key_here' --header 'sid: 123456' 'http://localhost:3000/student'

{
  "swagger": "2.0",
  "info": {
    "description": "This is a sample spec.",
    "version": "1.0.0",
    "title": "Debug the ui",
    "contact": {
      "email": "do-not-reply@berkeley.edu"
    }
  },
  "host": "localhost:3000",
  "basePath": "/",
  "schemes": [
    "http"
  ],
  "produces": [
    "application/xml",
    "application/json"
  ],
  "paths": {
    "/student": {
      "get": {
        "summary": "Sample of REST service",
        "description": "Dummy spec. to debug the swagger-ui accept issue.",
        "produces": [
          "application/xml",
          "application/json"
        ],
        "parameters": [
          {
            "in": "header",
            "name": "app_id",
            "description": "3Scale id",
            "default": "my_id_here",
            "required": true,
            "type": "string"
          },
          {
            "in": "header",
            "name": "app_key",
            "description": "3Scale key",
            "default": "my_key_here",
            "required": true,
            "type": "string"
          },
          {
            "in": "header",
            "name": "sid",
            "description": "Studet ID",
            "default": "123456",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful"
          },
          "404": {
            "description": "Something is wrong"
          }
        }
      }
    }
  }
}
@webron
Copy link
Contributor

webron commented Mar 1, 2016

It doesn't appear because your 200 response doesn't state it returns anything. The issue with the curl is different.

@kchsieh
Copy link
Author

kchsieh commented Mar 1, 2016

Thanks for the tip, I have updated my swagger.json to include schema (see below) and the "Response Content Type" selection is showing up. But the generated curl header still says 'application/json', when I selected 'application/xml':
curl -X GET --header "Accept: application/json" --header "app_id: my_id_here" --header "app_key: my_key_here" --header "sid: 123456" "http://localhost:3000/student"

Updated swagger.json:

{
  "swagger": "2.0",
  "info": {
    "description": "This is a sample spec.",
    "version": "1.0.0",
    "title": "Debug the ui",
    "contact": {
      "email": "do-not-reply@berkeley.edu"
    }
  },
  "host": "localhost:3000",
  "basePath": "/",
  "schemes": [
    "http"
  ],
  "produces": [
    "application/xml",
    "application/json"
  ],
  "paths": {
    "/student": {
      "get": {
        "summary": "Sample of REST service",
        "description": "Dummy spec. to debug the swagger-ui accept issue.",
        "produces": [
          "application/xml",
          "application/json"
        ],
        "parameters": [
          {
            "in": "header",
            "name": "app_id",
            "description": "3Scale id",
            "default": "my_id_here",
            "required": true,
            "type": "string"
          },
          {
            "in": "header",
            "name": "app_key",
            "description": "3Scale key",
            "default": "my_key_here",
            "required": true,
            "type": "string"
          },
          {
            "in": "header",
            "name": "sid",
            "description": "Studet ID",
            "default": "123456",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful",
            "schema": { "type": "string" }
          },
          "404": {
            "description": "Something is wrong"
          }
        }
      }
    }
  }
}

@kchsieh kchsieh changed the title "Response Content Type" selection does not show up curl "Accept" header issue in relation to the "Response Content Type" selection Mar 1, 2016
@xpxu
Copy link

xpxu commented Mar 3, 2016

To make it more simple, I think you can delete "produces" in "student" and try it again. A "produces" on the top level is enough.

@kevprice83
Copy link

This has been tried and the same error is still produced.

@kevprice83
Copy link

Still experiencing the same problem as described above. Any update on a fix for this?

@kevprice83
Copy link

any updates on this issue?

@jlh424
Copy link

jlh424 commented May 24, 2016

I am having the same problem, with 'Accept: text/html' showing up in the curl command even though I have not specified that anywhere.

@fehguy
Copy link
Contributor

fehguy commented Jun 16, 2016

fixed in efb7765

@fehguy fehguy closed this as completed Jun 16, 2016
@kchsieh
Copy link
Author

kchsieh commented Jun 27, 2016

@fehguy are you sure this has been fixed. I just downloaded the code from the dist folder (this is from master branch) and the generated curl command is fixed to "text/html" like below:

curl -X GET --header 'Accept: text/html' --header 'app_id: my_id_here' --header 'app_key: my_key_here' --header 'sid: 123456' 'http://localhost:3000/student'

@fehguy
Copy link
Contributor

fehguy commented Jun 27, 2016

@kchsieh it's been extensively tested, but there's always the possibility of an issue. Can you please share the definition that is producing this?

@kchsieh
Copy link
Author

kchsieh commented Jun 27, 2016

@fehguy , thanks for the quick response. My swagger.json spec. is in my March 1st comment above.

@fehguy
Copy link
Contributor

fehguy commented Jun 27, 2016

OK I just tested this and get the following:

curl -X GET --header 'Accept: application/json' --header 'app_id: my_id_here' --header 'app_key: my_key_here' --header 'sid: 123456' 'http://localhost:3000/student'

Can you please make sure you don't have a cached copy of swagger-ui.js in your browser?

This issue was originally against ef0fc16276847b22e43a1dc488e246faf20e6e8b but I've updated it to the release 2.1.15 in #2245

@fehguy
Copy link
Contributor

fehguy commented Jun 27, 2016

@kchsieh please pull master / dist and retest?

@kchsieh
Copy link
Author

kchsieh commented Jun 27, 2016

@fehguy , just downloaded master/dist again and this time I tested it without put them into my Rails application (suspect it was caching somehow). But when I select 'application/xml' from the 'Response Content Type', the generated curl script still says 'application/json'. Fyi, tested using 3 different browsers and got the same issue.

@fehguy
Copy link
Contributor

fehguy commented Jun 27, 2016

OK to be clear, you're now getting a different response than before?

@kchsieh
Copy link
Author

kchsieh commented Jun 27, 2016

correct, when I put it into my Rails application, select 'application/xml' or 'application/json', I always got 'text/html'.
Without test it in my Rails application, just use file:/// and test it in the browser, when I select 'application/xml', it generate 'application/json'.

@fehguy fehguy added this to the v2.2.1 milestone Aug 23, 2016
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

6 participants