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

Make schema object compatible with JSON Schema specification #1026

Closed
epoberezkin opened this issue Apr 4, 2017 · 16 comments
Closed

Make schema object compatible with JSON Schema specification #1026

epoberezkin opened this issue Apr 4, 2017 · 16 comments

Comments

@epoberezkin
Copy link

epoberezkin commented Apr 4, 2017

That's is related to #333

Given that all the major differences were removed in version 3, what is the reason to have remaining differences?

  • type as array is just a syntax sugar for anyOf
  • items - what is the reason to not support array syntax? APIs returning tuples and other heterogenous arrays are [regrettably] present. Why spec says items MUST be present? What's wrong with it not being present?
  • patternProperties - together with propertyNames added in draft-06 it is needed to support hash-maps rather than records.

Additional fields in schema are not a problem, but it still beats me why the restrictions are needed - they create nothing but inconvenience. The argument that certain functionality of tools can't be supported for the full JSON schema spec (see #333 (comment) by @fehguy) is a very week one to not support full JSON schema in API spec.

Instead, OpenAPI can say that tools can choose to support full or restricted JSON-schema and make it clear in their documentation.

I understand that it means that the code in some language may not be possible to generate due to the restrictions of those languages. But it should be the problem constrained to the users of that particular language rather than to all users (using more dynamic/loosely typed languages). If I were to need to generate c++ code from OpenAPI spec, the generator would impose these restrictions and I would simplify the API definition file.

Having full JSON-schema spec allowed outweighs the benefit that ALL tools can always work with the schema - I believe it should be left to the developer's discretion to decide whether to use full/restricted schema rather than having "restricted" imposed by OpenAPI as the only possible option. This "nanny state" approach is very frustrating when using this spec.

It would also allow to simplify this spec by simply referencing JSON schema spec instead of redefining it here.

@avkonst
Copy link

avkonst commented Apr 13, 2017

Great justification! I totally agree.

@RobDolinMS RobDolinMS added this to the v3.Next milestone Apr 21, 2017
@MikeRalphson
Copy link
Member

Re: patternProperties - is this any more difficult for tooling to support than additionalProperties ? I ask because I'm trying to ascertain how close we would be for an OpenAPI-described API to be able to serve its own OpenAPI definition via a schema-defined response. I'm using as my example the draft OpenAPI 3.0.x schema under development at google gnostic.

@webron
Copy link
Member

webron commented May 8, 2017

I don't really see the ability to define an OpenAPI definition that accepts an OpenAPI definition as a drive to support patternProperties. There are other reasons to support it, but this is not it.

@Relequestual
Copy link
Contributor

@webron I know @handrews and @philsturgeon have been on OpenAPI steering calls of late, sorry I haven't been able to attend due to travel.

Has there been any further discussion or thoughts on this since 2017?

@Relequestual
Copy link
Contributor

Maybe this is the same as #1443 ?

@philsturgeon
Copy link
Contributor

Correct @Relequestual, this would be taken care of by #1443.

@lpinca
Copy link

lpinca commented Nov 1, 2018

It's a shame that items does not support the array syntax. There is currently no way to define a tuple like

{
  "type": "array",
  "items": [
    { "type": "string" },
    { "type": "string" },
    { "type": "integer" }
  ]
}

The closest thing is

{
  "type": "array",
  "items": {
    "anyOf": [
      { "type": "string" },
      { "type": "string" },
      { "type": "integer" }
    ]
  },
  "minItems": 3,
  "maxItems": 3
}

but ofc it's not the same.

@handrews
Copy link
Member

handrews commented Nov 4, 2018

@lpinca See #1736 - assuming tooling vendors support proper JSON Schema (hopefully more recent versions) as alternativeSchemas, this will be addressed in OAS 3.1.

@lpinca
Copy link

lpinca commented Nov 4, 2018

@handrews awesome! Thank you.

@tedepstein
Copy link
Contributor

tedepstein commented Nov 4, 2018

Why not use an array of object?

{
  "type": "array",
  "items": {
    "type" : "object", 
    "properties": {
      "s1": {
        "type": "string"
      }, 
      "s2": {
        "type": "string"
      },
      "i1": {
        "type": "integer"
      }
    }
  },
  "minItems": 3,
  "maxItems": 3
}

I understand a tuple is not an object, because its members are unnamed. But I never saw a really good reason why it's a problem to name the members.

@lpinca
Copy link

lpinca commented Nov 5, 2018

@tedepstein you are right but the spec i'm working on is for an existing API not a new one, changing it it's a breaking change.

@tedepstein
Copy link
Contributor

@lpinca, thank you for the explanation. I feel better now. :-)

@ikokostya
Copy link

ikokostya commented Jul 10, 2019

Label Post 3.0 Proposal for this issue is not clear.

Looks like version 3 of OpenAPI specification still doesn't support tuple syntax for arrays:

Is it correct?

@ikokostya
Copy link

ikokostya commented Jul 11, 2019

There is another problem: null type is not supported

Refs #1368

@philsturgeon
Copy link
Contributor

I was hoping that alternative schema would be the savior here, but the current approach is not what I hoped it would be: OAI/sig-moonwalk#121

Instead #1977 is a new effort at closing the gap on OpenAPI v3.1 and JSON Schema.

@philsturgeon
Copy link
Contributor

This was fixed in #1977 so we can close this.

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

No branches or pull requests