astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)

Home Page:openapi-zod-client.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not respecting required nullable properly on trivial objects

filipbekic01 opened this issue · comments

In next schema, parent_id is not set as nullable. It's required but it should be nullable.

{
  "openapi": "3.0.0",
  "info": {
    "title": "Etsy Seller Taxonomy API",
    "version": "1.0.0"
  },
  "paths": {},
  "components": {
    "schemas": {
      "TestClass": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int32"
          },
          "parent_id": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "children": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TestClass"
            }
          }
        },
        "required": [
          "id",
          "parent_id"
        ]
      }
    }
  }
}

output:

type TestClass = {
    id: number;
    parent_id: number;
    children?: Array<TestClass> | undefined;
};

output (should be like this):

type TestClass = {
    id: number;
    parent_id: number | null;
    children?: Array<TestClass> | undefined;
};

I actually made PR here #204

We need null properties, undefined is something else.

We need null properties, undefined is something else.

hm, yes ? typed-openapi outputs this (which is the exactly the same as you expected in your OP)
export type TestClass = { id: number; parent_id: number | null; children?: Array<TestClass> | undefined };

We need null properties, undefined is something else.

hm, yes ? typed-openapi outputs this (which is the exactly the same as you expected in your OP) export type TestClass = { id: number; parent_id: number | null; children?: Array<TestClass> | undefined };

You're right, I checked wrong commit before. I tried the same as you did but has some TypeScript errors but I didnt want to use @ts-ignore there. Your getTs() method has different return type I assume.

Anyways, this nullable field seems to be deprecated in OpenAPI 3.1 version?

Anyways, this nullable field seems to be deprecated in OpenAPI 3.1 version?

yes it seems to be the case, I also just noticed when implementing it in typed-openapi