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

swagger-ui 'try it' generating curl urls with http scheme even though swagger.json only has https scheme #3166

Closed
pjfanning opened this issue Jun 1, 2017 · 17 comments

Comments

@pjfanning
Copy link

Found with current http://petstore.swagger.io/ UI (doesn't display a software version number).

{
  "swagger" : "2.0",
  "info" : {
    "description" : "",
    "version" : "1.0",
    "title" : "",
    "termsOfService" : ""
  },
  "host" : "localhost:8443",
  "basePath" : "/api",
  "tags" : [ {
    "name" : "services"
  } ],
  "schemes" : [ "https" ],
  "paths" : {
    "/services" : {
      "get" : {
        "tags" : [ "services" ],
        "summary" : "Return Service Information for all Environments",
        "description" : "",
        "operationId" : "get from all environments",
        "produces" : [ "application/json" ],
        "parameters" : [ {
          "name" : "serviceTypes",
          "in" : "query",
          "description" : "Variable to specify which serviceType Service Discovery should search for",
          "required" : false,
          "type" : "string"
        }, {
          "name" : "tenant",
          "in" : "query",
          "description" : "Specifies the tenant for an OTS/ORS endpoint",
          "required" : false,
          "type" : "string"
        }, {
          "name" : "stateFilteringPolicy",
          "in" : "query",
          "description" : "Filters out endpoints that are not READY",
          "required" : false,
          "type" : "string"
        }, {
          "name" : "fields",
          "in" : "query",
          "description" : "Allows users to specify which property fields they would like returned",
          "required" : false,
          "type" : "string"
        } ],
        "responses" : {
          "200" : {
            "description" : "Return Discovered Endpoints"
          },
          "400" : {
            "description" : "Bad Request"
          },
          "401" : {
            "description" : "Incorrect username or password"
          },
          "404" : {
            "description" : "No Endpoints Discovered"
          },
          "500" : {
            "description" : "Internal server error"
          }
        }
      }
    },
    "/envs/{environments}/services" : {
      "get" : {
        "tags" : [ "services" ],
        "summary" : "Return Service Information for a Specific Environment",
        "description" : "",
        "operationId" : "environments",
        "produces" : [ "application/json" ],
        "parameters" : [ {
          "name" : "serviceTypes",
          "in" : "query",
          "description" : "Variable to specify which serviceType Service Discovery should search for",
          "required" : false,
          "type" : "string"
        }, {
          "name" : "tenant",
          "in" : "query",
          "description" : "Specifies the tenant for an OTS/ORS endpoint",
          "required" : false,
          "type" : "string"
        }, {
          "name" : "environments",
          "in" : "path",
          "description" : "Specifies the environment to search for the service",
          "required" : true,
          "type" : "string"
        }, {
          "name" : "stateFilteringPolicy",
          "in" : "query",
          "description" : "Filters out endpoints that are not READY",
          "required" : false,
          "type" : "string"
        }, {
          "name" : "fields",
          "in" : "query",
          "description" : "Allows users to specify which property fields they would like returned",
          "required" : false,
          "type" : "string"
        } ],
        "responses" : {
          "200" : {
            "description" : "Return Discovered Endpoints"
          },
          "400" : {
            "description" : "Bad Request"
          },
          "401" : {
            "description" : "Incorrect username or password"
          },
          "404" : {
            "description" : "No Endpoints Discovered"
          },
          "500" : {
            "description" : "Internal server error"
          }
        }
      }
    }
  },
  "securityDefinitions" : {
    "basicAuth" : {
      "type" : "basic"
    }
  },
  "definitions" : {
    "Function1" : {
      "type" : "object"
    },
    "Function1RequestContextFutureRouteResult" : {
      "type" : "object"
    }
  }
}
@shockey
Copy link
Contributor

shockey commented Jun 3, 2017

I'm not able to reproduce this in the latest version, though I do see it on Petstore.

I'll circle back on this on Monday to confirm a fix, once we've redeployed Petstore... probably was some dependency weirdness.

@pjfanning
Copy link
Author

I tried this again with petstore.swagger.io and the issue still appears to be there.

