@sap/cds-dk 6.5.1 → 6.6.0
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.
- package/CHANGELOG.md +35 -0
- package/bin/activate.js +7 -0
- package/bin/add.js +1 -2
- package/bin/build/all.js +14 -9
- package/bin/cds.js +11 -8
- package/bin/compile/index.js +13 -3
- package/bin/env.js +16 -25
- package/bin/extend.js +8 -0
- package/bin/init.js +0 -3
- package/bin/login.js +3 -7
- package/bin/logout.js +2 -7
- package/bin/migrate.js +5 -2
- package/bin/watch.js +4 -5
- package/lib/client/activate.js +1 -1
- package/lib/client/helper/errors.js +2 -1
- package/lib/client/params.js +4 -3
- package/lib/client/pull.js +31 -5
- package/lib/client/push.js +3 -3
- package/lib/client/settings_manager.js +6 -6
- package/lib/client/subscription.js +1 -1
- package/lib/compile/asyncapi/channels.js +22 -0
- package/lib/compile/asyncapi/components/messageTraits/index.js +89 -0
- package/lib/compile/asyncapi/components/messages/index.js +150 -0
- package/lib/compile/asyncapi/components/schemas/annotations.js +13 -0
- package/lib/compile/asyncapi/components/schemas/array.js +8 -0
- package/lib/compile/asyncapi/components/schemas/cache.js +14 -0
- package/lib/compile/asyncapi/components/schemas/definition.js +187 -0
- package/lib/compile/asyncapi/components/schemas/enum.js +16 -0
- package/lib/compile/asyncapi/components/schemas/examples.js +10 -0
- package/lib/compile/asyncapi/components/schemas/index.js +14 -0
- package/lib/compile/asyncapi/components/schemas/localized.js +29 -0
- package/lib/compile/asyncapi/components/schemas/primitiveElement.js +41 -0
- package/lib/compile/asyncapi/components/schemas/ref.js +45 -0
- package/lib/compile/asyncapi/components/schemas/utils.js +108 -0
- package/lib/compile/asyncapi/index.js +226 -0
- package/lib/compile/asyncapi/message.js +13 -0
- package/lib/compile/asyncapi/utils.js +27 -0
- package/lib/compile/index.js +1 -0
- package/lib/compile/openapi/csdl2openapi.js +40 -18
- package/lib/import/message.js +3 -1
- package/lib/import/odata/metadataconverter/MetadataConverter.js +1 -1
- package/lib/import/odata/v2parser.js +131 -50
- package/lib/import/odata/v4parser.js +160 -68
- package/lib/import/openapi/importOpenAPI.js +14 -14
- package/lib/init/constants.js +1 -1
- package/lib/init/index.js +11 -21
- package/lib/init/template/_merging/registry-mta.js +15 -26
- package/lib/init/template/approuter/files/package.json +2 -2
- package/lib/init/template/approuter/index.js +6 -12
- package/lib/init/template/auditlog/files/auditlog.yaml +4 -1
- package/lib/init/template/auditlog/index.js +23 -8
- package/lib/init/template/cf-manifest/index.js +4 -14
- package/lib/init/template/connectivity/files/connectivity-proxy-info.yaml +2 -6
- package/lib/init/template/connectivity/files/values.yaml.hbs +5 -8
- package/lib/init/template/connectivity/index.js +2 -9
- package/lib/init/template/data/index.js +0 -4
- package/lib/init/template/destinations/files/destination.yaml +4 -1
- package/lib/init/template/destinations/index.js +25 -10
- package/lib/init/template/enterprise-messaging/files/event-mesh.yaml +4 -1
- package/lib/init/template/enterprise-messaging/files/values.yaml +1 -2
- package/lib/init/template/enterprise-messaging/index.js +28 -20
- package/lib/init/template/extensibility/index.js +23 -31
- package/lib/init/template/hana/files/hana.yaml +4 -1
- package/lib/init/template/hana/index.js +44 -24
- package/lib/init/template/helm/chart/templates/_helpers.tpl +12 -0
- package/lib/init/template/helm/chart/values.root.schema.json +40 -0
- package/lib/init/template/helm/chart/values.schema.json +32 -69
- package/lib/init/template/helm/index.js +26 -16
- package/lib/init/template/helm/subcharts/content-deployment/templates/_helpers.tpl +13 -26
- package/lib/init/template/helm/subcharts/content-deployment/templates/job.yaml +3 -3
- package/lib/init/template/helm/subcharts/content-deployment/templates/service-account.yaml +2 -0
- package/lib/init/template/helm/subcharts/content-deployment/templates/service-binding.yaml +3 -3
- package/lib/init/template/helm/subcharts/content-deployment/templating.md +37 -0
- package/lib/init/template/helm/subcharts/content-deployment/values.md +182 -185
- package/lib/init/template/helm/subcharts/content-deployment/values.schema.json +18 -22
- package/lib/init/template/helm/subcharts/content-deployment/values.yaml +2 -0
- package/lib/init/template/helm/subcharts/service-instance/Chart.yaml +5 -0
- package/lib/init/template/helm/subcharts/service-instance/templates/_helpers.tpl +65 -0
- package/lib/init/template/helm/subcharts/service-instance/templates/serviceinstance.yaml +23 -0
- package/lib/init/template/helm/subcharts/service-instance/templating.md +18 -0
- package/lib/init/template/helm/subcharts/service-instance/values-lint.yaml +2 -0
- package/lib/init/template/helm/subcharts/service-instance/values.md +186 -0
- package/lib/init/template/helm/subcharts/service-instance/values.schema.json +102 -0
- package/lib/init/template/helm/subcharts/service-instance/values.yaml +15 -0
- package/lib/init/template/html5-repo/files/html5-apps-repo-host.yaml +4 -1
- package/lib/init/template/html5-repo/index.js +30 -21
- package/lib/init/template/java/index.js +2 -5
- package/lib/init/template/kibana-logging/index.js +7 -10
- package/lib/init/template/lint/index.js +2 -3
- package/lib/init/template/mta/files/mta.yaml.hbs +4 -2
- package/lib/init/template/mta/index.js +7 -11
- package/lib/init/template/mtx/index.js +0 -5
- package/lib/init/template/multitenancy/files/java/package.json +16 -7
- package/lib/init/template/multitenancy/files/mta.yaml.hbs +11 -3
- package/lib/init/template/multitenancy/files/saas-registry-secret.yaml +9 -0
- package/lib/init/template/multitenancy/files/saas-registry.yaml +4 -17
- package/lib/init/template/multitenancy/files/service-manager.yaml +4 -1
- package/lib/init/template/multitenancy/files/values.yaml.hbs +15 -3
- package/lib/init/template/multitenancy/index.js +56 -31
- package/lib/init/template/nodejs/index.js +4 -7
- package/lib/init/template/notebook/index.js +1 -3
- package/lib/init/template/pipeline/index.js +2 -5
- package/lib/init/template/samples/index.js +6 -11
- package/lib/init/template/templateBase.js +10 -17
- package/lib/init/template/toggles/index.js +2 -6
- package/lib/init/template/xsuaa/files/values.yaml.hbs +0 -1
- package/lib/init/template/xsuaa/files/xsuaa.yaml +4 -1
- package/lib/init/template/xsuaa/index.js +27 -23
- package/lib/init/types.d.ts +0 -81
- package/lib/init/util/merge.js +23 -25
- package/lib/init/util/projectReader.js +27 -24
- package/lib/lint/Linter.js +31 -13
- package/lib/watch/livereload-server.js +21 -14
- package/lib/watch/node-watch.js +51 -49
- package/npm-shrinkwrap.json +546 -453
- package/package.json +2 -2
- package/readme.md +5 -0
- package/lib/init/template/connectivity/files/connectivity-binding.yaml +0 -9
- package/lib/init/template/connectivity/files/connectivity.yaml +0 -1
- package/lib/init/template/multitenancy/files/xsuaa.yaml +0 -1
- /package/lib/init/template/hana/files/{chart.yaml → hana-deployer.yaml} +0 -0
- /package/lib/init/template/html5-repo/files/{chart.yaml → html5-apps-deployer.yaml} +0 -0
- /package/lib/init/template/multitenancy/files/{chart.yaml → sidecar.yaml} +0 -0
|
@@ -43,6 +43,26 @@ const edmxncdsdatatype = {
|
|
|
43
43
|
"Edm.DateTimeOffset_a": "cds.Timestamp",
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
const extendedPrimitiveTypes = [
|
|
47
|
+
"Edm.Duration",
|
|
48
|
+
"Edm.Geography",
|
|
49
|
+
"Edm.GeographyPoint",
|
|
50
|
+
"Edm.GeographyLineString",
|
|
51
|
+
"Edm.GeographyPolygon",
|
|
52
|
+
"Edm.GeographyMultiPoint",
|
|
53
|
+
"Edm.GeographyMultiLineString",
|
|
54
|
+
"Edm.GeographyMultiPolygon",
|
|
55
|
+
"Edm.GeographyCollection",
|
|
56
|
+
"Edm.Geometry",
|
|
57
|
+
"Edm.GeometryPoint",
|
|
58
|
+
"Edm.GeometryLineString",
|
|
59
|
+
"Edm.GeometryPolygon",
|
|
60
|
+
"Edm.GeometryMultiPoint",
|
|
61
|
+
"Edm.GeometryMultiLineString",
|
|
62
|
+
"Edm.GeometryMultiPolygon",
|
|
63
|
+
"Edm.GeometryCollection"
|
|
64
|
+
];
|
|
65
|
+
|
|
46
66
|
const known_vocabularies = {
|
|
47
67
|
'Org.OData.Authorization.V1': 'Authorization',
|
|
48
68
|
'Org.OData.Aggregation.V1': 'Aggregation',
|
|
@@ -142,7 +162,7 @@ function _addNotNull(property, isCollection) {
|
|
|
142
162
|
}
|
|
143
163
|
|
|
144
164
|
function _typeWithCollections(property, type, isCollection) {
|
|
145
|
-
if (isCollection
|
|
165
|
+
if (isCollection) {
|
|
146
166
|
let typeKeys = Object.keys(type);
|
|
147
167
|
for (let i = 0; i < typeKeys.length; i++) {
|
|
148
168
|
if (typeKeys[i].startsWith("@")) {
|
|
@@ -164,13 +184,13 @@ function generatePropertyCsn(propertyType, isPrimaryKey) {
|
|
|
164
184
|
// primary key cannot be of type Collection
|
|
165
185
|
if (propertyType.$Collection)
|
|
166
186
|
throw new Error(messages.COLLECTION_IN_KEY);
|
|
167
|
-
if (propertyType.$Nullable
|
|
187
|
+
if (propertyType.$Nullable) {
|
|
168
188
|
console.log(warn("Expected key element to be not nullable"));
|
|
169
189
|
}
|
|
170
190
|
typeProperties["notNull"] = true;
|
|
171
191
|
}
|
|
172
192
|
else {
|
|
173
|
-
if ((propertyType.$Nullable
|
|
193
|
+
if ((!propertyType.$Nullable) && (propertyType.$Kind !== 'TypeDefinition')) {
|
|
174
194
|
typeProperties["notNull"] = true;
|
|
175
195
|
}
|
|
176
196
|
}
|
|
@@ -221,9 +241,13 @@ function generatePropertyCsn(propertyType, isPrimaryKey) {
|
|
|
221
241
|
typeProperties["@odata.Type"] = propertyType.$Type;
|
|
222
242
|
}
|
|
223
243
|
}
|
|
224
|
-
|
|
225
244
|
_typeWithCollections(property, typeProperties, propertyType.$Collection);
|
|
226
245
|
|
|
246
|
+
if (propertyType.$DefaultValue) {
|
|
247
|
+
if (propertyType.$Collection) console.log(warn("Type with Collection cannot have DefaultValue"));
|
|
248
|
+
_addDefaultValueObject(property, propertyType.$DefaultValue);
|
|
249
|
+
}
|
|
250
|
+
|
|
227
251
|
return property;
|
|
228
252
|
}
|
|
229
253
|
|
|
@@ -233,6 +257,10 @@ function _generateComplexTypePropertyCsn(propertyType) {
|
|
|
233
257
|
_typeWithCollections(property, type, propertyType.$Collection);
|
|
234
258
|
if (!propertyType.$Nullable) _addNotNull(property, propertyType.$Collection);
|
|
235
259
|
|
|
260
|
+
if (propertyType.$DefaultValue && !propertyType.$Collection) {
|
|
261
|
+
_addDefaultValueObject(property, propertyType.$DefaultValue);
|
|
262
|
+
}
|
|
263
|
+
|
|
236
264
|
return property;
|
|
237
265
|
}
|
|
238
266
|
|
|
@@ -243,6 +271,7 @@ function _generateTypeDefinitionPropertyCsn(propertyType) {
|
|
|
243
271
|
_includeExternalNamespaceAnnotation(propertyType, property);
|
|
244
272
|
_typeWithCollections(property, type, propertyType.$Collection);
|
|
245
273
|
if (!propertyType.$Nullable) _addNotNull(property, propertyType.$Collection);
|
|
274
|
+
// Verify: Can DefaultValue be present here?
|
|
246
275
|
|
|
247
276
|
return property;
|
|
248
277
|
}
|
|
@@ -342,6 +371,10 @@ function _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc, parserCo
|
|
|
342
371
|
let j;
|
|
343
372
|
let propertyType;
|
|
344
373
|
let enumType = {};
|
|
374
|
+
const entityTypeNames = parserContext.entityTypes.map(elementObject => {
|
|
375
|
+
return Object.keys(elementObject)[0];
|
|
376
|
+
});
|
|
377
|
+
|
|
345
378
|
parserContext.entityTypes.forEach(element => {
|
|
346
379
|
let key = Object.keys(element)[0];
|
|
347
380
|
let baseType = element[key].$BaseType;
|
|
@@ -364,13 +397,18 @@ function _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc, parserCo
|
|
|
364
397
|
// inheritance
|
|
365
398
|
if (baseType) {
|
|
366
399
|
entityCsn[key].includes = [];
|
|
367
|
-
|
|
368
|
-
|
|
400
|
+
if (entityTypeNames.includes(baseType)) {
|
|
401
|
+
entityCsn[key].includes.push(baseType);
|
|
402
|
+
}
|
|
403
|
+
else if (parserContext.entitySetToEntityTypeMap && parserContext.entitySetToEntityTypeMap.get(baseType)) {
|
|
369
404
|
baseType = _getBaseTypeEntityName(baseType, parserContext);
|
|
405
|
+
entityCsn[key].includes.push(baseType);
|
|
406
|
+
} else {
|
|
407
|
+
delete entityCsn[key].includes;
|
|
408
|
+
throw new Error(messages.UNRESOLVED_TYPE + `'${baseType}' in element: '${element}'.`);
|
|
370
409
|
}
|
|
371
|
-
entityCsn[key].includes.push(baseType);
|
|
372
410
|
if (!parserContext.entityTypeOpenEntries.includes(baseType)) parserContext.entityTypeOpenEntries.push(baseType);
|
|
373
|
-
}
|
|
411
|
+
}
|
|
374
412
|
if ((isAbstract || isOpenType) && !parserContext.entityTypeOpenEntries.includes(key)) {
|
|
375
413
|
parserContext.entityTypeOpenEntries.push(key);
|
|
376
414
|
}
|
|
@@ -412,8 +450,9 @@ function _generateCSNForEntityType(ignorePersistenceSkip, mockServerUc, parserCo
|
|
|
412
450
|
propertyType = element[key][property];
|
|
413
451
|
entityCsn[key].elements[property] = _generateTypeDefinitionPropertyCsn(propertyType);
|
|
414
452
|
} else {
|
|
415
|
-
let message = '"' + element[key][property].$Type + '" is not supported (in element:"' + property + '")';
|
|
416
|
-
console.log(warn(message));
|
|
453
|
+
// let message = '"' + element[key][property].$Type + '" is not supported (in element:"' + property + '")';
|
|
454
|
+
// console.log(warn(message));
|
|
455
|
+
throw new Error(messages.UNRESOLVED_TYPE + `'${element[key][property].$Type}' in element: '${property}'.`);
|
|
417
456
|
}
|
|
418
457
|
}
|
|
419
458
|
}
|
|
@@ -718,72 +757,93 @@ function _parseBounded(csnDefs, flag, parserContext) {
|
|
|
718
757
|
if (paramObj.$Collection && !paramType.items) {
|
|
719
758
|
csnDefs[boundedEntityName].actions[name].params[paramName] = {};
|
|
720
759
|
csnDefs[boundedEntityName].actions[name].params[paramName].items = paramType;
|
|
721
|
-
if(paramObj.$Nullable
|
|
760
|
+
if (!paramObj.$Nullable) {
|
|
722
761
|
csnDefs[boundedEntityName].actions[name].params[paramName].items["notNull"] = true;
|
|
723
762
|
}
|
|
724
763
|
} else {
|
|
725
764
|
csnDefs[boundedEntityName].actions[name].params[paramName] = paramType;
|
|
726
765
|
if (!paramType.items) {
|
|
727
|
-
if(paramObj.$Nullable
|
|
766
|
+
if (!paramObj.$Nullable) {
|
|
728
767
|
csnDefs[boundedEntityName].actions[name].params[paramName].notNull = true;
|
|
729
768
|
}
|
|
730
769
|
}
|
|
770
|
+
}
|
|
731
771
|
}
|
|
772
|
+
else {
|
|
773
|
+
// let message = '"' + paramObj.$Type + '" is not supported (in element:"' + name + '")';
|
|
774
|
+
// console.log(warn(message));
|
|
775
|
+
throw new Error(messages.UNRESOLVED_TYPE + `'${paramObj.$Type}' in element: '${name}'.`);
|
|
776
|
+
}
|
|
777
|
+
if (csnDefs[boundedEntityName].actions[name].params[paramName])
|
|
778
|
+
Object.assign(csnDefs[boundedEntityName].actions[name].params[paramName], annotations);
|
|
732
779
|
}
|
|
733
|
-
else {
|
|
734
|
-
let message = '"' + paramObj.$Type + '" is not supported (in element:"' + name + '")';
|
|
735
|
-
console.log(warn(message));
|
|
736
|
-
}
|
|
737
|
-
if (csnDefs[boundedEntityName].actions[name].params[paramName])
|
|
738
|
-
Object.assign(csnDefs[boundedEntityName].actions[name].params[paramName], annotations);
|
|
739
780
|
}
|
|
740
781
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
delete csnDefs[boundedEntityName].actions[name].params;
|
|
745
|
-
}
|
|
746
|
-
// add returns
|
|
747
|
-
if (obj[j].$ReturnType) {
|
|
748
|
-
let returnType = {};
|
|
749
|
-
let annotations = {};
|
|
750
|
-
// check if the return type is pre-defined, undefined or custom defined
|
|
751
|
-
if (edmxncdsdatatype[obj[j].$ReturnType.$Type] || edmxncdsdatatype[obj[j].$ReturnType.$Type + "_a"])
|
|
752
|
-
returnType = generatePropertyCsn(obj[j].$ReturnType, false);
|
|
753
|
-
else {
|
|
754
|
-
let type = _getDatatype(obj[j].$ReturnType.$Type, parserContext);
|
|
755
|
-
_includeExternalNamespaceAnnotation(obj[j].$ReturnType, annotations);
|
|
756
|
-
if (type) returnType["type"] = type;
|
|
782
|
+
// if parameters has no entries
|
|
783
|
+
if (csnDefs[boundedEntityName].actions[name].params && Object.keys(csnDefs[boundedEntityName].actions[name].params).length === 0) {
|
|
784
|
+
delete csnDefs[boundedEntityName].actions[name].params;
|
|
757
785
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
786
|
+
// add returns
|
|
787
|
+
if (obj[j].$ReturnType) {
|
|
788
|
+
let returnType = {};
|
|
789
|
+
let annotations = {};
|
|
790
|
+
let hasCdsTypeMapping = false;
|
|
791
|
+
// check if the return type is pre-defined, undefined or custom defined
|
|
792
|
+
if (edmxncdsdatatype[obj[j].$ReturnType.$Type] || edmxncdsdatatype[obj[j].$ReturnType.$Type + "_a"] ||
|
|
793
|
+
(!obj[j].$ReturnType.$Type && obj[j].$ReturnType.$MaxLength)
|
|
794
|
+
)
|
|
795
|
+
returnType = generatePropertyCsn(obj[j].$ReturnType, false);
|
|
796
|
+
else {
|
|
797
|
+
let type;
|
|
798
|
+
if (extendedPrimitiveTypes.includes(obj[j].$ReturnType.$Type)) {
|
|
799
|
+
hasCdsTypeMapping = true;
|
|
767
800
|
}
|
|
768
801
|
else {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
802
|
+
type = _getDatatype(obj[j].$ReturnType.$Type, parserContext);
|
|
803
|
+
}
|
|
804
|
+
_includeExternalNamespaceAnnotation(obj[j].$ReturnType, annotations);
|
|
805
|
+
if (type) returnType["type"] = type;
|
|
806
|
+
if (!type && !hasCdsTypeMapping) {
|
|
807
|
+
throw new Error(messages.UNRESOLVED_TYPE + `'${obj[j].$ReturnType.$Type}'`);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
if (Object.keys(returnType).length > 0) {
|
|
811
|
+
if (returnType.type || returnType.items.type) {
|
|
812
|
+
csnDefs[boundedEntityName].actions[name].returns = {};
|
|
813
|
+
// check if return type is a collection
|
|
814
|
+
if (obj[j].$ReturnType.$Collection && !returnType.items) {
|
|
815
|
+
csnDefs[boundedEntityName].actions[name].returns.items = returnType;
|
|
816
|
+
if (!obj[j].$ReturnType.$Nullable) {
|
|
817
|
+
csnDefs[boundedEntityName].actions[name].returns.items["notNull"] = true;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
else {
|
|
821
|
+
csnDefs[boundedEntityName].actions[name].returns = returnType;
|
|
822
|
+
if (!returnType.items) {
|
|
823
|
+
if (!obj[j].$ReturnType.$Nullable){
|
|
824
|
+
csnDefs[boundedEntityName].actions[name].returns["notNull"] = true;
|
|
825
|
+
}
|
|
773
826
|
}
|
|
774
827
|
}
|
|
775
828
|
}
|
|
829
|
+
} else {
|
|
830
|
+
csnDefs[boundedEntityName].actions[name].returns = {};
|
|
831
|
+
if (obj[j].$ReturnType.$Collection && !returnType.items) {
|
|
832
|
+
csnDefs[boundedEntityName].actions[name].returns = { "@odata.Type": obj[j].$ReturnType.$Type };
|
|
833
|
+
csnDefs[boundedEntityName].actions[name].returns.items = { "type": "cds.String" };
|
|
834
|
+
}
|
|
835
|
+
else
|
|
836
|
+
csnDefs[boundedEntityName].actions[name].returns = { "type": "cds.String", "@odata.Type": obj[j].$ReturnType.$Type };
|
|
776
837
|
}
|
|
838
|
+
if (csnDefs[boundedEntityName].actions[name].returns)
|
|
839
|
+
Object.assign(csnDefs[boundedEntityName].actions[name].returns, annotations);
|
|
777
840
|
} else {
|
|
778
|
-
|
|
779
|
-
|
|
841
|
+
if (obj[j].$Kind === 'Function')
|
|
842
|
+
throw new Error(messages.NO_RETURN_TYPE + `'${name}'.`);
|
|
780
843
|
}
|
|
781
|
-
if (csnDefs[boundedEntityName].actions[name].returns)
|
|
782
|
-
Object.assign(csnDefs[boundedEntityName].actions[name].returns, annotations)
|
|
783
844
|
}
|
|
784
845
|
}
|
|
785
846
|
}
|
|
786
|
-
}
|
|
787
847
|
});
|
|
788
848
|
}
|
|
789
849
|
}
|
|
@@ -829,9 +889,14 @@ function _generateCSNForComplexType(schemaData, parserContext) {
|
|
|
829
889
|
isAbstract = cTypes[element].$Abstract;
|
|
830
890
|
isOpenType = cTypes[element].$OpenType;
|
|
831
891
|
if (baseType) {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
892
|
+
if (parserContext.complexTypes[baseType]) {
|
|
893
|
+
complexCsn[element].includes = [];
|
|
894
|
+
complexCsn[element].includes.push(baseType);
|
|
895
|
+
if (!parserContext.complexTypeOpenEntries.includes(baseType)) parserContext.complexTypeOpenEntries.push(baseType);
|
|
896
|
+
}
|
|
897
|
+
else {
|
|
898
|
+
throw new Error(messages.UNRESOLVED_TYPE + `'${baseType}' in element: '${element}'.`);
|
|
899
|
+
}
|
|
835
900
|
}
|
|
836
901
|
if ((isAbstract || isOpenType) && !parserContext.complexTypeOpenEntries.includes(element)) {
|
|
837
902
|
parserContext.complexTypeOpenEntries.push(element);
|
|
@@ -854,8 +919,9 @@ function _generateCSNForComplexType(schemaData, parserContext) {
|
|
|
854
919
|
enumType = cTypes[element][property];
|
|
855
920
|
complexCsn[element].elements[property] = generatePropertyCsn(enumType, false);
|
|
856
921
|
} else {
|
|
857
|
-
let message = '"' + cTypes[element][property].$Type + '" is not supported (in element:"' + property + '")';
|
|
858
|
-
console.log(warn(message));
|
|
922
|
+
// let message = '"' + cTypes[element][property].$Type + '" is not supported (in element:"' + property + '")';
|
|
923
|
+
// console.log(warn(message));
|
|
924
|
+
throw new Error(messages.UNRESOLVED_TYPE + `'${cTypes[element][property].$Type}' in element: '${property}'.`);
|
|
859
925
|
}
|
|
860
926
|
} else if (property.startsWith("@")) {
|
|
861
927
|
complexCsn[element][property] = cTypes[element][property];
|
|
@@ -946,8 +1012,9 @@ function _parseUnbounded(schemaData, flag, parserContext) {
|
|
|
946
1012
|
}
|
|
947
1013
|
}
|
|
948
1014
|
} else {
|
|
949
|
-
let message = '"' + objData.$Parameter[i].$Type + '" is not supported (in element:"' + temp + '")';
|
|
950
|
-
console.log(warn(message));
|
|
1015
|
+
// let message = '"' + objData.$Parameter[i].$Type + '" is not supported (in element:"' + temp + '")';
|
|
1016
|
+
// console.log(warn(message));
|
|
1017
|
+
throw new Error(messages.UNRESOLVED_TYPE + `'${objData.$Parameter[i].$Type}' in element: '${temp}'.`);
|
|
951
1018
|
}
|
|
952
1019
|
if (obj[objType].params[objData.$Parameter[i].$Name])
|
|
953
1020
|
Object.assign(obj[objType].params[objData.$Parameter[i].$Name], annotations)
|
|
@@ -961,13 +1028,24 @@ function _parseUnbounded(schemaData, flag, parserContext) {
|
|
|
961
1028
|
if (objData.$ReturnType && Object.keys(objData.$ReturnType).length > 0 && obj) {
|
|
962
1029
|
let returnValue = {};
|
|
963
1030
|
let annotations = {};
|
|
1031
|
+
let hasCdsTypeMapping = false;
|
|
964
1032
|
// check if the return type is pre-defined, undefined or custom defined
|
|
965
|
-
if (edmxncdsdatatype[objData.$ReturnType.$Type] || edmxncdsdatatype[objData.$ReturnType.$Type + "_a"]
|
|
1033
|
+
if (edmxncdsdatatype[objData.$ReturnType.$Type] || edmxncdsdatatype[objData.$ReturnType.$Type + "_a"] ||
|
|
1034
|
+
(!objData.$ReturnType.$Type && objData.$ReturnType.$MaxLength)
|
|
1035
|
+
){
|
|
966
1036
|
returnValue = generatePropertyCsn(objData.$ReturnType, false);
|
|
967
1037
|
} else {
|
|
968
|
-
let type
|
|
1038
|
+
let type;
|
|
1039
|
+
if (extendedPrimitiveTypes.includes(objData.$ReturnType.$Type)) {
|
|
1040
|
+
hasCdsTypeMapping = true;
|
|
1041
|
+
} else {
|
|
1042
|
+
type = _getDatatype(objData.$ReturnType.$Type, parserContext);
|
|
1043
|
+
}
|
|
969
1044
|
_includeExternalNamespaceAnnotation(objData.$ReturnType, annotations);
|
|
970
1045
|
if (type) returnValue["type"] = type;
|
|
1046
|
+
if (!type && !hasCdsTypeMapping) {
|
|
1047
|
+
throw new Error(messages.UNRESOLVED_TYPE + `'${objData.$ReturnType.$Type}'`);
|
|
1048
|
+
}
|
|
971
1049
|
}
|
|
972
1050
|
if (Object.keys(returnValue).length > 0) {
|
|
973
1051
|
if (returnValue.type || returnValue.items.type) {
|
|
@@ -976,25 +1054,34 @@ function _parseUnbounded(schemaData, flag, parserContext) {
|
|
|
976
1054
|
if (objData.$ReturnType.$Collection && !returnValue.items) {
|
|
977
1055
|
obj[objType].returns.items = {};
|
|
978
1056
|
obj[objType].returns.items = returnValue;
|
|
979
|
-
if(objData.$ReturnType.$Nullable
|
|
1057
|
+
if (!objData.$ReturnType.$Nullable) {
|
|
980
1058
|
obj[objType].returns.items["notNull"] = true;
|
|
981
1059
|
}
|
|
982
1060
|
} else {
|
|
983
1061
|
obj[objType].returns = returnValue;
|
|
984
1062
|
if (!returnValue.items) {
|
|
985
|
-
if(objData.$ReturnType.$Nullable
|
|
986
|
-
|
|
987
|
-
|
|
1063
|
+
if (!objData.$ReturnType.$Nullable) {
|
|
1064
|
+
obj[objType].returns["notNull"] = true;
|
|
1065
|
+
}
|
|
988
1066
|
}
|
|
989
1067
|
}
|
|
990
1068
|
}
|
|
991
1069
|
}
|
|
992
1070
|
else {
|
|
993
|
-
|
|
994
|
-
|
|
1071
|
+
obj[objType].returns = {};
|
|
1072
|
+
// check if return type is a collection
|
|
1073
|
+
if ((objData.$ReturnType.$Collection && !returnValue.items)) {
|
|
1074
|
+
obj[objType].returns = { "@odata.Type":objData.$ReturnType.$Type };
|
|
1075
|
+
obj[objType].returns.items = {};
|
|
1076
|
+
obj[objType].returns.items = { "type": "cds.String" };
|
|
1077
|
+
} else
|
|
1078
|
+
obj[objType].returns = { "type": "cds.String", "@odata.Type": objData.$ReturnType.$Type };
|
|
995
1079
|
}
|
|
996
1080
|
if (obj[objType].returns)
|
|
997
1081
|
Object.assign(obj[objType].returns, annotations);
|
|
1082
|
+
} else {
|
|
1083
|
+
if (objData.$Kind === 'Function')
|
|
1084
|
+
throw new Error(messages.NO_RETURN_TYPE + `'${ub}'.`);
|
|
998
1085
|
}
|
|
999
1086
|
}
|
|
1000
1087
|
unboundedObj = Object.assign(unboundedObj, obj);
|
|
@@ -1097,7 +1184,12 @@ function _checkAnnotatationTerm(annotation, path, no_of_terms, targetString, voc
|
|
|
1097
1184
|
}
|
|
1098
1185
|
else if (vocab) {
|
|
1099
1186
|
if (vocab.includes(targetString.substring(targetString.indexOf('@') + 1, targetString.lastIndexOf('.')))) {
|
|
1100
|
-
|
|
1187
|
+
if (annotation[1][targetString]?.$Cast) {
|
|
1188
|
+
path[targetString] = Number(annotation[1][targetString].$Cast);
|
|
1189
|
+
}
|
|
1190
|
+
else {
|
|
1191
|
+
path[targetString] = annotation[1][targetString] === null ? true : annotation[1][targetString];
|
|
1192
|
+
}
|
|
1101
1193
|
}
|
|
1102
1194
|
}
|
|
1103
1195
|
}
|
|
@@ -129,32 +129,32 @@ function operations(context, csn, input) {
|
|
|
129
129
|
if (param.description) cdsParam["@description"] = param.description;
|
|
130
130
|
cdsParam["@openapi.in"] = param.in;
|
|
131
131
|
|
|
132
|
+
// only add the annotation "@openapi.explode" for true scenario
|
|
133
|
+
if (param.explode || param.style === "form")
|
|
134
|
+
cdsParam["@openapi.explode"] = true;
|
|
135
|
+
if (!param.explode)
|
|
136
|
+
delete cdsParam["@openapi.explode"];
|
|
137
|
+
|
|
132
138
|
if ((param.in === "path" && param.style && param.style !== "simple") ||
|
|
133
139
|
(param.in === "query" && param.style && param.style !== "form")
|
|
134
140
|
)
|
|
135
141
|
cdsParam["@openapi.style"] = param.style;
|
|
136
|
-
|
|
137
|
-
if (param.explode && param.style !== "form")
|
|
138
|
-
cdsParam["@openapi.explode"] = true;
|
|
139
|
-
|
|
140
|
-
if (param.explode === false &&
|
|
141
|
-
(param.style === "form" || (!param.style && param.in === "query"))
|
|
142
|
-
)
|
|
143
|
-
cdsParam["@openapi.explode"] = false;
|
|
144
|
-
|
|
145
|
-
if (param.in === "query" && param.collectionFormat === "csv")
|
|
146
|
-
cdsParam["@openapi.explode"] = false;
|
|
147
142
|
if (param.in === "query" && param.collectionFormat === "ssv")
|
|
148
143
|
cdsParam["@openapi.style"] = "spaceDelimited";
|
|
149
144
|
if (param.in === "query" && param.collectionFormat === "pipes")
|
|
150
145
|
cdsParam["@openapi.style"] = "pipeDelimited";
|
|
146
|
+
|
|
151
147
|
if (param.in === "query" && param.allowReserved === true)
|
|
152
148
|
cdsParam["@openapi.allowReserved"] = true;
|
|
149
|
+
|
|
153
150
|
if (param.required && param.in !== "path")
|
|
154
151
|
cdsParam["@openapi.required"] = true;
|
|
155
|
-
if (!param.required)
|
|
156
|
-
delete cdsParam.notNull;
|
|
157
152
|
|
|
153
|
+
if (!param.required) {
|
|
154
|
+
delete param.notNull;
|
|
155
|
+
if (param.default !== undefined)
|
|
156
|
+
cdsParam["default"] = { "val": param.default };
|
|
157
|
+
}
|
|
158
158
|
const name = cdsName(param.name);
|
|
159
159
|
if (name !== param.name) cdsParam["@openapi.name"] = param.name;
|
|
160
160
|
cdsOperation.params[name] = cdsParam;
|
|
@@ -382,8 +382,8 @@ function cdsType(
|
|
|
382
382
|
}
|
|
383
383
|
|
|
384
384
|
function addDefault(type, schema, forParameter) {
|
|
385
|
+
if (schema.default !== undefined) type.default = { val: schema.default };
|
|
385
386
|
if (forParameter) return;
|
|
386
|
-
if (schema.default) type.default = { val: schema.default };
|
|
387
387
|
}
|
|
388
388
|
|
|
389
389
|
function addPrimitiveExample(type, schema) {
|
package/lib/init/constants.js
CHANGED
package/lib/init/index.js
CHANGED
|
@@ -133,7 +133,7 @@ module.exports = class CDSGenerator {
|
|
|
133
133
|
this._initialize(null, options);
|
|
134
134
|
this._greetings(options._cmd);
|
|
135
135
|
|
|
136
|
-
if (!
|
|
136
|
+
if (!PROJECT_FILES.find(exists)) {
|
|
137
137
|
throw new Error(`The current folder doesn't seem to contain a project. None of the following files found: ${PROJECT_FILES.join(', ')}.`);
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -159,16 +159,6 @@ module.exports = class CDSGenerator {
|
|
|
159
159
|
await this._process();
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
async _findProjectFile(projectPath) {
|
|
163
|
-
for (const file of PROJECT_FILES) {
|
|
164
|
-
if (exists(path.join(projectPath, file))) {
|
|
165
|
-
return file;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
162
|
_initialize(projectName, options = {}) {
|
|
173
163
|
// deprecated, only for compatibility
|
|
174
164
|
if (options.verbose) {
|
|
@@ -176,8 +166,8 @@ module.exports = class CDSGenerator {
|
|
|
176
166
|
}
|
|
177
167
|
|
|
178
168
|
this.cwd = options.cwd || process.cwd();
|
|
179
|
-
|
|
180
|
-
this.projectName = path.basename(
|
|
169
|
+
cds.root = path.resolve(this.cwd, projectName || '.');
|
|
170
|
+
this.projectName = path.basename(cds.root);
|
|
181
171
|
|
|
182
172
|
this.options = options;
|
|
183
173
|
this._cleanupOptions();
|
|
@@ -186,7 +176,7 @@ module.exports = class CDSGenerator {
|
|
|
186
176
|
_greetings(cmd) {
|
|
187
177
|
switch (cmd) {
|
|
188
178
|
case COMMAND_INIT: {
|
|
189
|
-
const relativeProjectPath = path.relative(this.cwd,
|
|
179
|
+
const relativeProjectPath = path.relative(this.cwd, cds.root);
|
|
190
180
|
const folderName = (relativeProjectPath ? `.${path.sep}${relativeProjectPath}` : 'current folder');
|
|
191
181
|
LOG.info(`Creating new cap project in ${folderName}`);
|
|
192
182
|
break;
|
|
@@ -204,7 +194,7 @@ module.exports = class CDSGenerator {
|
|
|
204
194
|
}
|
|
205
195
|
|
|
206
196
|
async _process() {
|
|
207
|
-
DEBUG && DEBUG(`Project path: ${
|
|
197
|
+
DEBUG && DEBUG(`Project path: ${cds.root}`);
|
|
208
198
|
|
|
209
199
|
await this._validateOptions();
|
|
210
200
|
await this._fillTemplateList();
|
|
@@ -222,7 +212,7 @@ module.exports = class CDSGenerator {
|
|
|
222
212
|
async _createTemplate(filename) {
|
|
223
213
|
try {
|
|
224
214
|
const TemplateClass = require(`./template/${filename}`);
|
|
225
|
-
return new TemplateClass(this
|
|
215
|
+
return new TemplateClass(this);
|
|
226
216
|
} catch (err) {
|
|
227
217
|
if (err.code === 'MODULE_NOT_FOUND') {
|
|
228
218
|
const entries = (await readdir(path.join(__dirname, 'template')))
|
|
@@ -234,7 +224,7 @@ module.exports = class CDSGenerator {
|
|
|
234
224
|
);
|
|
235
225
|
const fuzzySearch = require('../../bin/util/fuzzySearch');
|
|
236
226
|
const [bestMatch] = fuzzySearch(filename, entries);
|
|
237
|
-
|
|
227
|
+
LOG.info(`Unknown facet '${term.bold(filename)}'. Did you mean ${term.bold(`cds add ${bestMatch}`)}?\n\nHaven't found the proper facet yet? Here are all supported facets:\n\n ${term.bold(entries.join('\n '))}\n`);
|
|
238
228
|
process.exit(1);
|
|
239
229
|
}
|
|
240
230
|
throw err;
|
|
@@ -330,7 +320,7 @@ module.exports = class CDSGenerator {
|
|
|
330
320
|
|
|
331
321
|
if (this.options._cmd === COMMAND_INIT) {
|
|
332
322
|
await this._validateProjectName(this.projectName);
|
|
333
|
-
await this._validateProjectFolder(this.
|
|
323
|
+
await this._validateProjectFolder(this.cwd);
|
|
334
324
|
}
|
|
335
325
|
}
|
|
336
326
|
|
|
@@ -351,11 +341,11 @@ module.exports = class CDSGenerator {
|
|
|
351
341
|
}
|
|
352
342
|
}
|
|
353
343
|
|
|
354
|
-
async _validateProjectFolder(
|
|
355
|
-
const existingProjectFile =
|
|
344
|
+
async _validateProjectFolder(cwd) {
|
|
345
|
+
const existingProjectFile = PROJECT_FILES.find(exists)
|
|
356
346
|
if (existingProjectFile) {
|
|
357
347
|
let message;
|
|
358
|
-
if (cwd ===
|
|
348
|
+
if (cwd === cds.root) {
|
|
359
349
|
message = `You seem to be working in a project which is already initialized. Use ${term.bold('cds add')} to add more features.`;
|
|
360
350
|
} else {
|
|
361
351
|
message = `You seem to be trying to initialize an existing project. Use a different project name instead.`;
|