loopbackio / loopbackio/loopback-next
Support comments in JSON files
还没有人认领这个 Issue。
- 主要语言
- TypeScript
- 星标
- 5.1k
- 派生
- 1.1k
- 平均合并
- 2 天 21 小时
- 30 天内合并 PR
- 27
描述
@bajtos commented on Wed Apr 29 2015
At the moment, configuration files are using JSON, which does not support comments. We should consider using a JSON superset that supports comments, for example http://json5.org/ or http://yaml.org/ or at least apply https://www.npmjs.com/package/strip-json-comments when loading JSON files.
@ritch commented on Wed Apr 29 2015
The problem with stripping comments is that once you JSON.stringify() the content back into the file ...it removes all the comments. Its a 1/2 solution IMO.
@bajtos commented on Wed Apr 29 2015
Ouch, that's a good point, I completely forgot about editing JSON programatically from loopback-workspace. I'm removing the "Beginner Friendly" label then.
@sam-github commented on Wed Apr 29 2015
The round-tripping is the more pervasive problem.
The reason I'm looking for comments is there doesn't appear to be a good place to comment on the structure and meaning of the API. There is the description field, but that's pretty limited.
@bajtos commented on Wed Apr 29 2015
There is the description field, but that's pretty limited.
FWIW, the description field supports an array of strings as a value, if that's of any help.
// single-line
description: "a short one"
// multi-line
description: [
"line1",
"line2"
]
@sam-github commented on Wed Apr 29 2015
And it allows arbitrary properties, right? So, I could add a comment: property anywhere, and LB would ignore it, right? I could try doing that. Though my dividing paragraphs into arrays of strings is a bit messy to edit, though fine to read.
@bajtos commented on Thu Apr 30 2015
And it allows arbitrary properties, right? So, I could add a
comment:property anywhere, and LB would ignore it, right?
Yes, I believe so.
@juodumas commented on Mon Feb 01 2016
Comments in config.json and others would be very nice. Maybe at least allow skipping config.json when config.local.js exists? Currently if I have config.local.js and have no config.json, loopback complains and doesn't load the config.
@tohagan commented on Thu Oct 05 2017
hjson might what you're looking for. Developers could opt to rename thier .json files to .hjson OR since hjson is backward compatible you'd just replace the JSON parser.
The hjson API includes the ability to preserve comments in editing round trips.
@tohagan commented on Thu Oct 05 2017
Many other apps provide sample configuration values and documentation as comment inside their configuration files. You also often want to keep old settings but comment them out or explanations of settings (e.g. reference to an issue number). Not having comments for configuration (or any code for that matter) is IMHO a major limitation for Loopback both for getting started and for on going code maintenance of JSON files. So I think adding this feature would be a valuable win.
An issue may be that some integrated tools would break as they would expect a standard JSON format but this should not be a deal breaker if they are open source.
@bajtos commented on Thu Oct 05 2017
@tohagan I agree with you. I am afraid we don't have bandwidth to address this in the near future, as our main focus is on the next version of LoopBack - see https://strongloop.com/strongblog/announcing-loopback-next/. Would you like to contribute this improvement yourself? I think there are two big pieces to make this happen:
-
Modify loopback-boot to support config files containing comments. You will need to make the changes in the
2.xbranch, as themasterbranch is tracking a 3.0 version that hasn't been released yet. -
Modify loopback-workspace to preserve comments when editing configuration JSON files. This package is used by all our tooling, from loopback-cli to IBM API Connect Editor. This second part will be probably tricky - the design of loopback-workspace has a steep learning curve, and we will need to find a way how to allow REST clients to preserve the comments. Since hjson stores comments are in non-enumerable
__COMMENTS__property, REST clients will not receive them and we may need to somehow merge the data from the client with the original comments when performing updates.
@tohagan commented on Thu Oct 12 2017
@bajtos Would be great to have this in Loopback Next!
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 loopback-boot 2.x 分支开始,定位配置文件加载逻辑,然后检查 loopback-workspace 的 JSON 编辑和 REST 更新路径。当配置注释能够被接受,并在程序化编辑过程中得到保留(包括通过 tooling clients 进行的更新)时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 领域
- tooling
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100