stoplightio / json-schema-viewer

A JSON Schema viewer React component
Apache License 2.0
175 stars 37 forks source link

feat: consume schema title property #76

Closed P0lip closed 4 years ago

P0lip commented 4 years ago

General rules:

After: image

After: image

{
  "type": "array",
  "title": "Foo"
}

Before: image

After: image

{
  "type": "object",
  "properties": {
    "foo": {
      "$ref": "#/properties/user"
    },
    "user" : {
      "title": "User",
      "properties": {
        "name": {
          "type": "string"
        }
      }
    }
  }
}

Before (eager resolving enabled): image

Before (eager resolving disabled): image

After (eager resolving enabled): image

After (eager resolving disabled): image

{
  "type": "object",
  "properties": {
    "users": {
      "type": "array",
      "items": {
        "$ref": "#/properties/user"
      }
    },
    "user" : {
      "title": "User",
      "properties": {
        "name": {
          "type": "string"
        }
      }
    }
  }
}

Before (eager resolving enabled): image

Before (eager resolving disabled): image

After (eager resolving enabled): image After (eager resolving disabled): image

Remarks:

{
  "type": "string",
  "title": "foo"
}

image

{
  "type": "array",
  "items": {
    "title": "abc",
    "type": "string"
  }
}
marbemac commented 4 years ago

This is 🔥.

One request - if you have not already, could you yalc this into platform v1 and manually inspect a wide variety of the sample-models in explorer to make sure that JSV:

a) does not crash for any of them b) handles the complex use cases represented in that repo nicely


The only thing I'm not sure about is object[User]. The [] kind of throws me off, since it's normally used for arrays. And it's not like when it is an array we show array[object[User]]. Maybe we just show User rather than object[User]?

marbemac commented 4 years ago

Also, I suggest that @mallachari does a pass on the code review.

P0lip commented 4 years ago

This might be unrelated here but I also don't understand why is there an extra level of indentation in one of these cases:

$refs have one extra level of nesting unless you enable eager $ref resolving (which we do have enabled in elements - studio, explorer, docs), so it's not that important.

Basically, when you don't resolve $refs upfront, we retain them in the document, to be resolved later once you expand the row.

image

Upon expansion image

With eager resolving enabled, this is how it looks like image

It's fairly transparent to user - the rendered schema looks like there was no $ref at all. Having said that, the extra nesting level is for the sake of consistency. In our case, however, the effect is rather none, given we have the eager resolving option enabled, so in our case the schema will look like the latter example.

P0lip commented 4 years ago

object - {name} looks tad weird, but hm, getting rid of object may be confusing for some. Don't have any preference. @marbemac what do you think about the proposal @mallachari posted?

marbemac commented 4 years ago

How about object{User} and array[User]? In this case would drop the extra {4} property counts, not sure how useful those really are in any case.

Or User and User[]?

P0lip commented 4 years ago

Or User and User[]?

This looks good to me, but what about other types, i.e strings? array[string]?

P0lip commented 4 years ago

I went with image It feels really cool. No title: image

stoplight-bot commented 4 years ago

:tada: This PR is included in version 3.0.0-beta.25 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

marbemac commented 4 years ago

Looks great! The only small suggestion in the name of consistency might be object[], but we can visit this later - not a big deal.

stoplight-bot commented 3 years ago

:tada: This PR is included in version 3.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: