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

Support patternProperties #1859

Open
ELigoP opened this issue Jan 31, 2024 · 1 comment
Open

Support patternProperties #1859

ELigoP opened this issue Jan 31, 2024 · 1 comment

Comments

@ELigoP
Copy link

ELigoP commented Jan 31, 2024

Typescript-restricted key (fail)

// test_str.ts
export type A = `wifi${number}`;
// actual_str.json
{
  "$ref": "#/definitions/A",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "A": {
      "type": "string"
    }
  }
}
// expected_str.json
{
  "$ref": "#/definitions/A",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "A": {
      "type": "string",
      "pattern": "^wifi[0-9]+$"
    }
  }
}

Annotated string (pass)

// test_annotated_str.ts
/**
 * @pattern ^wifi[0-9]+$
 */
export type A = `wifi${number}`;
// actual_annotated_str.json
// expected_annotated_str.json
{
  "$ref": "#/definitions/A",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "A": {
      "pattern": "^wifi[0-9]+$",
      "type": "string"
    }
  }
}

Annotated key (kinda pass)

// test_annotated_key.ts
/**
 * @pattern ^wifi[0-9]+$
 */
type WifiDevName = string;
export type A = Record<WifiDevName, number>;
// actual_annotated_key.json
{
  "$ref": "#/definitions/A",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "A": {
      "additionalProperties": {
        "type": "number"
      },
      "propertyNames": {
        "pattern": "^wifi[0-9]+$"
      },
      "type": "object"
    }
  }
}
// expected_annotated_key.json
{
  "$ref": "#/definitions/A",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "A": {
      "patternProperties": {
        "^wifi[0-9]+$": {
          "type": "number"
        }
      },
      "type": "object"
    }
  }
}

Real life object (fail)

// test_real_life.ts
/**
 * @pattern ^lan[0-9]+$
 */
type LedLanKey = `lan${number}`;
/**
 * @pattern ^radio[0-9]+$
 */
type LedRadioKey = `radio${number}`;
type LedsLan = Record<LedLanKey, object>;
type LedsRadio = Record<LedRadioKey, object>;
export type A = LedsLan &
    LedsRadio & {
        power?: object;
    };
// actual_real_life.json
{
  "$ref": "#/definitions/A",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "A": {
      "additionalProperties": {
        "type": "object"
      },
      "properties": {
        "power": {
          "type": "object"
        }
      },
      "type": "object"
    }
  }
}
// expected_real_life.json
{
  "$ref": "#/definitions/A",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "A": {
      "properties": {
        "power": {
          "type": "object"
        }
      },
      "patternProperties": {
        "^lan[0-9]+$": {
          "type": "object"
        },
        "^radio[0-9]+$": {
          "type": "object"
        }
      },
      "type": "object"
    }
  }
}
@ELigoP
Copy link
Author

ELigoP commented Jan 31, 2024

I tried to read the code to contribute fix but didn't understand where to start.

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

No branches or pull requests

1 participant