glideapps/quicktype

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

已关闭

#1,239 创建于 2019年5月23日

 (1 条评论) (0 个反应) (0 位负责人)TypeScript (968 个派生)batch import
Pythonbuggood first issue

仓库指标

星标
 (10,867 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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)

贡献者指南