@pdtf/schemas 2.0.0 → 2.1.2-1

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.
@@ -86,24 +86,57 @@ const extractOverlay = (sourceSchema, ref) => {
86
86
  jp.set(returnSchema, `${path}/${property}`, element[property]);
87
87
  }
88
88
  });
89
- const { discriminator } = element;
90
89
 
90
+ const { discriminator } = element;
91
91
  if (discriminator) {
92
92
  const { propertyName } = discriminator;
93
93
  element.oneOf.forEach((item, index) => {
94
94
  const discriminatorProperty = item.properties[propertyName];
95
- jp.set(
96
- returnSchema,
97
- `${path}/oneOf/${index}/properties/${propertyName}`,
98
- discriminatorProperty
99
- );
95
+ // copy const discriminator as-is
96
+ if (discriminatorProperty.const) {
97
+ jp.set(
98
+ returnSchema,
99
+ `${path}/oneOf/${index}/properties/${propertyName}/const`,
100
+ discriminatorProperty.const
101
+ );
102
+ } else {
103
+ // must be an enum
104
+ const discriminatorEnumPath = `${path}/oneOf/${index}/properties/${propertyName}/enum`;
105
+ // if a refEnum use that
106
+ const refEnum = `${ref}Enum`;
107
+ if (discriminatorProperty[refEnum]) {
108
+ jp.set(
109
+ returnSchema,
110
+ discriminatorEnumPath,
111
+ discriminatorProperty[refEnum]
112
+ );
113
+ } else {
114
+ // use the base enum
115
+ jp.set(
116
+ returnSchema,
117
+ discriminatorEnumPath,
118
+ discriminatorProperty.enum
119
+ );
120
+ }
121
+ }
100
122
  });
101
123
  }
102
124
  }
125
+
103
126
  const refRequired = `${ref}Required`;
104
127
  if (element[refRequired]) {
105
128
  jp.set(returnSchema, `${path}/required`, element[refRequired]);
106
129
  }
130
+
131
+ const refTitle = `${ref}Title`;
132
+ if (element[refTitle]) {
133
+ jp.set(returnSchema, `${path}/title`, element[refTitle]);
134
+ }
135
+
136
+ const refEnum = `${ref}Enum`;
137
+ if (element[refEnum]) {
138
+ jp.set(returnSchema, `${path}/enum`, element[refEnum]);
139
+ }
107
140
  });
108
141
  return returnSchema;
109
142
  };
@@ -136,6 +169,8 @@ const coreSchema = deleteProperties(combinedSchema, [
136
169
  "discriminator",
137
170
  ...extractFields.map((item) => `${item}Ref`),
138
171
  ...extractFields.map((item) => `${item}Required`),
172
+ ...extractFields.map((item) => `${item}Title`),
173
+ ...extractFields.map((item) => `${item}Enum`),
139
174
  ]);
140
175
 
141
176
  fs.writeFileSync(