preaction / Yancy

The Best Web Framework Deserves the Best Content Management System
http://preaction.me/yancy/
Other
54 stars 21 forks source link

Translate JSON schema "types" array to OpenAPI spec "types" #42

Closed preaction closed 3 years ago

preaction commented 5 years ago

Continued from #38: The types in JSON schema can be an array. Yancy uses this to allow properties to be null. However, OpenAPI does not allow this (either in v2 or v3). In v3, OpenAPI adds a nullable property, but in v2 all properties are assumed to be nullable unless required.

The Yancy collections configuration (and through it, the read_schema schemas) are JSON schemas. The Yancy editor works with OpenAPI schemas, not JSON schemas. To fix this problem, Yancy will need to translated the JSON schemas to OpenAPI schemas when building the editor's OpenAPI schema.

We also need to make sure the documentation is clear: read_schema and collections are JSON schema (and what version we support), openapi and the editor are OpenAPI (and what version we support).

mohawk2 commented 5 years ago

59 adds a bit of doc about this, and also code to convert from OpenAPI to JSON and back.

The position I'm taking currently on array-of-types is that regardless of what swagger.io says, the JSON schema for OpenAPI 2 allows type to be an array. I recall we chatted on IRC about this, and this is a change from that.

What are your thoughts?

preaction commented 5 years ago

The bigger problem is, I think, that while the Perl JSON::Validator / Mojolicious::Plugin::OpenAPI modules allow type: [ ... ] in OpenAPI specs, other tools may not.

Except, I think you're right: The OpenAPI spec specifically allows it. Here's the definition of the "schema" property and here's the line in the schema property that says it supports JSON schema's types.

But, all of the parameters except body parameters ("in": "header", "in": "query", "in": "formData", and "in": "path", the ones that do not have a schema property) do not support array-types. So that's where we would need to pick the first one instead of allowing any.

preaction commented 3 years ago

The OpenAPI code has moved to Yancy::Plugin::OpenAPI, so there's no need to do anything additional here in Yancy.