Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: contentful-userland/cf-content-types-generator
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.3.1
Choose a base ref
...
head repository: contentful-userland/cf-content-types-generator
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.3.2
Choose a head ref
  • 1 commit
  • 5 files changed
  • 1 contributor

Commits on Dec 13, 2020

  1. fix(output): no "any" return type (#73)

    Ensure a specific type for any field.
    marcolink authored Dec 13, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f7a9bcd View commit details
Showing with 469 additions and 4 deletions.
  1. +1 −1 src/cf-definitions-builder.ts
  2. +2 −3 src/renderer/cf-render-prop-link.ts
  3. +18 −0 test/cases/case-01.test.ts
  4. +410 −0 test/cases/fixtures/01-input.json
  5. +38 −0 test/cases/fixtures/01-output.txt
2 changes: 1 addition & 1 deletion src/cf-definitions-builder.ts
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ export default class CFDefinitionsBuilder {
private addProperty = (
file: SourceFile,
declaration: InterfaceDeclaration,
field: Field
field: Field,
): void => {
declaration.addProperty({
name: field.id,
5 changes: 2 additions & 3 deletions src/renderer/cf-render-prop-link.ts
Original file line number Diff line number Diff line change
@@ -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