angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.72k stars 11.98k forks source link

local schema #11307

Open mina-skunk opened 6 years ago

mina-skunk commented 6 years ago

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

clydin commented 6 years ago

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

mina-skunk commented 6 years ago

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\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

mina-skunk commented 6 years ago

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

mina-skunk commented 6 years ago

@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

gmullerb commented 5 years ago

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

nickbullock commented 4 years ago

Any news?

matheo commented 3 years ago

wow, the extension of local schemas is quite a big deal and it's just not a priority :thinking:

angular-robot[bot] commented 2 years ago

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

angular-robot[bot] commented 2 years ago

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.