Skip to content

How to interpret schema with both properties and oneOf? #1529

@bcherny

Description

@bcherny

I was wondering how to interpret the SqlConnectionInfo definition in the Azure JSON-Schema.

It looks like this:

  "SqlConnectionInfo": {
    "type": "object",
    "oneOf": [
      {
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "SqlConnectionInfo"
            ]
          }
        }
      }
    ],
    "properties": {
      "userName": {
        "type": "string",
        "description": "User name"
      },
      "password": {
        "type": "string",
        "description": "Password credential."
      },
      "type": {
        "type": "string"
      },
      ...
    },
    ...
  },

Full JSON-Schema: https://schema.management.azure.com/schemas/2017-11-15-privatepreview/Microsoft.DataMigration.json.

Is the right way to interpret this:

  1. SqlConnectionInfo is an object which may declare keys userName, password, and type
  2. If declared, the type field must be the string literal "SqlConnectionInfo"

Motivation: making sure that https://github.com/bcherny/json-schema-to-typescript/pull/603/files doesn't regress TypeScript typing generation for Azure's JSON-Schema.

Side note: it would be nice if the JSON-Schema Spec and docs more directly talked about how to handle complex schemas like this one, where more than one keyword applies (eg. if this schema definition moved the oneOf into type's definition, it would be much more clear how to interpret this schema). Or, let me know if I missed it in the docs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions