Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

Cannot parse link as resource if mapping link name from hal through @HalProperty() decorator #24

Open
vdytynyuk opened this issue Jan 5, 2018 · 3 comments

Comments

@vdytynyuk
Copy link

vdytynyuk commented Jan 5, 2018

Lets say I have a model which has a field expected as link.

Model:

export class Foo extends HalResource {
   @HalProperty('response.bar')
   bar: Bar; // it's link
}

When fetching Foo resource hal-parser spits out bar field as HalResorce not as Bar which is incorrect behavior. After some debugging I found that library passes to method Reflect.getMetadata link key as it is from hal json (e.g. 'response.bar') but MetadataMap contains field names and appropriate constructors in format that is specified in @HalProperty() decorator (e.g. 'bar'). Apparently proper constructor cannot be found by incorrect key and that leads to casting Bar field to HalResource.

@deblockt
Copy link
Owner

deblockt commented Jan 5, 2018

I don't understand the issue.

Can you provide you json ? I will try to reproduce your error.

@vdytynyuk
Copy link
Author

vdytynyuk commented Jan 5, 2018

@deblockt here's my json.

{
	"_links": {
		"self": {
			"href": "projects/2",
			"type": "application/hal+json"
		},
		"service.runs": {
			"href": "project/2/runs",
			"type": "application/hal+json"
		}
	},
	"key": 2,
	"name": "proj54"
}

Here's my Project model.

export class Project extends HalResource {
    @HalProperty()
    key: number;

    @HalProperty()
    name: string;

    @HalProperty('service.runs')
    runs: RunCollection;
}

export class RunCollection extends HalResource {
    @HalProperty()
    count: number;

    @HalProperty(Run)
    list: Run[];
}

After execution of await this.project.runs.fetch(true); field this.project.runs is HalResource not RunCollection.

@vdytynyuk
Copy link
Author

vdytynyuk commented Jan 11, 2018

I believe this PR should fix the problem. When will it be merged?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants