小编kim*_*kim的帖子

JSON Schema:使用 require 读取文件时删除多个 $ref

我有一个 json 模式定义了几个属性。我已将其中 2 个属性移至定义,并引用了它们。我这样做是因为我想将它们组合在一起并以通用方式对这些属性进行一些测试。这工作正常,所有 json 数据都像以前一样处理。

但是,我注意到当我将 json 模式文件读入我的 javascript 文件时,我只看到最后一个 $ref。我不知道这是什么原因。我真的需要知道所有引用的属性。

这是我的 json 模式的一个片段(在文件 schemas/schema1.json 中):

{
    "type": "object",
    "properties": {
         "$ref": "#/definitions/groupedProperties/property1",
         "$ref": "#/definitions/groupedProperties/property2"
    },
    "definitions": {
        "groupedProperties": {
            "type": "object",
            "properties": {
                "property1": {
                    "type": "string"
                },
                "property2": {
                    "type": "string"
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我将它读入我的 js 文件中(在文件 test.js 中):

var schemas = requireDir('./schemas')
for (var prop in schemas['schema1'].properties) {
    console.log(prop)
}
Run Code Online (Sandbox Code Playgroud)

当我从我的 js 文件迭代模式中的属性时,我只能看到一个 $ref。我想这是因为它认为属性名称是 '$ref' 并且只能有唯一的名称。是否有某种方式我需要需要这个文件,以便第一个 $ref 不会被破坏?

编辑:我的语法没有通过 json 模式验证器,虽然我不确定为什么,所以我决定做一些不同的事情,而不是为此而苦苦挣扎。我想要的只是一种对某些属性进行分组的方法,因此我将这些属性放回到主模式中,并将定义更改为仅包含该组的属性名称的枚举。所以现在我的架构看起来像:

{
    "type": …
Run Code Online (Sandbox Code Playgroud)

javascript jsonschema

5
推荐指数
2
解决办法
1714
查看次数

在 angular13 中运行 jest:模块“DynamicTestModule”导入了意外值“TranslateModule”。请添加@NgModule注释

我有一个 Angular 12 项目的测试,效果很好。我已将项目升级到 Angular 13,但现在它们不起作用。

这是我的测试文件:

import { Component } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { GlobalTestingUtilities } from './global-testing-utilities';

@Component({
  template: `
    <div id="test-div-with-click-event-id"
     class="test-div-with-click-event-class"
     (click)="onTestDivClick()">
    </div>
  `
})
class ButtonClickTestComponent {
   public onTestDivClick(): void {}
}

describe('GlobalUtilities', () => {
  let component: ButtonClickTestComponent;
  let fixture: ComponentFixture<ButtonClickTestComponent>;
  let testTranslateService: TranslateService;
  const globalTestingUtilitesInstance = new GlobalTestingUtilities();

  beforeEach(waitForAsync(() => {
    TestBed.configureTestingModule({
      declarations: [
        ButtonClickTestComponent
      ], …
Run Code Online (Sandbox Code Playgroud)

jestjs angular13

5
推荐指数
2
解决办法
3546
查看次数

标签 统计

angular13 ×1

javascript ×1

jestjs ×1

jsonschema ×1