json-schema-viewer icon indicating copy to clipboard operation
json-schema-viewer copied to clipboard

External Refs Resolution

Open azriel46d opened this issue 1 year ago • 2 comments

Hi, given that external refs are not supported, i've tested out a local setup in which the only change im doing is adjusting the loadUrl functionality such that it utilises json-refs library. for which all references are resolved.

Old Code

 private loadUrl(url: string): void {
      fetch(url)
          .then(resp => resp.json())
          .then(schema => this.setState({ result: { schema, currentUrl: url } }))
          .catch(e => this.setState({ result: { currentUrl: url, schema: { message: e.message }}}));
   }

New Code

 private loadUrl(url: string): void {
      jsonRefs.resolveRefsAt(url).then((result) => 
         this.setState({ result: { schema: result.resolved as JsonSchema, currentUrl: url } })
      ).catch(e => this.setState({ result: { currentUrl: url, schema: { message: e.message }}})); 
  }

would such a PR be accepted?
maybe utilising a toggle in the homepage wether refs should be resolved or not, would switch between the two ?

azriel46d avatar Nov 16 '23 14:11 azriel46d

Hmm, the idea of this App, for performance reasons, was never to have to load external schemas once your schema was successfully downloaded: you either got everything or nothing.

Is it possible to bundle your external schema fully before providing it to this tool?

However, that said, can you paste a screenshot of what the error state looks like in the event that a sub-referenced schema fails to load?

robertmassaioli avatar Nov 21 '23 21:11 robertmassaioli

regs resolution would be very useful. most schemas in the Spatio Temporal Asset Catalog ecosystem use refs

this fails https://raw.githubusercontent.com/crim-ca/mlm-extension/main/json-schema/schema.json

Screenshot 2024-07-26 at 12 33 22 PM

rbavery avatar Jul 26 '24 19:07 rbavery