Skip to content

Defaults are not applied when using $refs in json schema #22600

Closed
@fischeversenker

Description

@fischeversenker

🐞 Bug report

Command

  • ng generate / schematics

Is this a regression?

I don't know, sorry.

Description

I noticed that the schematics CLI is applying defaults in a schema differently, depending on whether a property is defined "inline" or defined in a reference using $ref. This applies to both ng generate and schematics.

Assume this schema for a schematic:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "additionalProperties": false,
  "definitions": {
    "Reference": {
      "default": false,
      "type": "boolean"
    }
  },
  "properties": {
    "inlineProperty": {
      "default": false,
      "type": "boolean"
    },
    "referencedProperty": {
      "$ref": "#/definitions/Reference"
    }
  },
  "type": "object"
}

When a schematic that uses this schema is called without any arguments, the options object that it receives looks like this:

{ inlineProperty: false }

Note, that it does not contain the referencedProperty, even though it uses the same exact schema - only it's referencing it. If the contents of the reference are copied into the referencedProperty, then the same default-logic is applied to it and the options object turns into this:

{ inlineProperty: false, referencedProperty: false }

I would expect the schematics schema validation to apply the same logic for defaults, regardless of whether properties are defined "inline" or as a reference.

🔬 Minimal Reproduction

I provided a minimal setup in this repository. Follow the steps in the README.md to reproduce this issue.

🌍 Your Environment


@angular-devkit/schematics-cli   13.2.0
@angular-devkit/core             13.2.0
@angular-devkit/schematics       13.2.0
typescript                       4.3.5

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions