Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>schema-generatorNew to Visual Studio Code? Get it now.
schema-generator

schema-generator

tianma630

|
481 installs
| (0) | Free
schema生成器
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

schema-generator

在开发模块时,我们需要做一些配置的工作,一般都是先编写scema文件,再编写mock数据。其实这2个工作有一点重复,我们可以从mock数据结构中反推出schema结构,自动生成。

schema生成器就是用来解决这个问题,它可以帮助开发者从繁杂的schema编写工作中解放出来,配置越复杂,提升的效率也就越高,尤其是针对schema不熟悉的同学。

使用

右键mock文件,选择schema生成器

注意

在定义字段名时要用驼峰式,并且要尽量简单,比如商品标题不要用item_title, 而是用itemTitle,但最佳的方案是title,这样在自动映射标题的更有可能被匹配上。

在编写mock数据的时候也要遵守shema本身的一些规范,比如:

  • 不要直接在一级json中直接编写具体的配置字段。
# wrong
{
  "id": 1,
  "title": "hello",
  "price": 12
}
# right
{
  "item": {
    "id": 1,
    "title": "hello",
    "price": 12
  }
}
  • 在数组中只能放对象,而且不要为空
# wrong
{
  "items": [1, 2, 3]
}

# wrong
{
  "items": []
}

# wrong
{
  "items": [
    [
      {id: 1}
    ]
  ]
}
# right
{
  "items": [
    {"id": 1},
    {"id": 2},
    {"id": 3}
  ]
}
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft