Skip to content

Commit

Permalink
fix(output): no "any" return type (#73)
Browse files Browse the repository at this point in the history
Ensure a specific type for any field.
  • Loading branch information
marcolink authored Dec 13, 2020
1 parent cb5d8df commit f7a9bcd
Show file tree
Hide file tree
Showing 5 changed files with 469 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cf-definitions-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default class CFDefinitionsBuilder {
private addProperty = (
file: SourceFile,
declaration: InterfaceDeclaration,
field: Field
field: Field,
): void => {
declaration.addProperty({
name: field.id,
Expand Down
5 changes: 2 additions & 3 deletions src/renderer/cf-render-prop-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import {renderUnionType} from './render-union-type';

const linkContentType = (field: Pick<Field, 'id' | 'validations'>): string => {
const validations = linkContentTypeValidations(field);
return renderUnionType(validations?.length > 0 ? validations.map(moduleFieldsName) : ['any']);
return renderUnionType(validations?.length > 0 ? validations.map(moduleFieldsName) : [moduleFieldsName(field.id)]);
};

export const renderPropLink = (field: Pick<Field, 'id' | 'validations' | 'linkType'>) => {
const value = field.validations && field.validations.length === 0 ? 'any' : linkContentType(field);
return field.linkType === 'Entry'
? renderGenericType('Contentful.' + field.linkType, value)
? renderGenericType('Contentful.' + field.linkType, linkContentType(field))
: 'Contentful.' + field.linkType!;
};
18 changes: 18 additions & 0 deletions test/cases/case-01.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {expect} from "@oclif/test";
import {readFileSync} from "fs-extra";
import * as path from "path";
import CFDefinitionsBuilder from "../../src/cf-definitions-builder";

function testCase(id: string, description: string) {
it(description, () => {
let builder = new CFDefinitionsBuilder();
const fixture = require(`./fixtures/${id}-input.json`)
fixture.contentTypes.forEach((contentType: any) => builder.appendType(contentType));
expect(builder.toString(), description).to.eql(
readFileSync(path.resolve(__dirname, `./fixtures/${id}-output.txt`)).toString())
});
}

describe('cases', () => {
testCase('01', '"TypeBrandFields" correctly linked in "TypeProductFields"');
});
Loading

0 comments on commit f7a9bcd

Please sign in to comment.