Skip to content

Schema build bug #96

@NivGreenstein

Description

@NivGreenstein

Hi all, Sorry for the title. Help me change it.
I have this typescript iterface:

type QueueName = 'changesets' | 'files';

interface QueueOptions {
  enabledBatchJobs: boolean;
  maxBatchSize?: number;
}

interface ClosureQueueConfig {
  queueOptions: QueueOptions;
  .....
}

interface ClosureConfig {
  uiPath: string;
  queues: {
    [key in QueueName]: ClosureQueueConfig;
  };
}

So I've created this schema

{
  "$id": "https://mapcolonies.com/vector/osmSyncTracker/v1",
  "type": "object",
  "title": "VectorOsmSyncTrackerSchemaV1",
  "description": "osm-sync-tracker schema",
  "allOf": [
    {
      "$ref": "#/definitions/closure"
    }
  ],
  "definitions": {
    "closure": {
      "type": "object",
      "properties": {
        "uiPath": {
          "type": "string",
          "x-env-value": "CLOSURE_UI_PATH",
          "description": "The path to the closure UI"
        },
        "queues": {
          "type": "object",
          "properties": {
            "changesets": {
              "type": "object",
              "properties": {
                "queueOptions": {
                  "$ref": "#/definitions/changesetsQueueOptions"
                }
              }
            },
            "files": {
              "type": "object",
              "properties": {
                "queueOptions": {
                  "$ref": "#/definitions/filesQueueOptions"
                }
              }
            }
          }
        }
      }
    },
    "changesetsQueueOptions": {
      "allOf": [
        { "$ref": "#/definitions/queueOptions" },
        {
          "type": "object",
          "properties": {
            "enabledBatchJobs": {
              "x-env-value": "CHANGESETS_QUEUE_ENABLED_BATCH_JOBS",
              "default": true
            },
            "maxBatchSize": {
              "x-env-value": "CHANGESETS_QUEUE_MAX_BATCH_SIZE",
              "default": 10
            }
          }
        }
      ]
    },
    "filesQueueOptions": {
      "allOf": [
        { "$ref": "#/definitions/queueOptions" },
        {
          "type": "object",
          "properties": {
            "enabledBatchJobs": {
              "x-env-value": "FILES_QUEUE_ENABLED_BATCH_JOBS",
              "default": false
            },
            "maxBatchSize": {
              "x-env-value": "FILES_QUEUE_MAX_BATCH_SIZE"
            }
          }
        }
      ]
    },
    "queueOptions": {
      "type": "object",
      "properties": {
        "enabledBatchJobs": {
          "type": "boolean"
        },
        "maxBatchSize": {
          "type": "integer"
        }
      },
      "if": {
        "properties": {
          "enabledBatchJobs": {
            "const": true
          }
        }
      },
      "then": {
        "required": ["maxBatchSize"]
      },
      "else": {
        "properties": {
          "enabledBatchJobs": {
            "const": false
          }
        }
      }
    }
  }
}

The schema contains queueOptions definition.
The only thing that changes between changesetsQueueOptions and filesQueueOptions is x-env-value and default values. So, I've created queueOptions as base and extend it.

