Repository: Parquery/swagger-to

Issue:
ValueError: Expected the value in a schema to be a string, but got: <class 'swagger_to.swagger.RawDict'>
if definitions properties has name with description, will cause this issue
```
  DeviceDefineInfoRes:
    type: object
    discriminator: ''
    properties:
      createPerson:
        type: string
      createTime:
        type: string
      description:
        type: string
      id:
        type: string
      manufacturer:
        type: string
      name:
        type: string
      number:
        type: string
      productTypeCode:
        type: integer
        format: int32
      updatePerson:
        type: string
      updateTime:
        type: string
    description: ''
```
<img width="729" alt="20211027104911" src="https://user-images.githubusercontent.com/17000812/138991549-b512b07d-f789-4df9-8436-92e87c698d4c.png">

*(@mristin, 2021-10-27: added markers for multi-line code)*

Discussion:
mristin: @AkuPython thanks a ton for this!

Would you mind adding your example from above as a unit test?
AkuPython: @mristin 2 tests added.
The "parsing" test passes both pre and post PR (it's just proving the validator is working for the use case).
The "intermediate" test fails pre PR, and passes post PR.

1. parsing ... confirm: info->description->(not string)==failure (per error.txt - may be cumbersome to maintain...?)
2. intermediate ... confirm: definitions->foo->description->(not string)==success

Patch:
diff --git a/swagger_to/intermediate.py b/swagger_to/intermediate.py
index c4dc496..8a26b91 100644
--- a/swagger_to/intermediate.py
+++ b/swagger_to/intermediate.py
@@ -432,12 +432,7 @@ def _recursively_strip_descriptions(schema_dict: MutableMapping[str, Any]) -> Mu
     new_schema_dict = collections.OrderedDict()  # type: MutableMapping[str, Any]
 
     for key, value in schema_dict.items():
-        if key.lower() == 'description':
-            if not isinstance(value, str):
-                raise ValueError("Expected the value in a schema to be a string, but got: {}".format(type(value)))
-
-            new_schema_dict[key] = value.strip()
-        elif isinstance(value, list):
+        if isinstance(value, list):
             lst = []  # type: List[Any]
             for item in value:
                 if isinstance(item, (dict, collections.OrderedDict)):
@@ -451,6 +446,11 @@ def _recursively_strip_descriptions(schema_dict: MutableMapping[str, Any]) -> Mu
             new_schema_dict[key] = _recursively_strip_descriptions(schema_dict=value)
         elif isinstance(value, swagger_to.swagger.RawDict):
             new_schema_dict[key] = _recursively_strip_descriptions(schema_dict=value)
+        elif key.lower() == 'description':
+            if not isinstance(value, str):
+                raise ValueError("Expected the value in a schema to be a string, but got: {}".format(type(value)))
+
+            new_schema_dict[key] = value.strip()
         else:
             new_schema_dict[key] = value
 


Test patch:
diff --git a/tests/cases/intermediate/definitions_item_description_as_object/endpoints.json b/tests/cases/intermediate/definitions_item_description_as_object/endpoints.json
new file mode 100644
index 0000000..1298ed4
--- /dev/null
+++ b/tests/cases/intermediate/definitions_item_description_as_object/endpoints.json
@@ -0,0 +1,44 @@
+[
+  {
+    "consumes": [],
+    "description": "",
+    "line": 14,
+    "method": "get",
+    "operation_id": "get_foo",
+    "parameters": [
+      {
+        "description": "The foo id",
+        "in_what": "path",
+        "json_schema": {
+          "identifier": "",
+          "text": ""
+        },
+        "line": 21,
+        "name": "foo_id",
+        "required": true,
+        "typedef": {
+          "description": "",
+          "format": "",
+          "identifier": "",
+          "json_schema": {
+            "identifier": "",
+            "text": ""
+          },
+          "line": 0,
+          "pattern": "",
+          "type": "string"
+        }
+      }
+    ],
+    "path": "/api/v1/foo",
+    "produces": [],
+    "responses": {
+      "200": {
+        "code": "200",
+        "description": "Success",
+        "line": 17,
+        "typedef": null
+      }
+    }
+  }
+]
\ No newline at end of file
diff --git a/tests/cases/intermediate/definitions_item_description_as_object/intermediate_params.json b/tests/cases/intermediate/definitions_item_description_as_object/intermediate_params.json
new file mode 100644
index 0000000..9e26dfe
--- /dev/null
+++ b/tests/cases/intermediate/definitions_item_description_as_object/intermediate_params.json
@@ -0,0 +1,1 @@
+{}
\ No newline at end of file
diff --git a/tests/cases/intermediate/definitions_item_description_as_object/intermediate_typedefs.json b/tests/cases/intermediate/definitions_item_description_as_object/intermediate_typedefs.json
new file mode 100644
index 0000000..0228d9e
--- /dev/null
+++ b/tests/cases/intermediate/definitions_item_description_as_object/intermediate_typedefs.json
@@ -0,0 +1,65 @@
+{
+  "foo": {
+    "description": "",
+    "identifier": "foo",
+    "json_schema": {
+      "identifier": "foo",
+      "text": "{\n  \"title\": \"foo\",\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"id\": {\n      \"description\": \"Identifier\"\n    },\n    \"name\": {\n      \"type\": \"string\",\n      \"example\": \"TestJob\",\n      \"description\": \"Name of the test.\"\n    },\n    \"description\": {\n      \"type\": \"string\",\n      \"example\": \"TestJob\",\n      \"description\": \"Test description.\"\n    }\n  }\n}"
+    },
+    "line": 28,
+    "properties": {
+      "id": {
+        "description": "Identifier",
+        "line": 0,
+        "name": "id",
+        "required": false,
+        "typedef": {
+          "description": "",
+          "identifier": "",
+          "json_schema": {
+            "identifier": "",
+            "text": ""
+          },
+          "line": 31
+        }
+      },
+      "name": {
+        "description": "Name of the test.",
+        "line": 0,
+        "name": "name",
+        "required": false,
+        "typedef": {
+          "description": "",
+          "format": null,
+          "identifier": "",
+          "json_schema": {
+            "identifier": "",
+            "text": ""
+          },
+          "line": 33,
+          "pattern": "",
+          "type": "string"
+        }
+      },
+      "description": {
+        "description": "Test description.",
+        "line": 0,
+        "name": "description",
+        "required": false,
+        "typedef": {
+          "description": "",
+          "format": null,
+          "identifier": "",
+          "json_schema": {
+            "identifier": "",
+            "text": ""
+          },
+          "line": 37,
+          "pattern": "",
+          "type": "string"
+        }
+      }
+    },
+    "required": []
+  }
+}
\ No newline at end of file
diff --git a/tests/cases/intermediate/definitions_item_description_as_object/swagger.yaml b/tests/cases/intermediate/definitions_item_description_as_object/swagger.yaml
new file mode 100644
index 0000000..0d77584
--- /dev/null
+++ b/tests/cases/intermediate/definitions_item_description_as_object/swagger.yaml
@@ -0,0 +1,40 @@
+# This is a valid schema, but the definition...->description object broke swagger-to.
+# Test relates to: https://github.com/Parquery/swagger-to/issues/132
+swagger: '2.0'
+info:
+  description: description
+  version: '1.0'
+  title: An API
+basePath: /api/v1
+tags:
+- name: foo
+  description: description
+paths:
+  /foo:
+    get:
+      operationId: get_foo
+      responses:
+        '200':
+          description: Success
+      tags:
+      - foo
+    parameters:
+    - in: path
+      description: The foo id
+      name: foo_id
+      required: true
+      type: string
+definitions:
+  foo:
+    type: object
+    properties:
+      id:
+        description: Identifier
+      name:
+        type: string
+        example: TestJob
+        description: Name of the test.
+      description:
+        type: string
+        example: TestJob
+        description: Test description.
\ No newline at end of file
diff --git a/tests/cases/parsing/info_description_not_string/errors.txt b/tests/cases/parsing/info_description_not_string/errors.txt
new file mode 100644
index 0000000..e5878bd
--- /dev/null
+++ b/tests/cases/parsing/info_description_not_string/errors.txt
@@ -0,0 +1,11 @@
+"info"/"description":RawDict([('name', 'This is expected to fail!')]) is not of type 'string'
+
+Failed validating 'type' in schema['properties']['info']['properties']['description']:
+    {'description': 'A longer description of the API. Should be different '
+                    'from the title.  GitHub Flavored Markdown is allowed.',
+     'type': 'string'}
+
+On instance['info']['description']:
+    RawDict([('name', 'This is expected to fail!')])
+
+We used the JSON schema of OpenAPI 2 from: https://raw.githubusercontent.com/OAI/OpenAPI-Specification/88cd94419e117b154b67b834fa8e471bb98bd346/schemas/v2.0/schema.json
\ No newline at end of file
diff --git a/tests/cases/parsing/info_description_not_string/swagger.yaml b/tests/cases/parsing/info_description_not_string/swagger.yaml
new file mode 100644
index 0000000..20ba39f
--- /dev/null
+++ b/tests/cases/parsing/info_description_not_string/swagger.yaml
@@ -0,0 +1,28 @@
+# This is invalid schema...
+# It confirms the validator fails at a "description" element that MUST be a string.
+# Test relates to: https://github.com/Parquery/swagger-to/issues/132
+swagger: '2.0'
+info:
+  description:
+    name: This is expected to fail!
+  version: '1.0'
+  title: An API
+basePath: /api/v1
+tags:
+- name: foo
+  description: description
+paths:
+  /foo:
+    get:
+      operationId: get_foo
+      responses:
+        '200':
+          description: Success
+      tags:
+      - foo
+    parameters:
+    - in: path
+      description: The foo id
+      name: foo_id
+      required: true
+      type: string
\ No newline at end of file