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

Add discriminator to union-type schema #70

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Reykudo
Copy link

@Reykudo Reykudo commented Nov 12, 2022

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 Reykudo marked this pull request as draft November 12, 2022 20:39
@Reykudo
Copy link
Author

Reykudo commented Nov 12, 2022

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"
          }

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

Successfully merging this pull request may close these issues.

1 participant