mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 03:41:58 +00:00
bugdown: Don't show path params as data in curl example.
With test added by tabbott.
This commit is contained in:
@@ -138,6 +138,8 @@ def generate_curl_example(endpoint: str, method: str,
|
|||||||
lines.append(" -u %s:%s" % (auth_email, auth_api_key))
|
lines.append(" -u %s:%s" % (auth_email, auth_api_key))
|
||||||
|
|
||||||
for param in openapi_params:
|
for param in openapi_params:
|
||||||
|
if param["in"] == "path":
|
||||||
|
continue
|
||||||
param_name = param["name"]
|
param_name = param["name"]
|
||||||
if param_name in exclude:
|
if param_name in exclude:
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -650,6 +650,30 @@ class TestCurlExampleGeneration(ZulipTestCase):
|
|||||||
spec_mock_using_object = {
|
spec_mock_using_object = {
|
||||||
"paths": {
|
"paths": {
|
||||||
"/endpoint": {
|
"/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": {
|
"get": {
|
||||||
"description": "Get some info.",
|
"description": "Get some info.",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
@@ -679,7 +703,7 @@ class TestCurlExampleGeneration(ZulipTestCase):
|
|||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"name": "param1",
|
"name": "param1",
|
||||||
"in": "path",
|
"in": "query",
|
||||||
"description": "An object",
|
"description": "An object",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object"
|
"type": "object"
|
||||||
@@ -700,7 +724,7 @@ class TestCurlExampleGeneration(ZulipTestCase):
|
|||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"name": "param1",
|
"name": "param1",
|
||||||
"in": "path",
|
"in": "query",
|
||||||
"description": "An array",
|
"description": "An array",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "array"
|
"type": "array"
|
||||||
@@ -792,6 +816,17 @@ class TestCurlExampleGeneration(ZulipTestCase):
|
|||||||
]
|
]
|
||||||
self.assertEqual(generated_curl_example, expected_curl_example)
|
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")
|
@patch("zerver.lib.openapi.OpenAPISpec.spec")
|
||||||
def test_generate_and_render_curl_with_object_without_example(self, spec_mock: MagicMock) -> None:
|
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
|
spec_mock.return_value = self.spec_mock_using_object_without_example
|
||||||
|
|||||||
Reference in New Issue
Block a user