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

add ArrayObject into AST type #583

Closed
wants to merge 6 commits into from

Conversation

UMRzcz-831
Copy link

Happen to notice, JSTT fail to compile duplicate enum.
image

However,it works fine when the enum property is direct property of an object
image

example data

{
  "type": "object",
  "properties": {
    "asDirectPropertyEnumType": {
      "type": "integer",
      "description": "duplicate enum",
      "enum": [
        1,
        2,
        3,
        5,
        1,
        2,
        6,
        10,
        1,
        1,
        2,
        1,
        2
      ]
    },
    "result": {
      "type": "object",
      "properties": {
        "total": {
          "type": "integer",
          "description": "total num"
        },
        "data": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "enumType": {
                "type": "integer",
                "description": "duplicate enum",
                "enum": [
                  1,
                  2,
                  3,
                  5,
                  1,
                  2,
                  6,
                  10,
                  1,
                  1,
                  2,
                  1,
                  2
                ]
              },
              "objectType": {
                "type": "object",
                "properties": {
                  "minAmount": {
                    "type": "integer",
                    "description": "minimum amount"
                  },
                  "maxAmount": {
                    "type": "integer",
                    "description": "maximum amount"
                  }
                },
                "description": "Object Propertie of ArrayObjectItem",
                "additionalProperties": false
              },
              "env": {
                "type": "integer",
                "description": "env"
              },
              "version": {
                "type": "string",
                "description": "version"
              }
            },
            "additionalProperties": false
          },
          "description": "data set"
        }
      },
      "additionalProperties": false
    }
  },
  "$schema": "http://json-schema.org/draft-04/schema#",
  "additionalProperties": false
}

In that way,I found out data like Object[] get no optimization in ./src/optimizer.
image

So i separate the type ARRAYOBJECT from just ARRAY,make sure the inside ast get optimized.

As result
e2e test case
compiled into

export interface ArrayObject {
      result?: {
        /**␊
         * total num␊
         */
        total?: number;
        /**␊
         * data set␊
         */
        data?: {
          /**␊
           * duplicate enum␊
           */
          enumType?: 1 | 2 | 3 | 5 | 6 | 10;
          /**␊
           * Object Propertie of ArrayObjectItem␊
           */
          objectType?: {
            /**␊
             * minimum amount␊
             */
            minAmount?: number;
            /**␊
             * maximum amount␊
             */
            maxAmount?: number;
          };
          /**␊
           * env␊
           */
          env?: number;
          /**␊
           * version␊
           */
          version?: string;
        }[];
      };
    }

@bcherny bcherny closed this in 9cbe26e Apr 20, 2024
@bcherny
Copy link
Owner

bcherny commented Apr 20, 2024

Thanks for the contribution! Simplified this a bit in 9cbe26e

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 this pull request may close these issues.

None yet

2 participants