Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove warning for microfrontends #24046

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions generators/base-application/support/prepare-entity.mts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
import { fieldIsEnum } from './field-utils.mjs';

import { Entity } from '../types/index.mjs';
import type CoreGenerator from '../../base-core/generator.mjs';

const { sortedUniq, intersection } = _;

Expand Down Expand Up @@ -284,7 +285,10 @@ export function derivedPrimaryKeyProperties(primaryKey) {
});
}

export function prepareEntityPrimaryKeyForTemplates(entityWithConfig, generator, enableCompositeId = true) {
export function prepareEntityPrimaryKeyForTemplates(
this: CoreGenerator | void,
{ entity: entityWithConfig, enableCompositeId = true, application }: { entity: any; enableCompositeId?: boolean; application?: any },
) {
const idFields = entityWithConfig.fields.filter(field => field.id);
const idRelationships = entityWithConfig.relationships.filter(relationship => relationship.id);
let idCount = idFields.length + idRelationships.length;
Expand All @@ -294,9 +298,8 @@ export function prepareEntityPrimaryKeyForTemplates(entityWithConfig, generator,
if (idField) {
idField.id = true;
} else {
if (entityWithConfig.microserviceName) {
// TODO ignore warning for microfrontends.
generator.log.warn("Microservice entities should have a custom id to make sure gateway and microservice types won't conflict");
if (entityWithConfig.microserviceName && !application?.microfrontend) {
this?.log.warn("Microservice entities should have a custom id to make sure gateway and microservice types won't conflict");
}
idField = {
fieldName: 'id',
Expand Down Expand Up @@ -413,7 +416,7 @@ export function prepareEntityPrimaryKeyForTemplates(entityWithConfig, generator,
idField.dynamic = false;
// Allow ids type to be empty and fallback to default type for the database.
if (!idField.fieldType) {
idField.fieldType = generator.jhipsterConfig.pkType ?? getDatabaseTypeData(entityWithConfig.databaseType).defaultPrimaryKeyType;
idField.fieldType = application?.pkType ?? getDatabaseTypeData(entityWithConfig.databaseType).defaultPrimaryKeyType;
}
primaryKeyName = idField.fieldName;
primaryKeyType = idField.fieldType;
Expand Down
12 changes: 6 additions & 6 deletions generators/base-application/support/prepare-entity.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('generator - base-application - support - prepareEntity', () => {
fields: [{ fieldName: 'id', fieldType: 'CustomType', path: ['id'], relationshipsPath: [] }],
};
beforeEach(() => {
entity = prepareEntityPrimaryKeyForTemplates(entity, defaultGenerator);
entity = prepareEntityPrimaryKeyForTemplates({ entity });
});
it('should adopt id field as @Id', () => {
expect(entity.fields[0]).to.eql({
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('generator - base-application - support - prepareEntity', () => {
],
};
beforeEach(() => {
entity = prepareEntityPrimaryKeyForTemplates(entity, defaultGenerator);
entity = prepareEntityPrimaryKeyForTemplates({ entity });
});
it('should not adopt id field as @Id', () => {
expect(entity.fields[0]).to.eql({
Expand Down Expand Up @@ -177,10 +177,10 @@ describe('generator - base-application - support - prepareEntity', () => {
],
};

entity1 = prepareEntityPrimaryKeyForTemplates(entity1, defaultGenerator, true);
entity2 = prepareEntityPrimaryKeyForTemplates(entity2, defaultGenerator, true);
entity3 = prepareEntityPrimaryKeyForTemplates(entity3, defaultGenerator, true);
entity4 = prepareEntityPrimaryKeyForTemplates(entity4, defaultGenerator, true);
entity1 = prepareEntityPrimaryKeyForTemplates({ entity: entity1, enableCompositeId: true });
entity2 = prepareEntityPrimaryKeyForTemplates({ entity: entity2, enableCompositeId: true });
entity3 = prepareEntityPrimaryKeyForTemplates({ entity: entity3, enableCompositeId: true });
entity4 = prepareEntityPrimaryKeyForTemplates({ entity: entity4, enableCompositeId: true });
});

it('should prepare correct primaryKey for entity1', () => {
Expand Down
4 changes: 2 additions & 2 deletions generators/bootstrap-application-server/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ export default class BoostrapApplicationServer extends BaseApplicationGenerator
prepareEntity({ entity }) {
prepareEntityServerForTemplates(entity);
},
preparePrimaryKey({ entity }) {
preparePrimaryKey({ entity, application }) {
// If primaryKey doesn't exist, create it.
if (!entity.embedded && !entity.primaryKey) {
prepareEntityPrimaryKeyForTemplates(entity, this);
prepareEntityPrimaryKeyForTemplates.call(this, { entity, application });
}
},
});
Expand Down
2 changes: 1 addition & 1 deletion generators/liquibase/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default class LiquibaseGenerator extends BaseEntityChangesGenerator {
prepareEntity(entity, this, application);
prepareEntityForServer(entity);
if (!entity.embedded && !entity.primaryKey) {
prepareEntityPrimaryKeyForTemplates(entity, this);
prepareEntityPrimaryKeyForTemplates.call(this, { entity, application });
}
for (const field of entity.fields ?? []) {
prepareField(entity, field, this);
Expand Down