错误:原理图输入未根据架构进行验证:{...},数据路径“”不得具有其他属性(...)

问题描述 投票:0回答:1

我正在创建自定义原理图,我想用它在单独的 Angular 项目中生成组件文件。为此,我使用依赖于 schema.json 文件中声明的可选参数的条件模板。问题是,当我尝试生成这样的组件时:

ng g 订阅组件:组件 --foo --path="/app" 新

我收到以下错误:

Error: Schematic input does not validate against the Schema: {"foo":true,"path":"/app","name":"new"}
Errors:

Data path "" must NOT have additional properties(foo).

这是我的 schema.json 文件:

{
"$schema": "http://json-schema.org/schema",
"$id": "Schema",
"type": "object",
"properties": {
    "path": {
        "type": "string",
        "format": "path"
    },
    "name": {
        "type": "string",
        "$default": {
            "$source": "argv",
            "index": 0
        }
    },
    "foo": {
        "type": "boolean",
        "default": false
    }
},
"required": [
    "name"
]


 } 

我的 Angular 项目中的 collection.json 文件:

{
  "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
  "schematics": {
    "component": {
      "aliases": [
        "c"
      ],
      "description": "A blank schematic.",
      "factory": "./subscription-component/index#subscriptionComponent",
      "schema": "./subscription-component/schema.json"
    }
  }
}

还有我的文件:

import { Component, OnInit } from '@angular/core';

@Component({
    selector: 'app-<%= dasherize(name) %>-component',
    templateUrl: './<%= dasherize(name) %>.component.html',
    styleUrls: ['./<%= dasherize(name) %>.component.scss'],
})
export class <%= classify(name) %>Component implements OnInit <% if (foo) {%>, OnDestroy <% }%> {

<% if (foo) {%>
private readonly subscription: Subscription = new Subscription();
<% }%>

constructor() { }

ngOnInit(): void {
}

<% if (foo) {%>
ngOnDestroy(): void {
    this.subscription.unsubscribe();
}
<% }%>
}

知道如何解决这个问题吗?

angular angular-cli angular-schematics
1个回答
0
投票

我从 angular.json 中删除了以下代码,它对我有用。

"schematics": {
 "@schematics/angular:component": {
   "styleext": "scss"
  }
},
© www.soinside.com 2019 - 2024. All rights reserved.