codify-plugin-lib 1.0.96 → 1.0.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -115,6 +115,11 @@ export class ParsedResourceSettings {
115
115
  'determine the prompt to ask users during imports. It can\'t parse which parameters are needed when ' +
116
116
  'required is declared conditionally.');
117
117
  }
118
+ const importRequiredParameterNotInSchema = this.settings.import?.requiredParameters?.filter((p) => !(schema?.properties[p]));
119
+ if (schema && importRequiredParameterNotInSchema && importRequiredParameterNotInSchema.length > 0) {
120
+ throw new Error(`The following properties were declared in settings.import.requiredParameters but were not found in the schema:
121
+ ${JSON.stringify(importRequiredParameterNotInSchema, null, 2)}`);
122
+ }
118
123
  }
119
124
  validateParameterEqualsFn(parameter, key) {
120
125
  if (parameter.type === 'stateful') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.96",
3
+ "version": "1.0.97",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -65,4 +65,30 @@ describe('Resource options parser tests', () => {
65
65
 
66
66
  expect(() => new ParsedResourceSettings(option)).throws;
67
67
  })
68
+
69
+ it('Throws an error when an import.requiredParameters is declared improperly', () => {
70
+ const schema = {
71
+ '$schema': 'http://json-schema.org/draft-07/schema',
72
+ '$id': 'https://www.codifycli.com/git-clone.json',
73
+ 'title': 'Git-clone resource',
74
+ 'type': 'object',
75
+ 'properties': {
76
+ 'remote': {
77
+ 'type': 'string',
78
+ 'description': 'Remote tracking url to clone repo from. Equivalent to repository and only one should be specified'
79
+ },
80
+ },
81
+ 'additionalProperties': false,
82
+ }
83
+
84
+ const option: ResourceSettings<TestConfig> = {
85
+ id: 'typeId',
86
+ schema,
87
+ import: {
88
+ requiredParameters: ['import-error']
89
+ }
90
+ }
91
+
92
+ expect(() => new ParsedResourceSettings(option)).throws;
93
+ })
68
94
  })
@@ -3,10 +3,10 @@ import { StringIndexedObject } from 'codify-schemas';
3
3
 
4
4
  import {
5
5
  ParameterSetting,
6
- ResourceSettings,
7
- StatefulParameterSetting,
8
6
  resolveEqualsFn,
9
- resolveParameterTransformFn
7
+ resolveParameterTransformFn,
8
+ ResourceSettings,
9
+ StatefulParameterSetting
10
10
  } from './resource-settings.js';
11
11
  import { StatefulParameter as StatefulParameterImpl } from './stateful-parameter.js'
12
12
 
@@ -138,7 +138,6 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
138
138
  throw new Error(`Resource: ${this.id}. Stateful parameters are not allowed if multiples of a resource exist`)
139
139
  }
140
140
 
141
-
142
141
  const schema = this.settings.schema as JSONSchemaType<any>;
143
142
  if (!this.settings.import && (schema?.oneOf
144
143
  && Array.isArray(schema.oneOf)
@@ -167,6 +166,13 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
167
166
  'required is declared conditionally.'
168
167
  )
169
168
  }
169
+
170
+ const importRequiredParameterNotInSchema =
171
+ this.settings.import?.requiredParameters?.filter((p) => !(schema?.properties[p]))
172
+ if(schema && importRequiredParameterNotInSchema && importRequiredParameterNotInSchema.length > 0) {
173
+ throw new Error(`The following properties were declared in settings.import.requiredParameters but were not found in the schema:
174
+ ${JSON.stringify(importRequiredParameterNotInSchema, null, 2)}`)
175
+ }
170
176
  }
171
177
 
172
178
  private validateParameterEqualsFn(parameter: ParameterSetting, key: string): void {