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

Type error on passing JSON schema to openapi.components.schema #705

Closed
2 tasks done
benevbright opened this issue Jan 12, 2023 · 3 comments · Fixed by #707
Closed
2 tasks done

Type error on passing JSON schema to openapi.components.schema #705

benevbright opened this issue Jan 12, 2023 · 3 comments · Fixed by #707
Labels
bug Confirmed bug good first issue Good for newcomers typescript TypeScript related

Comments

@benevbright
Copy link

benevbright commented Jan 12, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

Plugin version

No response

Node.js version

18.12.1

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

13.0

Description

I get type error when passing a JSON schema to register option openapi.components.schema. (I create the json schema using Typebox)

fastify-swagger is using openapi-types for TS type. But we(fastify-swagger) don't have their change that they've made for OpenApi 3.1 kogosoftwarellc/open-api#757 and now they have OpenAPIV3_1.Document.

So we would need to apply this to here

openapi?: Partial<OpenAPIV3.Document>
somehow, using OR or something.

Steps to Reproduce

Try this on TS playground

import { OpenAPIV3, OpenAPIV3_1 } from "openapi-types"

// error: Type '"null"' is not assignable to type 'NonArraySchemaObjectType | undefined'.(2322)
const User1: OpenAPIV3.SchemaObject = {
  type: "object",
  properties: {
    name: { type: "string" },
    city: {
      anyOf: [{ type: "null" }, { type: "string" }],
    },
  },
};

// ok
const User2: OpenAPIV3_1.SchemaObject = {
  type: "object",
  properties: {
    name: { type: "string" },
    city: {
      anyOf: [{ type: "null" }, { type: "string" }],
    },
  },
};

Also, it's reproducible when passing this object to openapi.components.schema option on fastify.register.

Expected Behavior

No response

@benevbright
Copy link
Author

related to #499

@benevbright benevbright changed the title Type error on passing JSON schema to swagger.openapi.components.schema Type error on passing JSON schema to openapi.components.schema Jan 12, 2023
@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@mcollina mcollina added bug Confirmed bug good first issue Good for newcomers typescript TypeScript related labels Jan 13, 2023
@nidhi-kala
Copy link
Contributor

If no one has taken this yet, I'm happy to send a pull request for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug good first issue Good for newcomers typescript TypeScript related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants