bugdown: Don't show path params as data in curl example.

With test added by tabbott.
This commit is contained in:
Vishnu Ks
2019-10-03 13:02:51 +00:00
committed by Tim Abbott
parent bfd5f4066a
commit 30ad650afb
2 changed files with 39 additions and 2 deletions

View File

@@ -138,6 +138,8 @@ def generate_curl_example(endpoint: str, method: str,
lines.append(" -u %s:%s" % (auth_email, auth_api_key))
for param in openapi_params:
if param["in"] == "path":
continue
param_name = param["name"]
if param_name in exclude:
continue

View File

@@ -650,6 +650,30 @@ class TestCurlExampleGeneration(ZulipTestCase):
spec_mock_using_object = {
"paths": {
"/endpoint": {
"get": {
"description": "Get some info.",
"parameters": [
{
"name": "param1",
"in": "query",
"description": "An object",
"schema": {
"type": "object"
},
"example": {
"key": "value"
},
"required": True
}
]
}
}
}
}
spec_mock_using_param_in_path = {
"paths": {
"/endpoint/{param1}": {
"get": {
"description": "Get some info.",
"parameters": [
@@ -679,7 +703,7 @@ class TestCurlExampleGeneration(ZulipTestCase):
"parameters": [
{
"name": "param1",
"in": "path",
"in": "query",
"description": "An object",
"schema": {
"type": "object"
@@ -700,7 +724,7 @@ class TestCurlExampleGeneration(ZulipTestCase):
"parameters": [
{
"name": "param1",
"in": "path",
"in": "query",
"description": "An array",
"schema": {
"type": "array"
@@ -792,6 +816,17 @@ class TestCurlExampleGeneration(ZulipTestCase):
]
self.assertEqual(generated_curl_example, expected_curl_example)
@patch("zerver.lib.openapi.OpenAPISpec.spec")
def test_generate_and_render_curl_with_object_param_in_path(self, spec_mock: MagicMock) -> None:
spec_mock.return_value = self.spec_mock_using_param_in_path
generated_curl_example = self.curl_example("/endpoint/{param1}", "GET")
expected_curl_example = [
'```curl',
'curl -sSX GET -G http://localhost:9991/api/v1/endpoint/{param1}',
'```'
]
self.assertEqual(generated_curl_example, expected_curl_example)
@patch("zerver.lib.openapi.OpenAPISpec.spec")
def test_generate_and_render_curl_with_object_without_example(self, spec_mock: MagicMock) -> None:
spec_mock.return_value = self.spec_mock_using_object_without_example