feat: implemented new linting of entities to support new scorecards#2495
feat: implemented new linting of entities to support new scorecards#2495AlbinaBlazhko17 wants to merge 16 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 475e9f8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bb3606d to
475e9f8
Compare
|
|
||
| expect(resolvedType).toBeTruthy(); | ||
| expect(resolvedType.name).toBe('EntityFileDefault'); | ||
| expect(resolvedType.name).toBe('UserEntity'); // Falls back to first type when discriminator fails |
There was a problem hiding this comment.
Maybe it's better to put Entity first, so it becomes the default fallback?
| const { lintEntityFile } = await import('../lint.js'); | ||
| const { makeDocumentFromString, BaseResolver } = await import('../resolve.js'); | ||
|
|
||
| const entities = `- type: user |
| expect(entityTypes).toHaveProperty('DomainEntity'); | ||
| expect(entityTypes).toHaveProperty('TeamEntity'); | ||
| expect(entityTypes).toHaveProperty('Entity'); | ||
| expect(entityTypes).toHaveProperty('EntityFileArray'); |
There was a problem hiding this comment.
WHy don't we expect EntityFile/Default anymore?
There was a problem hiding this comment.
I see we use them in createEntityTypes.
| const discriminatedTypeName = value[discriminatedPropertyName]; | ||
| if (typeof discriminatedTypeName === 'string' && ctx[discriminatedTypeName]) { | ||
| return discriminatedTypeName; | ||
| const discriminatorValue = value[discriminatedPropertyName]; |
There was a problem hiding this comment.
Why changed discriminatedTypeName -> discriminatorValue? It's still a property name, not a value. Or am I missing something?
|
|
||
| // Store mapping from discriminator value to actual type name | ||
| if (typeof actualTypeName === 'string') { | ||
| discriminatorMapping[discriminatorValue] = actualTypeName; |
There was a problem hiding this comment.
Not sure why do we need to mutate it here. Don't we receive the discriminator mapping in the needed form already?
| typeof parsed === 'object' && | ||
| parsed !== null && |
There was a problem hiding this comment.
| typeof parsed === 'object' && | |
| parsed !== null && | |
| isPlainObject(parsed) |
| entityDefaultSchema: JSONSchema; | ||
| severity?: ProblemSeverity; | ||
| externalRefResolver?: BaseResolver; | ||
| assertionConfig?: Record<string, Assertion>; |
There was a problem hiding this comment.
Assertions should be converted a separate array, at least it's so for regular lint. Let's discuss this offline.
| } | ||
|
|
||
| const externalRefResolver = new BaseResolver(); | ||
| const entityDocument = makeDocumentFromString(JSON.stringify(entity, null, 2), 'entity.yaml'); |
There was a problem hiding this comment.
Why do we need to create a fake entity file on the fly? We should be able to resolve the real files.
| }); | ||
|
|
||
| return [...entityProblems, ...apiProblems]; | ||
| } else if (Object.keys(apiRules).length !== 0) { |
There was a problem hiding this comment.
Please use a utility function if possible (isEmptyObject or something like that).
| return subjectType; | ||
| } | ||
|
|
||
| export function transformScorecardRulesToAssertions( |
There was a problem hiding this comment.
Why not use the existing assertion/rules conversion mechanism?
What/Why/How?
lintEntityWithScorecardLevel, which will be used inportalto lint new entities with new scorecard functionality.lintSchemafor linting specific schema. If entity hasdata-schematype we need to lint only provided schema.Assertions(custom rules) inlintEntityFile.@redocly/config.json-schema-adapter.tsto handlenodeTypeNameif provided. Added returning ofdiscriminatorFuncfrom adapter to get proper rootType. Added functionality todiscriminatorFuncfor handling mapping the default naming and providednodeTypeName.Opened questions:
api-operations.lt,lte,gte, etc.) for arrays.Reference
Testing
Ran tests in
CLIandRealm.Screenshots (optional)
Check yourself
Security