Angular-cli: local schema

Created on 19 Jun 2018  路  6Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request

Area

- [X] devkit
- [ ] schematics

Versions

node --version v8.11.1
npm --version 6.1.0

Repro steps

{
  "$schema": "http://json-schema.org/draft-06/schema",
  "title": "My builder schema",
  "type": "object",
  "allOf": [
    {
      "$ref": "file://../../node_modules/@angular-devkit/build-angular/src/browser/schema.json#"
    }
  ],
  "properties": {
    "myProp": {
      "type": "object"
    }
  },
  "additionalProperties": false
}

or

{
  "$schema": "http://json-schema.org/draft-06/schema",
  "title": "My builder schema",
  "type": "object",
  "allOf": [
    {
      "$ref": "../../node_modules/@angular-devkit/build-angular/src/browser/schema.json#"
    }
  ],
  "properties": {
    "myProp": {
      "type": "object"
    }
  },
  "additionalProperties": false
}

The log given by the failure

Protocol "file:" not supported. Expected "http:"
Error: Protocol "file:" not supported. Expected "http:"
at new ClientRequest (_http_client.js:131:11)
at request (http.js:38:10)
at Object.get (http.js:42:13)
at Promise (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\src\json\schema\registry.js:74:18)
at new Promise ()
at CoreSchemaRegistry._fetch (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\src\json\schema\registry.js:73:16)
at Object.loadSchema (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\src\json\schema\registry.js:61:39)
at loadMissingSchema (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\node_modules\ajv\lib\compile\async.js:67:64)
at _compileAsync (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\node_modules\ajv\lib\compile\async.js:56:48)
at C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\node_modules\ajv\lib\compile\async.js:32:34

or

Unable to determine the domain name
Error: Unable to determine the domain name
at new ClientRequest (_http_client.js:85:13)
at request (http.js:38:10)
at Object.get (http.js:42:13)
at Promise (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\src\json\schema\registry.js:74:18)
at new Promise ()
at CoreSchemaRegistry._fetch (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\src\json\schema\registry.js:73:16)
at Object.loadSchema (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\src\json\schema\registry.js:61:39)
at loadMissingSchema (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\node_modules\ajv\lib\compile\async.js:67:64)
at _compileAsync (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\node_modules\ajv\lib\compile\async.js:56:48)
at C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\node_modules\ajv\lib\compile\async.js:32:34

Desired functionality

$ref relative schemas

devkiarchitect low broken bufix

Most helpful comment

The current implementation only use http for asynchronous schema compilation using the loadSchema option of ajv, then we are only able to reference schemas using _http_ (for which there no really extended usefullness, most schema json on the web are available using https), neither https nor a local file are available,

       this._ajv = ajv({
            formats: formatsObj,
            loadSchema: (uri) => this._fetch(uri),
            schemaId: 'auto',
            passContext: true,
        });

The implementation of the _fetch in registry.js should allow to handle file://(possibly simply using the path module + a require()), http:// (with the http module, already implemented), https:// (with the https module). This way there will be freedom of choice when build schemas

All 6 comments

take off the protocol. file:// is not support by ajv and not needed by the specification. For additional examples, please see here: https://spacetelescope.github.io/understanding-json-schema/structuring.html

With out file:// you get:

Unable to determine the domain name
Error: Unable to determine the domain name
at new ClientRequest (_http_client.js:85:13)
at request (http.js:38:10)
at Object.get (http.js:42:13)
at Promise (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\src\json\schemaregistry.js:74:18)
at new Promise ()
at CoreSchemaRegistry._fetch (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\src\json\schemaregistry.js:73:16)
at Object.loadSchema (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\src\json\schemaregistry.js:61:39)
at loadMissingSchema (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\node_modulesajv\lib\compile\async.js:67:64)
at _compileAsync (C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\node_modulesajv\lib\compile\async.js:56:48)
at C:\Users\User\source\repos\AutoFluent-Cloud\autofluent-clients\node_modules\@angular-devkit\core\node_modulesajv\lib\compile\async.js:32:34

@clydin please reopen as it is still not possible to use relative schema references.

@clydin also following https://spacetelescope.github.io/understanding-json-schema/structuring.html I added an id but now get Request failed. Status Code: 404, I don't want to publicly host my schema

The current implementation only use http for asynchronous schema compilation using the loadSchema option of ajv, then we are only able to reference schemas using _http_ (for which there no really extended usefullness, most schema json on the web are available using https), neither https nor a local file are available,

       this._ajv = ajv({
            formats: formatsObj,
            loadSchema: (uri) => this._fetch(uri),
            schemaId: 'auto',
            passContext: true,
        });

The implementation of the _fetch in registry.js should allow to handle file://(possibly simply using the path module + a require()), http:// (with the http module, already implemented), https:// (with the https module). This way there will be freedom of choice when build schemas

Any news?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JanStureNielsen picture JanStureNielsen  路  3Comments

IngvarKofoed picture IngvarKofoed  路  3Comments

jbeckton picture jbeckton  路  3Comments

rajjejosefsson picture rajjejosefsson  路  3Comments

hartjo picture hartjo  路  3Comments