OpenAPI schema export not valid

It looks like the OpenAPI export functionality does not properly handle the the schema definitions for inputs. It correctly places the response schema definitions under #/components/schemas but for input schemas, it continues to use the old Swagger method of putting it in the definitions attribute. This results in validation errors like Could not resolve reference: Evaluation failed on token: "definitions".

Hey Aaron,

Thanks for bringing this up.

Let me pull the team on this so we can take a closer look.

1 Like

Can you provide a failing schema?

Sure here is an example operation:

# This file is auto generated.
# Remove/modify this header if you want to customize the operation.
mutation faunaDBTenant_createInvoices_mutation($data: faunaDBTenant_InvoicesInput!) {
  faunaDBTenant_createInvoices(data: $data) {
    _id
    _ts
    balance
    currency
    dueDate
    issueDate
    lineItems {
      account
      description
      item
      modified_at
      quantity
      remote_id
      total_amount
      unit_price
    }
    number
    sourceSystemMeta {
      mergeId
      remoteId
      remoteUpdatedAt
      remoteWasDeleted
      type
    }
    totalAmount
    totalTaxAmount
  }
}

and an example openapi spec:

{
  "openapi": "3.1.0",
  "info": {
    "title": "Example API",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "http://localhost:9991/operations"
    }
  ],
  "paths": {
    "/faunaDBTenant/CreateInvoices": {
      "post": {
        "operationId": "FaunaDBTenantCreateInvoices",
        "x-wundergraph-operation-type": "mutation",
        "x-wundergraph-requires-authentication": true,
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "data": {
                    "$ref": "#/definitions/faunaDBTenant_InvoicesInput"
                  }
                },
                "additionalProperties": false,
                "required": [
                  "data"
                ],
                "definitions": {
                  "faunaDBTenant_InvoicesInput": {
                    "additionalProperties": false,
                    "type": "object",
                    "properties": {
                      "balance": {
                        "type": [
                          "integer",
                          "null"
                        ]
                      },
                      "currency": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "dueDate": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "issueDate": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "lineItems": {
                        "type": "array",
                        "minItems": 1,
                        "items": {
                          "$ref": "#/definitions/faunaDBTenant_InvoiceLineItemInput"
                        }
                      },
                      "number": {
                        "type": "string"
                      },
                      "sourceSystemMeta": {
                        "$ref": "#/definitions/faunaDBTenant_SourceSystemMetaInput"
                      },
                      "totalAmount": {
                        "type": [
                          "integer",
                          "null"
                        ]
                      },
                      "totalTaxAmount": {
                        "type": [
                          "integer",
                          "null"
                        ]
                      }
                    },
                    "required": [
                      "lineItems",
                      "number"
                    ]
                  },
                  "faunaDBTenant_InvoiceLineItemInput": {
                    "additionalProperties": false,
                    "type": "object",
                    "properties": {
                      "account": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "description": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "item": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "modified_at": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "quantity": {
                        "type": [
                          "integer",
                          "null"
                        ]
                      },
                      "remote_id": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "total_amount": {
                        "type": [
                          "integer",
                          "null"
                        ]
                      },
                      "unit_price": {
                        "type": [
                          "number",
                          "null"
                        ]
                      }
                    }
                  },
                  "faunaDBTenant_SourceSystemMetaInput": {
                    "additionalProperties": false,
                    "type": [
                      "object",
                      "null"
                    ],
                    "properties": {
                      "mergeId": {
                        "type": "string"
                      },
                      "remoteId": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "remoteUpdatedAt": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "remoteWasDeleted": {
                        "type": [
                          "boolean",
                          "null"
                        ]
                      },
                      "type": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "faunaDBTenant_createInvoices": {
                          "type": "object",
                          "properties": {
                            "_id": {
                              "type": "string"
                            },
                            "_ts": {
                              "type": "string"
                            },
                            "balance": {
                              "type": "integer"
                            },
                            "currency": {
                              "type": "string"
                            },
                            "dueDate": {
                              "type": "string"
                            },
                            "issueDate": {
                              "type": "string"
                            },
                            "lineItems": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "account": {
                                    "type": "string"
                                  },
                                  "description": {
                                    "type": "string"
                                  },
                                  "item": {
                                    "type": "string"
                                  },
                                  "modified_at": {
                                    "type": "string"
                                  },
                                  "quantity": {
                                    "type": "integer"
                                  },
                                  "remote_id": {
                                    "type": "string"
                                  },
                                  "total_amount": {
                                    "type": "integer"
                                  },
                                  "unit_price": {
                                    "type": "number"
                                  }
                                },
                                "additionalProperties": false
                              }
                            },
                            "number": {
                              "type": "string"
                            },
                            "sourceSystemMeta": {
                              "type": "object",
                              "properties": {
                                "mergeId": {
                                  "type": "string"
                                },
                                "remoteId": {
                                  "type": "string"
                                },
                                "remoteUpdatedAt": {
                                  "type": "string"
                                },
                                "remoteWasDeleted": {
                                  "type": "boolean"
                                },
                                "type": {
                                  "type": "string"
                                }
                              },
                              "additionalProperties": false,
                              "required": [
                                "mergeId"
                              ]
                            },
                            "totalAmount": {
                              "type": "integer"
                            },
                            "totalTaxAmount": {
                              "type": "integer"
                            }
                          },
                          "additionalProperties": false,
                          "required": [
                            "_id",
                            "_ts",
                            "lineItems",
                            "number"
                          ]
                        }
                      },
                      "additionalProperties": false,
                      "required": [
                        "faunaDBTenant_createInvoices"
                      ]
                    }
                  },
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvalidInputError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "InvalidInputError": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          },
          "input": {},
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "propertyPath": {
                  "type": "string"
                },
                "invalidValue": {},
                "message": {
                  "type": "string"
                }
              },
              "required": [
                "propertyPath",
                "invalidValue",
                "message"
              ]
            }
          }
        },
        "required": [
          "message",
          "input",
          "errors"
        ]
      }
    }
  }
}

Also I’m using https://editor.swagger.io/ to validate the schema for testing purposes but also want to use Readme.io to import it… they have slightly different validation algorithms.

okay cool, we’re taking a look

1 Like