@webron
Copy link
Contributor

webron commented Jun 13, 2017

Confirmed. @shockey - the issue is there.

@shockey shockey added the Ready label Jun 27, 2017
@santoshghalsasi
Copy link

Hi,
Can you please let me know when the fix for this will be pushed.

Regards,
Santosh

@shockey
Copy link
Contributor

shockey commented Jun 28, 2017

I'm working on it now, @santoshghalsasi.

It'd be helpful if you could share a spec that causes the problem, and shared how you use Swagger-UI (via swagger.io, via static files, or via npm). Thanks!

@santoshghalsasi
Copy link

Hi @shockey,
Thank you for your reply. I have posted the details of the exercise that we are trying to do and the problem faced on the swagger community - https://groups.google.com/forum/#!searchin/swagger-swaggersocket/sharepoint%7Csort:relevance/swagger-swaggersocket/uVrQnRrB-0M/u7TZjohOAAAJ

We are using static files(I guess that is what you mean when we copy the swagger UI files and use it somewhere else) and using below spec to test it(have removed some part due to confidentiality) -

{
"swagger": "2.0",
"info": {
"description": "Get Checklist History Details",
"version": "1.0.0",
"title": "Checklist History Details",
"contact": {
"name": "API Team",
"email": "apiteam@apigee.net"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"host": "0.0.0.0",
"basePath": "/checklistapi",
"schemes": [
https
],
"paths": {
"/getchecklisthistorydetails": {
"post": {
"summary": "get checklist history details for a Fleet Id",
"operationId": "getchecklisthistorydetails",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"description": "",
"type": "object",
"properties": {
"MobileServiceheader": {
"type": "object",
"properties": {
"transactionID": {}
}
},
"Body": {
"type": "object",
"properties": {
"getChecklistHistoryDetailsResponse": {
"type": "object",
"properties": {
"Status": {
"type": "string",
"minLength": 1
},
"OperationHeaderList": {
"type": "object",
"properties": {
"OperationHeaderInformation": {
"type": "object",
"properties": {
"CreatedDate": {},
"NumberOfDefectsRaised": {},
"OperationWorkAreaList": {}
}
}
},
"required": [
"OperationHeaderInformation"
]
}
},
"required": [
"Status",
"OperationHeaderList"
]
}
},
"required": [
"getChecklistHistoryDetailsResponse"
]
}
},
"required": [
"MobileServiceheader",
"Body"
]
}
}
},
"parameters": [
{
"name": "Authorization",
"in": "header",
"description": "The access token that was provided in the authentication stage prefixed by 'Bearer'.",
"required": true,
"type": "string"
},
{
"name": "udid",
"in": "header",
"description": "A unique identifier for the device or app instance. Used for token verification purposes.",
"required": true,
"type": "string"
},
{
"name": "Content-Type",
"in": "header",
"description": "Content Type of the request",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/getChecklistHistoryDetailsReq"
},
"description": "The getChecklistHistoryDetails JSON service request.",
"required": true
}
]
}
}
},
"definitions": {
"getChecklistHistoryDetailsReq": {

                        "description": "",
                        "type": "object",
                        "properties": {
                            "Body": {
                                "type": "object",
                                "properties": {
                                    "getChecklistHistoryDetails": {
                                        "type": "object",
                                        "properties": {
											"Id": {
                                                "type": "string",
                                                "minLength": 1
                                            },
											"OperationHeaderId": {
                                                "type": "string",
                                                "minLength": 1
                                            },
											"OriginCode": {
                                                "type": "string",
                                                "minLength": 1
                                            }
                                        },
                                        "required": [
											"Id",
											"OperationHeaderId",
											"OriginCode"
                                        ]
                                    }
                                },
                                "required": [
                                    "getChecklistHistoryDetails"
                                ]
                            }
                        },
                        "required": [
                            "Body"
                        ]
                    
	}
}

}

Please let me know if you need any more info.

Regards,
Santosh

@santoshghalsasi
Copy link

santoshghalsasi commented Jun 29, 2017

Hi @shockey,
Can you please let me know by when will you be pushing this fix, any tentative timelines?

