MapColonies / MapColonies/schemas

Schema build bug

Open
#96 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
0
Forks
1
Avg merge
28m
Merged PRs (30d)
1

Description

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

```typescript
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
```json
{
"$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`
```ProcessOutput {
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>'.\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>'.\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>'.\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>'.\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:

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with build/schemas/vector/osmSyncTracker/v1.schema.ts and run npm run validate to reproduce the TypeScript error. Trace the reported JSONSchema incompatibility through the nested allOf and properties definitions, including the custom x-env-value fields. Done means the schema passes validation without the reported TS2344 error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.