biocad / openapi3

OpenAPI 3.0 data model
BSD 3-Clause "New" or "Revised" License
39 stars 53 forks source link

Add discriminator to union-type schema #70

Open Reykudo opened 1 year ago

Reykudo commented 1 year ago

Hello! I'm trying to implement support discriminator for sum-types. My way is to call a function that turns inline into a ref, without name clash(by appending _ at end).

Reykudo commented 1 year ago

But what to do with the tests, they do not take into account the definitions. For example:

expected:

{
              "oneOf": [
                  {
                      "properties": {
                          "tag": {
                              "enum": [
                                  "ErrorNoUser"
                              ],
                              "type": "string"
                          },
                          "userId": {
                              "maximum": 9223372036854775807,
                              "minimum": -9223372036854775808,
                              "type": "integer"
                          }
                      },
                      "required": [
                          "userId",
                          "tag"
                      ],
                      "type": "object"
                  },
                  {
                      "properties": {
                          "requiredPermission": {
                              "type": "string"
                          },
                          "tag": {
                              "enum": [
                                  "ErrorAccessDenied"
                              ],
                              "type": "string"
                          }
                      },
                      "required": [
                          "requiredPermission",
                          "tag"
                      ],
                      "type": "object"
                  }
              ],
              "type": "object"
          }

but got:

 {
              "discriminator": {
               ^
                  "mapping": {
                      "ErrorAccessDenied": "#/components/schemas/ErrorAccessDenied",
                      "ErrorNoUser": "#/components/schemas/ErrorNoUser"
                  },
                  "propertyName": "tag"
              },
              "oneOf": [
                  {
                      "$ref": "#/components/schemas/ErrorNoUser"
                  },
                  {
                      "$ref": "#/components/schemas/ErrorAccessDenied"
                  }
              ],
              "type": "object"
          }