Skip to content

Feature request: combining JSON schema #1879

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

Closed
hlubovac opened this issue Jan 15, 2016 · 7 comments
Closed

Feature request: combining JSON schema #1879

hlubovac opened this issue Jan 15, 2016 · 7 comments

Comments

@hlubovac
Copy link

Will there be support for displaying complex schema within the UI? Question is about this:
http://spacetelescope.github.io/understanding-json-schema/reference/combining.html

I'm really after finding a way to display inline definitions for properties which may contain different runtime types. For example, I have a situation where an object displayed as:

some_resource
{
  some_property(object)
}

could, on runtime, be either:

some_resource
{
  some_property(another)
}

another
{
  blah(string)
}

or:

some_resource
{
  some_property(something_else)
}

something_else
{
  blah(int)
}

Possibly, this can be solved by defining swagger-json as this:

{
    definitions:
    {
        some_resource:
        {
            title: " ",
            type: "object",
            properties:
            {
                some_property:
                {
                    anyOf:
                    [
                        {
                            "$ref": "#/definitions/another",
                            description: "something about {another}"
                        },
                        {
                            "$ref": "#/definitions/something_else",
                            description: "something about {something_else}"
                        }                       
                    [
                }
            }
        },
        another:
        {
            title: " ",
            type: "object",
            properties:
            {
                blah:
                {
                    "type": "string",
                    "description": "something about \"blah\" text"
                }
            }
        },
        something_else:
        {
            title: " ",
            type: "object",
            properties:
            {
                blah:
                {
                    "type": "integer",
                    "format": "int32",
                    "description": "something about \"blah\" number"
                }
            }
        }
    }
}

Maybe I have it defined badly, but I'd somehow want this (or similar):

some_resource
{
  some_property(another or something_else)
}

another
{
  blah(string)
}

something_else
{
  blah(int)
}

Or, is there another solution?

@webron
Copy link
Contributor

webron commented Jan 16, 2016

There's support for allOf, there's no support for oneOf or anyOf as that's not supported by the spec.

@4hopp
Copy link

4hopp commented Sep 19, 2016

Hello everyone,

same problem here, I need to specify something to either be a string or an object. I understand that the current standard does not support the oneOf keyword, but since it probably will be in the specification, version 3.0 (see here: OAI/OpenAPI-Specification#57 (comment)) … Would it take much of an effort to support oneOf (or x-oneOf, as long as it's still 2.0) in Swagger-UI already, at least in an developement version?

Thanks for your time!
Sincerely
Joshua Hopp

@webron
Copy link
Contributor

webron commented Mar 22, 2017

This will be added with support for OAS3.

@webron webron closed this as completed Mar 22, 2017
@mattdeboard
Copy link

it's not clear to me whether OAS3 will support e.g. "type": ["string", null] or if the expectation is that these should not be included in required fields

@fehguy
Copy link
Contributor

fehguy commented Apr 20, 2017

What you show above is not supported, but what is supported is oneOf or anyOf to allow different types to be described in a single schema. null is not valid in the schema.

@mattdeboard
Copy link

mattdeboard commented Apr 21, 2017

Ok, sorry if I'm forcing you to repeat yourself, but just for my own understanding, what you're saying is that Swagger/OAS has no support for optional/maybe/nullable/whatever types, right? No such thing as "type": null or "type": ["string", null], yeah?

If I'm understanding right, is there a way to express this concept in a way that is json-schema compliant?

edit: And also you're saying that non-nullable union types will be expressed via oneOf, correct?

@webron
Copy link
Contributor

webron commented Apr 21, 2017

@mattdeboard I believe you found the relevant OAS ticket. null value support has been added with the nullableproperty.

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

5 participants