glideapps/quicktype

python: invalid code due to comments starting or ending with double quotes

クローズ

#1,239 opened on 2019/05/23

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)TypeScript (968 件のフォーク)batch import
Pythonbuggood first issue

Repository metrics

Stars
 (10,867 個のスター)
PR merge metrics
 (PR metrics pending)

説明

when generating python code, the generated syntax becomes invalid if there are comments (i.e. "description" fields in the JSON schema) that start or end with double quotes

Example

for the JSON schema fragment:

"properties": {
  "type": {
    "description": "type is \"output\"",
    "minLength": 1,
    "oneOf": [
	  {
	    "$ref": "#/definitions/MessageType"
	  }
    ]
  },

the generated (invalid) python 3.7 code fragment is

"""type is "output""""
type: MessageType

Solution

the generator for python should check the first and last character of a documentation-comment (i.e. the "description" field value) -- and if this is the case, the emitted code should "escape" these characters (e.g. prepend/append a newline or space character)

コントリビューターガイド