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

Discriminator in Openapi Schema does not allow - in the field value #7440

Closed
1 of 4 tasks
aboyton opened this issue Aug 1, 2024 · 0 comments · Fixed by #7443
Closed
1 of 4 tasks

Discriminator in Openapi Schema does not allow - in the field value #7440

aboyton opened this issue Aug 1, 2024 · 0 comments · Fixed by #7443

Comments

@aboyton
Copy link
Contributor

aboyton commented Aug 1, 2024

Issue workflow progress

Progress of the issue based on the
Contributor Workflow


Describe the bug

When using a discriminator, it seems the field that does the mapping cannot have a - in it. For legacy APIs it's useful to be able to do so.

To Reproduce Steps to reproduce the behavior:

Github

With the query

query Pet_dog($petsByIdId: String!) {
  pets_by_id(id: $petsByIdId) {
    ... on Cat {
      name
      petType
    }
    ... on Dog {
      name
      petType
    }
  }
}

I get the error message

{
  "errors": [
    {
      "message": "Abstract type \"Pet\" was resolved to a type \"pet-cat\" that does not exist inside the schema.",
      "path": [
        "pets_by_id"
      ]
    }
  ],
  "data": {
    "pets_by_id": null
  }
}

I've tried a few combinations of the mesh.yaml, all without success:

components:
  schemas:
    Pet:
      required:
        - name
      type: object
      discriminator:
        propertyName: petType
        mapping:
          "pet-cat": '#/components/schemas/Cat'
          "pet-dog": '#/components/schemas/Dog'
      properties:
        name:
          type: string
        petType:
          type: string
    Cat:
      title: "Cat"
      allOf:
        - $ref: '#/components/schemas/Pet'
    Dog:
      title: "Dog"
      allOf:
        - $ref: '#/components/schemas/Pet'

or changed to

        mapping:
          "pet-cat": '#/components/schemas/pet-cat'
          "pet-dog": '#/components/schemas/pet-dog'
    'pet-cat':
      allOf:
        - $ref: '#/components/schemas/Pet'
    'pet-dog':
      allOf:
        - $ref: '#/components/schemas/Pet'

or with title: "petCat" and title: "petDog".

Expected behaviour

While I don't want a type name with a - in it, it would be useful to be able to have the discriminator field to be able to do so.

Environment:

  • OS: macOS
    "@graphql-mesh/cli": "0.83.0-alpha-20230602110655-2f92b7981",
    "@graphql-mesh/openapi": "0.94.0-alpha-20230602110655-2f92b7981",

and

    "@graphql-mesh/cli": "^0.92.4-alpha-20240726162150-a48089a7ec036914e026d6ddd90cface63197cb9",
    "@graphql-mesh/openapi": "^0.102.5-alpha-20240726162150-a48089a7ec036914e026d6ddd90cface63197cb9",
  • NodeJS: v18.19.0 or v20.15.1
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 a pull request may close this issue.

1 participant