Many Thanks,
Santosh

@shockey
Copy link
Contributor

shockey commented Jun 29, 2017

Hey folks,

No promises on a timeline, but I'm working on this today. I think I've gotten to the bottom of it.

I'm only able to reproduce this by loading a spec with the text input in the Explore bar. Loading the spec via config should let you work around this problem.

@santoshghalsasi and @pjfanning: are you loading your specs by pasting the URL into the Explore bar? If so, can you try loading your spec by adding ?url=[your url] to your address bar instead, and let me know if there's a difference? If not, please let me know how you provide your spec to Swagger-UI.

@shockey shockey added In progress and removed Ready labels Jun 29, 2017
@pjfanning
Copy link
Author

@shockey In a quick test with http://petstore.swagger.io, I seem to see the behaviour that you describe. My swagger json only has HTTPS scheme (but the swagger.json itself is fetched from a HTTP endpoint).
Entering swagger.json URL into the text box, seems to lead to the HTTPS scheme being ignored. Using the http://petstore.swagger.io/?url=http://localhost:8080/api-docs/swagger.json approach, seems to lead to the HTTPS scheme being used correctly in the Try It calls.

@shockey
Copy link
Contributor

shockey commented Jun 29, 2017

Great, you should be able to lean on that as a workaround while we get this patched.

It looks like Swagger-UI is passing a bad value for the scheme dropdown once a second spec is loaded into the UI - it incorrectly hangs onto the value from the first spec. We give the scheme dropdown priority when we decide what scheme to use for a Try-It-Out request, so that bad value overrides all other indicators (schemes array in spec, scheme the spec was loaded from, etc).

@shockey
Copy link
Contributor

shockey commented Jun 29, 2017

This should be fixed in master.

Please note that the changes won't be live on Petstore or in the distributed packages until we do our next release, which will be next week.

If you need this fix ASAP, you can clone the repository and build the project for your own use.

Thanks for the help with identifying this, @pjfanning and @santoshghalsasi!

@santoshghalsasi
Copy link

Hi @shockey,
Thank you for the fix and glad that I could contribute in some way. :) I have not used github much so don't know the process to build the project. Will try to read around and see how that is done.

Regards,
Santosh

@shockey
Copy link
Contributor

shockey commented Jul 3, 2017

@santoshghalsasi No worries. Here's an overview:

You'll need git, node 6 or newer, and npm installed on your system.

  • Clone the swagger-ui repository
  • Make sure you're on the master branch (you should be by default)
  • run npm run build

Unless you run into some errors, you should end up with some fresh files in the dist folder of the repository you cloned. You can open up the index.html file in the dist folder directly in your browser in order to use the copy of Swagger-UI you just generated.

This is a pretty standard setup for a JavaScript project, so you shouldn't have much trouble Googling your way through it. Feel free to open a ticket if you're having a problem running the build.

Thanks again!

@santoshghalsasi
Copy link

@shockey - Thank you for the direction. I could get it imported and make it work. I can now see that the URL is being constructed with 'https'.

Thanks,
Santosh

@santoshghalsasi
Copy link

santoshghalsasi commented Jul 3, 2017

Hi @shockey - I am seeing a special character 'A' embedded at the end of each parameter name in the UI like below for my specs -
Authorization *required
string

It was not there previously. Can you please let me know the possible reason behind this?

Thanks,
Santosh

@shockey
Copy link
Contributor

shockey commented Jul 3, 2017

@santoshghalsasi, I opened the spec that you provided and I'm not seeing that happen:

image

If this is happening consistently, please consider opening a new Github issue that better describes how to reproduce the problem. Screenshots would be helpful as well.

@santoshghalsasi
Copy link

santoshghalsasi commented Jul 4, 2017

@shockey, We had done some changes in the index.html file in order to make it work properly on the sharepoint and pick and load the specs dynamically. I added the encoding configuration(given below) in that file and it seems to have resolved the problem. I will let this tested by my team and will get back to you in case we need any more info. I hope addition of this encoding configuration is fine -

<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>

Thanks,
Santosh

@lock lock bot locked and limited conversation to collaborators Jul 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants