Skip to content

Incorrect tuples generation with v6.x #1011

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 task
Jmenache opened this issue Dec 1, 2022 · 5 comments · Fixed by #1205
Closed
1 task

Incorrect tuples generation with v6.x #1011

Jmenache opened this issue Dec 1, 2022 · 5 comments · Fixed by #1205
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@Jmenache
Copy link

Jmenache commented Dec 1, 2022

Description

Hello. Thank you very much for your great work on this library 👍 !!

From v6.0 tuples stopped being properly generated.
I get the following :

export interface paths {
  "/tupleTest": {
    post: {
      requestBody: {
        content: {
          "application/json; charset=UTF-8": {
            tupleTest: [[[object Object], [object Object]], [[object Object], [object Object]]];
          };
        };
      };
    };
  };
}
Name Version
openapi-typescript 6.1.0
Node.js 16.13.0
OS + version Windows 10

Reproduction

{
  "openapi": "3.1.0",
  "paths": {
    "/tupleTest": {
      "post": {
        "requestBody": {
          "required": true,
          "content": {
            "application/json; charset=UTF-8": {
              "schema": {
                "type": "object",
                "properties": {
                  "tupleTest": {
                    "type": "array",
                    "minItems": 2,
                    "maxItems": 2,
                    "items": [
                      {"type": "string"},
                      {"type": "number"}
                    ]
                  }
                },
                "required": ["tupleTest"],
                "additionalProperties": false
              }
            }
          }
        }
      }
    }
  }
}

Expected result

With v5.4.0 I get :

export interface paths {
  '/tupleTest': {
    post: {
      requestBody: {
        content: {
          'application/json; charset=UTF-8': {
            tupleTest: [string, number];
          };
        };
      };
    };
  };
}

Checklist

@mitchell-merry
Copy link
Contributor

This appears to be working in my tests (6.1.1). Could you confirm if this is still happening? i.e. using your example the output is:

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

export interface paths {
  "/tupleTest": {
    post: {
      requestBody: {
        content: {
          "application/json; charset=UTF-8": {
            tupleTest: [string, number];
          };
        };
      };
    };
  };
}

export interface components {}

export interface operations {}

export interface external {}

@liangskyli
Copy link
Contributor

liangskyli commented Apr 23, 2023

@mitchell-merry : I also have the same problem here
version: [email protected]

export interface paths {
  "/tupleTest": {
    post: {
      requestBody: {
        content: {
          "application/json; charset=UTF-8": {
            tupleTest: ([[object Object], [object Object]])[];
          };
        };
      };
    };
  };
}

export type webhooks = Record<string, never>;

export type components = Record<string, never>;

export type external = Record<string, never>;

export type operations = Record<string, never>;

liangskyli added a commit to liangskyli/openapi-typescript that referenced this issue Apr 23, 2023
@drwpow
Copy link
Contributor

drwpow commented Apr 24, 2023

Agree this needs to be supported. Though I believe the spec requires prefixItems to be an array rather than items. I think items needs to stay as an object (or be set to false).

@liangskyli
Copy link
Contributor

I think items also need support!
see: https://json-schema.org/draft/2020-12/release-notes.html
image
because: Draft 2019-09 use items, so we alse need support items!

https://json-schema.org/understanding-json-schema/reference/array.html#tuple-validation
image
In Draft 4 - 2019-09, tuple validation was handled by an alternate form of the items keyword. When items was an array of schemas instead of a single schema, it behaved the way prefixItems behaves.

@drwpow
Copy link
Contributor

drwpow commented Apr 26, 2023

With #1082 and #1085 merged this is mostly handled, but I’d like to add support for prefixItems when I have time to (I’m working with a spec now that uses that, and I can test it on there)

@drwpow drwpow added the bug Something isn't working label May 15, 2023
@drwpow drwpow added the openapi-ts Relevant to the openapi-typescript library label May 22, 2023
@drwpow drwpow mentioned this issue Jul 6, 2023
3 tasks
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.

4 participants