Skip to content

Commit

Permalink
feat: Add support noImplicitOverride config option (#4687)
Browse files Browse the repository at this point in the history
* add support for method overrides

* added changelog

* update test-services

---------

Co-authored-by: Tom Frenken <[email protected]>
  • Loading branch information
shibeshduw and tomfrenken authored May 22, 2024
1 parent 0326eb8 commit 022adae
Show file tree
Hide file tree
Showing 89 changed files with 150 additions and 139 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-carpets-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sap-cloud-sdk/generator": minor
---

Generated clients support `noImplicitOverride` config option in `tsconfig.json`.
18 changes: 11 additions & 7 deletions packages/generator/src/entity/class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ describe('entity class generator generates a class', () => {
const staticProperties = classDeclaration.properties!.filter(
prop => prop.isStatic
);
expect(staticProperties.map(prop => [prop.name, prop.initializer])).toEqual(
[
['_entityName', `'${breakfastEntity.entitySetName}'`],
['_defaultBasePath', `'${foodService.serviceOptions.basePath}'`],
['_keys', "['EntityName','BreakfastTime']"]
]
);
expect(
staticProperties.map(prop => [
prop.name,
prop.initializer,
prop.hasOverrideKeyword
])
).toEqual([
['_entityName', `'${breakfastEntity.entitySetName}'`, true],
['_defaultBasePath', `'${foodService.serviceOptions.basePath}'`, true],
['_keys', "['EntityName','BreakfastTime']"]
]);
});

it('has expected instance properties', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/generator/src/entity/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function entityName(entity: VdmEntity): PropertyDeclarationStructure {
kind: StructureKind.Property,
name: prependPrefix('entityName'),
isStatic: true,
hasOverrideKeyword: true,
initializer: `'${entity.entitySetName}'`,
docs: [addLeadingNewline(`Technical entity name for ${entity.className}.`)]
};
Expand All @@ -78,6 +79,7 @@ function defaultBasePath(
kind: StructureKind.Property,
name: prependPrefix('defaultBasePath'),
isStatic: true,
hasOverrideKeyword: true,
initializer: `'${service.serviceOptions.basePath}'`,
docs: [addLeadingNewline('Default url path for the according service.')]
};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class Airlines<T extends DeSerializers = DefaultDeSerializers>
/**
* Technical entity name for Airlines.
*/
static _entityName = 'Airlines';
static override _entityName = 'Airlines';
/**
* Default url path for the according service.
*/
static _defaultBasePath =
static override _defaultBasePath =
'V4/(S(duh2c3dgb1c5lzc0bqwgyekc))/TripPinServiceRW/';
/**
* All key fields of the Airlines entity
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export class Airports<T extends DeSerializers = DefaultDeSerializers>
/**
* Technical entity name for Airports.
*/
static _entityName = 'Airports';
static override _entityName = 'Airports';
/**
* Default url path for the according service.
*/
static _defaultBasePath =
static override _defaultBasePath =
'V4/(S(duh2c3dgb1c5lzc0bqwgyekc))/TripPinServiceRW/';
/**
* All key fields of the Airports entity
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export class People<T extends DeSerializers = DefaultDeSerializers>
/**
* Technical entity name for People.
*/
static _entityName = 'People';
static override _entityName = 'People';
/**
* Default url path for the according service.
*/
static _defaultBasePath =
static override _defaultBasePath =
'V4/(S(duh2c3dgb1c5lzc0bqwgyekc))/TripPinServiceRW/';
/**
* All key fields of the People entity
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class Photos<T extends DeSerializers = DefaultDeSerializers>
/**
* Technical entity name for Photos.
*/
static _entityName = 'Photos';
static override _entityName = 'Photos';
/**
* Default url path for the according service.
*/
static _defaultBasePath =
static override _defaultBasePath =
'V4/(S(duh2c3dgb1c5lzc0bqwgyekc))/TripPinServiceRW/';
/**
* All key fields of the Photos entity
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test-packages/test-services-e2e/v4/test-service/TestEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export class TestEntity<T extends DeSerializers = DefaultDeSerializers>
/**
* Technical entity name for TestEntity.
*/
static _entityName = 'TestEntity';
static override _entityName = 'TestEntity';
/**
* Default url path for the according service.
*/
static _defaultBasePath = '/odata/test-service';
static override _defaultBasePath = '/odata/test-service';
/**
* All key fields of the TestEntity entity
*/
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class TestEntity50Prop<T extends DeSerializers = DefaultDeSerializers>
/**
* Technical entity name for TestEntity50Prop.
*/
static _entityName = 'TestEntity50Prop';
static override _entityName = 'TestEntity50Prop';
/**
* Default url path for the according service.
*/
static _defaultBasePath = '/odata/test-service';
static override _defaultBasePath = '/odata/test-service';
/**
* All key fields of the TestEntity50Prop entity
*/
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class TestEntityLink<T extends DeSerializers = DefaultDeSerializers>
/**
* Technical entity name for TestEntityLink.
*/
static _entityName = 'TestEntityLink';
static override _entityName = 'TestEntityLink';
/**
* Default url path for the according service.
*/
static _defaultBasePath = '/odata/test-service';
static override _defaultBasePath = '/odata/test-service';
/**
* All key fields of the TestEntityLink entity
*/
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export class TestEntityWithMultipleKeys<
/**
* Technical entity name for TestEntityWithMultipleKeys.
*/
static _entityName = 'TestEntityWithMultipleKeys';
static override _entityName = 'TestEntityWithMultipleKeys';
/**
* Default url path for the according service.
*/
static _defaultBasePath = '/odata/test-service';
static override _defaultBasePath = '/odata/test-service';
/**
* All key fields of the TestEntityWithMultipleKeys entity
*/
Expand Down
8 changes: 4 additions & 4 deletions test-packages/test-services-odata-common/common-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ export class CommonEntitySingleLink<
extends Entity
implements CommonEntitySingleLinkType<T>
{
static _entityName = 'A_CommonEntitySingleLink';
static override _entityName = 'A_CommonEntitySingleLink';
readonly _oDataVersion: any;
static _defaultBasePath = '/sap/opu/odata/sap/API_COMMON_SRV';
static override _defaultBasePath = '/sap/opu/odata/sap/API_COMMON_SRV';
static _keys = ['KeyProperty'];
declare keyProperty: DeserializedType<T, 'Edm.String'>;
declare stringProperty?: DeserializedType<T, 'Edm.String'> | null;
Expand Down Expand Up @@ -361,9 +361,9 @@ export class CommonEntity<T extends DeSerializers = DefaultDeSerializers>
extends Entity
implements CommonEntityType<T>
{
static _entityName = 'A_CommonEntity';
static override _entityName = 'A_CommonEntity';
readonly _oDataVersion: any;
static _defaultBasePath = '/sap/opu/odata/sap/API_COMMON_SRV';
static override _defaultBasePath = '/sap/opu/odata/sap/API_COMMON_SRV';
static _keys = ['KeyPropertyGuid', 'KeyPropertyString'];
declare keyPropertyGuid: DeserializedType<T, 'Edm.Guid'>;
declare keyPropertyString: DeserializedType<T, 'Edm.String'>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ function adjustCustomField(str: string): string {
}

function addODataVersion(str: string): string {
if (str.match(/static _entityName =.*/)) {
const nameString = str.match(/static _entityName =.*/)![0];
if (str.match(/static override _entityName =.*/)) {
const nameString = str.match(/static override _entityName =.*/)![0];
return str.replace(
nameString,
[nameString, 'readonly _oDataVersion: any;'].join(unixEOL)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 022adae

Please sign in to comment.