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

Support circular schema definitions #333

Closed
Stefano31 opened this issue Jul 14, 2023 · 1 comment · Fixed by #335
Closed

Support circular schema definitions #333

Stefano31 opened this issue Jul 14, 2023 · 1 comment · Fixed by #335

Comments

@Stefano31
Copy link

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
@ardatan
Copy link
Owner

ardatan commented Jul 14, 2023

Fixed in #335 ! Thanks for the feedback!

@theguild-bot theguild-bot mentioned this issue Oct 26, 2023
20 tasks
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.

2 participants