I get this error when running npm run validate

  stdout: `build/schemas/vector/osmSyncTracker/v1.schema.ts(7,42): error TS2344: Type '{ readonly $id: "https://mapcolonies.com/vector/osmSyncTracker/v1"; readonly type: "object"; readonly title: "VectorOsmSyncTrackerSchemaV1"; readonly description: "osm-sync-tracker schema"; readonly allOf: readonly [...]; readonly definitions: { ...; }; }' does not satisfy the constraint 'JSONSchema'.\n` +
  `  Type '{ readonly $id: "https://mapcolonies.com/vector/osmSyncTracker/v1"; readonly type: "object"; readonly title: "VectorOsmSyncTrackerSchemaV1"; readonly description: "osm-sync-tracker schema"; readonly allOf: readonly [...]; readonly definitions: { ...; }; }' is not assignable to type 'Readonly<{ $id?: string | undefined; $ref?: string | undefined; $schema?: string | undefined; $comment?: string | undefined; type?: JSONSchemaType | readonly JSONSchemaType[] | undefined; ... 43 more ...; [$JSONSchema]?: unique symbol | undefined; }>'.\n` +
  "    Types of property 'allOf' are incompatible.\n" +
  `      Type 'readonly [{ readonly type: "object"; readonly properties: { readonly uiPath: { readonly type: "string"; readonly "x-env-value": "CLOSURE_UI_PATH"; readonly description: "The path to the closure UI"; }; readonly queues: { ...; }; }; }]' is not assignable to type 'readonly JSONSchema[]'.\n` +
  `        Type '{ readonly type: "object"; readonly properties: { readonly uiPath: { readonly type: "string"; readonly "x-env-value": "CLOSURE_UI_PATH"; readonly description: "The path to the closure UI"; }; readonly queues: { ...; }; }; }' is not assignable to type 'JSONSchema'.\n` +
  `          Type '{ readonly type: "object"; readonly properties: { readonly uiPath: { readonly type: "string"; readonly "x-env-value": "CLOSURE_UI_PATH"; readonly description: "The path to the closure UI"; }; readonly queues: { ...; }; }; }' is not assignable to type 'Readonly<{ $id?: string | undefined; $ref?: string | undefined; $schema?: string | undefined; $comment?: string | undefined; type?: JSONSchemaType | readonly JSONSchemaType[] | undefined; ... 43 more ...; [$JSONSchema]?: unique symbol | undefined; }>'.\n` +
  "            Types of property 'properties' are incompatible.\n" +
  `              Type '{ readonly uiPath: { readonly type: "string"; readonly "x-env-value": "CLOSURE_UI_PATH"; readonly description: "The path to the closure UI"; }; readonly queues: { readonly type: "object"; readonly properties: { ...; }; }; }' is not assignable to type 'Readonly<Record<string, JSONSchema>>'.\n` +
  `                Property '"queues"' is incompatible with index signature.\n` +
  `                  Type '{ readonly type: "object"; readonly properties: { readonly changesets: { readonly type: "object"; readonly properties: { readonly queueOptions: { readonly allOf: readonly [{ readonly type: "object"; readonly properties: { readonly enabledBatchJobs: { readonly type: "boolean"; }; readonly maxBatchSize: { ...; }; }; r...' is not assignable to type 'JSONSchema'.\n` +
  `                    Type '{ readonly type: "object"; readonly properties: { readonly changesets: { readonly type: "object"; readonly properties: { readonly queueOptions: { readonly allOf: readonly [{ readonly type: "object"; readonly properties: { readonly enabledBatchJobs: { readonly type: "boolean"; }; readonly maxBatchSize: { ...; }; }; r...' is not assignable to type 'Readonly<{ $id?: string | undefined; $ref?: string | undefined; $schema?: string | undefined; $comment?: string | undefined; type?: JSONSchemaType | readonly JSONSchemaType[] | undefined; ... 43 more ...; [$JSONSchema]?: unique symbol | undefined; }>'.\n` +
  "                      Types of property 'properties' are incompatible.\n" +
  `                        Type '{ readonly changesets: { readonly type: "object"; readonly properties: { readonly queueOptions: { readonly allOf: readonly [{ readonly type: "object"; readonly properties: { readonly enabledBatchJobs: { readonly type: "boolean"; }; readonly maxBatchSize: { ...; }; }; readonly if: { ...; }; readonly then: { ...; }; r...' is not assignable to type 'Readonly<Record<string, JSONSchema>>'.\n` +
  `                          Property '"files"' is incompatible with index signature.\n` +
  `                            Type '{ readonly type: "object"; readonly properties: { readonly queueOptions: { readonly allOf: readonly [{ readonly type: "object"; readonly properties: { readonly enabledBatchJobs: { readonly type: "boolean"; }; readonly maxBatchSize: { readonly type: "integer"; }; }; readonly if: { ...; }; readonly then: { ...; }; rea...' is not assignable to type 'JSONSchema'.\n` +
  `                              Type '{ readonly type: "object"; readonly properties: { readonly queueOptions: { readonly allOf: readonly [{ readonly type: "object"; readonly properties: { readonly enabledBatchJobs: { readonly type: "boolean"; }; readonly maxBatchSize: { readonly type: "integer"; }; }; readonly if: { ...; }; readonly then: { ...; }; rea...' is not assignable to type 'Readonly<{ $id?: string | undefined; $ref?: string | undefined; $schema?: string | undefined; $comment?: string | undefined; type?: JSONSchemaType | readonly JSONSchemaType[] | undefined; ... 43 more ...; [$JSONSchema]?: unique symbol | undefined; }>'.\n` +
  "                                Types of property 'properties' are incompatible.\n" +
  `                                  Type '{ readonly queueOptions: { readonly allOf: readonly [{ readonly type: "object"; readonly properties: { readonly enabledBatchJobs: { readonly type: "boolean"; }; readonly maxBatchSize: { readonly type: "integer"; }; }; readonly if: { ...; }; readonly then: { ...; }; readonly else: { ...; }; }, { ...; }]; }; }' is not assignable to type 'Readonly<Record<string, JSONSchema>>'.\n` +
  `                                    Property '"queueOptions"' is incompatible with index signature.\n` +
  `                                      Type '{ readonly allOf: readonly [{ readonly type: "object"; readonly properties: { readonly enabledBatchJobs: { readonly type: "boolean"; }; readonly maxBatchSize: { readonly type: "integer"; }; }; readonly if: { readonly properties: { ...; }; }; readonly then: { ...; }; readonly else: { ...; }; }, { ...; }]; }' is not assignable to type 'JSONSchema'.\n` +
  `                                        Type '{ readonly allOf: readonly [{ readonly type: "object"; readonly properties: { readonly enabledBatchJobs: { readonly type: "boolean"; }; readonly maxBatchSize: { readonly type: "integer"; }; }; readonly if: { readonly properties: { ...; }; }; readonly then: { ...; }; readonly else: { ...; }; }, { ...; }]; }' is not assignable to type 'Readonly<{ $id?: string | undefined; $ref?: string | undefined; $schema?: string | undefined; $comment?: string | undefined; type?: JSONSchemaType | readonly JSONSchemaType[] | undefined; ... 43 more ...; [$JSONSchema]?: unique symbol | undefined; }>'.\n` +
  "                                          Types of property 'allOf' are incompatible.\n" +
  `                                            Type 'readonly [{ readonly type: "object"; readonly properties: { readonly enabledBatchJobs: { readonly type: "boolean"; }; readonly maxBatchSize: { readonly type: "integer"; }; }; readonly if: { readonly properties: { readonly enabledBatchJobs: { ...; }; }; }; readonly then: { ...; }; readonly else: { ...; }; }, { ...; }]' is not assignable to type 'readonly JSONSchema[]'.\n` +
  `                                              Type '{ readonly type: "object"; readonly properties: { readonly enabledBatchJobs: { readonly type: "boolean"; }; readonly maxBatchSize: { readonly type: "integer"; }; }; readonly if: { readonly properties: { readonly enabledBatchJobs: { ...; }; }; }; readonly then: { ...; }; readonly else: { ...; }; } | { ...; }' is not assignable to type 'JSONSchema'.\n` +
  `                                                Type '{ readonly type: "object"; readonly properties: { readonly enabledBatchJobs: { readonly "x-env-value": "FILES_QUEUE_ENABLED_BATCH_JOBS"; readonly default: false; }; readonly maxBatchSize: { readonly "x-env-value": "FILES_QUEUE_MAX_BATCH_SIZE"; }; }; }' is not assignable to type 'JSONSchema'.\n` +
  `                                                  Type '{ readonly type: "object"; readonly properties: { readonly enabledBatchJobs: { readonly "x-env-value": "FILES_QUEUE_ENABLED_BATCH_JOBS"; readonly default: false; }; readonly maxBatchSize: { readonly "x-env-value": "FILES_QUEUE_MAX_BATCH_SIZE"; }; }; }' is not assignable to type 'Readonly<{ $id?: string | undefined; $ref?: string | undefined; $schema?: string | undefined; $comment?: string | undefined; type?: JSONSchemaType | readonly JSONSchemaType[] | undefined; ... 43 more ...; [$JSONSchema]?: unique symbol | undefined; }>'.\n` +
  "                                                    Types of property 'properties' are incompatible.\n" +
  `                                                      Type '{ readonly enabledBatchJobs: { readonly "x-env-value": "FILES_QUEUE_ENABLED_BATCH_JOBS"; readonly default: false; }; readonly maxBatchSize: { readonly "x-env-value": "FILES_QUEUE_MAX_BATCH_SIZE"; }; }' is not assignable to type 'Readonly<Record<string, JSONSchema>>'.\n` +
  `                                                        Property '"maxBatchSize"' is incompatible with index signature.\n` +
  `                                                          Type '{ readonly "x-env-value": "FILES_QUEUE_MAX_BATCH_SIZE"; }' is not assignable to type 'JSONSchema'.\n`,
  stderr: '',
  signal: null,
  exitCode: 2 (Misuse of shell builtins),
  duration: 1335
}

Notice that filesQueueOptions.maxBatchSize have only x-env-value attribute. When I add some other attribute (such as $comment, the error disappears and the build completes.

PLZ help :) :shipit: :shipit: :shipit: :shipit:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions