Git Product home page Git Product logo

Comments (15)

notEthan avatar notEthan commented on May 22, 2024 1

the choice of X / blank to indicate what's valid is pretty unintuitive to me. the book doesn't even explain "X means valid" (I initially assumed X meant failure). I've applied the magic of unicode to help make this more intuitive-looking. I've also ordered things where valid schemas go first and thrown in explanatory comments.

if then else whole schema
`if` schema validates; `then` schema result applies to the instance. `else` is not applied.
`if` schema fails to validate; `else` schema result applies to the instance. `then` is not applied.

from understanding-json-schema.

 avatar commented on May 22, 2024 1

I was just looking into this myself and was going to do a PR. I don't know if @notEthan or @HertzDevil are still interested. Looking at the source it looks like this has almost been completely addressed (without the unicode characters, and missing 1 row), but perhaps it's just not been published.

Here's what the source currently looks like:

==== ==== ==== ============
if   then else whole schema
==== ==== ==== ============
          X    X
     X          
     X    X    X
X               
X         X     
X    X         X
X    X    X    X
==== ==== ==== ============

The only suggestion I'd make is to put the first line in. I'll submit a PR with this completed and with the unicode.

from understanding-json-schema.

notEthan avatar notEthan commented on May 22, 2024

the source, since github doesn't make that easy to see:

<table>
  <tr>
    <td>if</th>
    <td>then</th>
    <td>else</th>
    <td></th>
    <td>whole schema</th>
  </tr>
  <tr>
    <td colspan=5>`if` schema validates; `then` schema result applies to the instance. `else` is not applied.</td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td colspan=5>`if` schema fails to validate; `else` schema result applies to the instance. `then` is not applied.</td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
</table>

from understanding-json-schema.

mdboom avatar mdboom commented on May 22, 2024

Any interest in turning this into a pull request?

from understanding-json-schema.

dima1206 avatar dima1206 commented on May 22, 2024

There is also a mistake before the table: "If if is invalid, else must also be valid". I guess it should be "If if is invalid, else must be valid" (removed "also").

About the table. It can be reduced using "-" or something similar, so it would be like this:

if | then | else || whole schema
--------------------------------
❌ |  --  |  ❌  ||    ❌
❌ |  --  |  ✅  ||    ✅
✅ |  ❌  |  --  ||    ❌
✅ |  ✅  |  --  ||    ✅

from understanding-json-schema.

karenetheridge avatar karenetheridge commented on May 22, 2024

I like reducing the cases together to show that the results of the other branch (of "then" and "else") don't matter. Indeed, the implementation won't even run them, which is a distinction that should be made clear to the user.

from understanding-json-schema.

dima1206 avatar dima1206 commented on May 22, 2024

Just remembered, that when I was reading, I also was wondering about omitting else. Seeing example at the end of the page, I guess that it works the same as {} schema. Here is one more variation of the table (not sure about then):

if | then  | else  || whole schema
--------------------------------
❌ |  --   |  ❌   ||    ❌
❌ |  --   |  ✅   ||    ✅
❌ |  --   |omitted||    ✅
✅ |  ❌   |  --   ||    ❌
✅ |  ✅   |  --   ||    ✅
✅ |omitted|  --   ||    ✅/incorrect schema

Maybe also add some explanation about omitting.

from understanding-json-schema.

notEthan avatar notEthan commented on May 22, 2024

thanks for picking this up, @mgwelch.

I do agree it's simpler with the unused control paths collapsed, but not strongly opinionated about it.

from understanding-json-schema.

 avatar commented on May 22, 2024

I do like the collapsed as well. I can make the change. Adding omitted is very important as well. I didn't even realize that was a valid option.

from understanding-json-schema.

 avatar commented on May 22, 2024

Here is one more variation of the table (not sure about then):

Wouldn't omitting then work just like else? It seems your table is correct, I just didn't understand your trailing comment: "/incorrect schema"

from understanding-json-schema.

 avatar commented on May 22, 2024

Just remembered, that when I was reading, I also was wondering about omitting else. Seeing example at the end of the page, I guess that it works the same as {}

It might keep the table simpler to NOT call out the omitted cases but instead mention (if true) that an omitted schema is always valid since it works the same as {}.

The reason to not call it out in the table is that it gets complicated representing both "don't care" cases and omitted cases. Or at least I think it gets more complicated to see a boolean truth table with 4 different entries in the cells.

Perhaps we could put a footnote on the ✅ cases for then and else indicating that it includes the omitted cases.

from understanding-json-schema.

dima1206 avatar dima1206 commented on May 22, 2024

I just didn't understand your trailing comment: "/incorrect schema"

As I said, I'm not sure about omitting then, so depending on that, there should be either '✅' or 'incorrect schema'. I guess(!) that it should be the first one. JSON schemas are new to me so don't take my words as truth.

Maybe you're right that omitting shouldn't complicate the table, and adding footnote would be enough.

from understanding-json-schema.

 avatar commented on May 22, 2024

As I said, I'm not sure about omitting then

The spec I guess is clear enough (it took me a few times to read it to understand that it is clear):

if

This keyword's value MUST be a valid JSON Schema.

This validation outcome of this keyword's subschema has no direct
effect on the overall validation result.  Rather, it controls which
of the "then" or "else" keywords are evaluated.

Instances that successfully validate against this keyword's subschema
MUST also be valid against the subschema value of the "then" keyword,
if present.

Not that it's guaranteed to be a correct implementation, but I did confirm with ajv that this instance

{
    "id": 0,
    "name": "Michael"
}

conforms to this schema

{
  "if": {
    "properties": {
      "id": { "const": 0 }
    }
  },
  "else": {
    "properties": {
      "name": {
        "type": "number"
      }
    }
  }
}

from understanding-json-schema.

 avatar commented on May 22, 2024

@mdboom I've submitted a PR but there are issues with unicode characters and Latex. In the PR (#127) I post a screen shot of an alternative.

from understanding-json-schema.

jdesrosiers avatar jdesrosiers commented on May 22, 2024

Fixed by #143

from understanding-json-schema.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.