Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Schema Support Proposal #741

Closed
wants to merge 1 commit into from
Closed

JSON Schema Support Proposal #741

wants to merge 1 commit into from

Conversation

webron
Copy link
Member

@webron webron commented Jul 21, 2016

WIP

This PR will build up to a proposal for the changes in handling JSON Schema in OpenAPI.next.
This comment will be modified as the proposal evolves.

At this time, please avoid adding comments to this proposal. Comments will be deleted. When the status of the PR changes, comments and discussions would be welcome.

This PR does not cover representation of XML and alternative data structures.

Great work starts with a single character.
This was referenced Jul 21, 2016
@ralfhandl
Copy link
Contributor

@fehguy Using allOf might make it more difficult for tools.

Following the discussion in #556 I experimented with description nested within JSON References versus allOf. In the allOf variant both Swagger UI and Swagger Editor were more likely to "give up" on type expansion and just mark a property's type as "undefined", whereas additional properties within JSON References allowed correct expansion of types.

@tedepstein
Copy link
Contributor

tedepstein commented Aug 2, 2016

There's a conflict between the allOf semantics and the default value of false for additionalProperties.

Consistent with JSON schema, an allOf schema is valid "if and only if it is valid against all the schemas in this keyword's value."

In JSON Schema, this example:

{
  "a" : "Jack",
  "b" : "Jill"
}

...is valid against this schema:

    allOf:
    - type: object
      properties:
        a:
          type: string
    - type: object
      properties:
        b:
          type: string

This holds true because:

  • The example is valid w.r.t. the first schema (defining only property 'a'); and
  • The example is valid w.r.t. the second schema (defining only property 'b'); and

But both of those conditions depend on the default value of true for additionalProperties. If additionalProperties were false, then the example wouldn't be valid w.r.t. either of those subschemas:

  • The example is invalid w.r.t. the first schema because the additional property b is disallowed.
  • The example is invalid w.r.t. the second schema because the additional property a is disallowed.

IIUC, based on @webron's earlier comments, the intention in the current 2.0 and planned 3.0 versions of OpenAPI is to redefine the default value of additionalProperties to false, and disallow setting it to true.

We can talk about how to resolve this. But first:

  • Is the problem clear enough?
  • @webron, do I understand your earlier comments correctly?

@ePaul
Copy link
Contributor

ePaul commented Aug 3, 2016

@fehguy I think in your format example of type:integer the fallback description is backward (i.e. it should be »type: integer, format: int64 falls back to type:integer«.)

@fehguy
Copy link
Contributor

fehguy commented Aug 3, 2016

@ePaul no, exactly the opposite. If you don't specify the format, the underperscribed type, integer would have a fallback to int64 in my example. integer on its own, is simply ambiguous.

@ePaul
Copy link
Contributor

ePaul commented Aug 4, 2016

@fehguy Hmm, then the text needs to be clearer, I've read it differently. (And the spec would need to say which format is the default for each type.)

My approach would be to say:

  • type: string without format = any JSON string, without any restrictions or special interpretation.
  • type: number without format = any JSON number (= a decimal number with any number of digits before and after the decimal point, possibly represented on wire with e-notation). In Java this would correspond to BigDecimal.
  • type: integer without format = any JSON integer (= a decimal number without a decimal point, with any number of digits, possible represented on wire with e-notation using a positive exponent). In Java this would correspond to BigInteger.

(For types boolean, object and array there are no formats anyways, and null is not a real type.)

And all formats unsupported by an implementation would fall back to those meanings – this allows any application to work around the non-support. This is how I interpreted the current spec anyways.

We could introduce a format: abitrary or similar for this meaning.

@fehguy fehguy self-assigned this Sep 30, 2016
fehguy added a commit that referenced this pull request Oct 7, 2016
@webron webron mentioned this pull request Feb 21, 2017
@webron
Copy link
Member Author

webron commented Feb 22, 2017

Closed in favor of (the now merged) #894.

@webron webron closed this Feb 22, 2017
@webron webron deleted the JSONSchema.next branch February 22, 2017 22:58
AndersDJohnson pushed a commit to AndersDJohnson/OpenAPI-Specification that referenced this pull request Apr 8, 2019
jeremyfiel pushed a commit to jeremyfiel/redocly-cli that referenced this pull request Jul 3, 2024
tatomyr pushed a commit to jeremyfiel/redocly-cli that referenced this pull request Jul 10, 2024
tatomyr pushed a commit to jeremyfiel/redocly-cli that referenced this pull request Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants