Skip to content

JsonSchema 'true' produces literal 'true' type instead of unknown #1227

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

Closed
1 of 2 tasks
m-ronchi opened this issue Jul 17, 2023 · 0 comments · Fixed by #1228
Closed
1 of 2 tasks

JsonSchema 'true' produces literal 'true' type instead of unknown #1227

m-ronchi opened this issue Jul 17, 2023 · 0 comments · Fixed by #1228
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@m-ronchi
Copy link
Contributor

m-ronchi commented Jul 17, 2023

Description

boolean true/false are valid JsonSchemas and represents respectively "everything is valid" / "nothing is valid".

when openapi-typescript encounters one (e.g. {"properties": {"foo": true}} it produces foo: true instead of foo: unknown in the corresponding type

Name Version
openapi-typescript 6.3.4
Node.js v18.15.0
OS + version macOS

Reproduction

minimal-api.json:

{
  "openapi": "3.1.0",
  "servers": [ { "url": "" } ],
  "info": {
    "title": "API",
    "version": ""
  },
  "paths": { },
  "components": {
    "schemas": {
      "Foo": {
        "type": "object",
        "properties": {
          "works": { },
          "fails": true
        }
      }
    }
  }
}

$ npx openapi-typescript minimal-api.json:

/**
 * This file was auto-generated by openapi-typescript.
 * Do not make direct changes to the file.
 */


export type paths = Record<string, never>;

export type webhooks = Record<string, never>;

export interface components {
  schemas: {
    Foo: {
      works?: unknown;
      fails?: true;
    };
  };
  responses: never;
  parameters: never;
  requestBodies: never;
  headers: never;
  pathItems: never;
}

export type external = Record<string, never>;

export type operations = Record<string, never>;

Expected result

....
    Foo: {
      works?: unknown;
      fails?: unknown; <-- here
    };
....

also false should either produce : never or omit the property

Checklist

NOTE: redocly fails expecting an object in that position, but both the JsonSchema spec and other validators online (like this) say it's valid

@m-ronchi m-ronchi added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant