Support circular schema definitions · Issue #333 · ardatan/feTS · GitHub
Skip to content

Support circular schema definitions #333

Description

@Stefano31

First of all, great job.

I have tried to use this library but in a test case I have found a problem with the circular schema.

To Reproduce
Use any circular schema, here an example:

// file tree.oas.ts
// Open API Specification
export default {
  openapi: "3.0.3",
  info: {
    version: "1",
    title: "Tree - OpenAPI 3.0",
    description:
      "This is a sample of tree",
    termsOfService: "http://swagger.io/terms/",
  },
  paths: {
    "/tree": {
      get: {
        tags: ["tree"],
        summary: "Get tree",
        description: "",
        operationId: "getTree",
        responses: {
          "200": {
            description: "successful operation",
            content: {
              "application/json": {
                schema: {
                  $ref: "#/components/schemas/Node",
                },
              },
            },
          },
          "404": {
            description: "Tree not found",
          },
        },
      },
    },
  },
  components: {
    schemas: {
      Node: {
        type: "object",
        properties: {
          number: {
            type: "integer",
            format: "int64",
            example: 10,
          },
          child: {
            $ref: "#/components/schemas/Node",
          },
        },
      },
    },
  },
} as const;
// file client.ts
import { createClient, Mutable } from 'fets'
import treeOAS from './tree.oas'
 
const client = createClient<Mutable<typeof treeOAS>>()

const response = await client['/tree'].get() // <--- HERE THERE IS AN ERROR TS2615 (circular reference for field "child")

const body = await response.json()

console.log(body)

Expected behavior

Honestly, I don't know how to works deeply this library and I'm trying to understand, but I think that should be there a flag that avoids these scenarios with circular reference

Environment:

  • package-name...: fets
  • NodeJS: 18

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions