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

HalForm property value not set #1717

Open
ecattez opened this issue Nov 12, 2021 · 2 comments · May be fixed by #2039
Open

HalForm property value not set #1717

ecattez opened this issue Nov 12, 2021 · 2 comments · May be fixed by #2039

Comments

@ecattez
Copy link

ecattez commented Nov 12, 2021

For the example, I've got products with product references.

Here's the code to set "select-product" relation.

private static ProductDto withSelectProductAffordance(ProductDto productDto) {
        SelectProductRequest request = SelectProductRequest.builder()
                .reference(productDto.getReference())
                .build();

        Link selectProductLink = linkTo(methodOn(SelectProductResource.class)
                .selectProduct(request))
                .withRel(ProductCatalogRelations.SELECT_PRODUCT);

        Link affordance = selectProductLink
                .andAffordance(afford(methodOn(SelectProductResource.class)
                        .selectProduct(request)));

        return productDto.add(affordance);
    }

Here's the current result of the collection of products:

{
  "_embedded": {
    "products": [
      {
        "reference": "product-001",
        "_links": {
          "select-product": {
            "href": "http://localhost:8080/api/select-product"
          }
        },
        "_templates": {
          "default": { ... },
          "selectProduct": {
            "method": "post",
            "properties": [
              {
                "name": "reference",
                "required": true,
                "type": "text"
              }
            ],
            "target": "http://localhost:8080/api/select-product"
          }
        }
      },
      { ... }
    ]
  }
}

I would expect to have product reference already set in selectProduct template like below:

"properties": [
  {
    "name": "reference",
    "required": true,
    "type": "text",
    "value": "product-001"
  }
]

It seems that value does not exist in AffordanceModel#PropertyMetadata but is a valid in the spec: https://rwcbook.github.io/hal-forms/#_code_value_code

I would also expect the template name to be the same as the link rel.

@Ickbinet
Copy link

"I would also expect the template name to be the same as the link rel."

A link can have more than one template associated.
The association is defined via the templates target or if no target is set via the self link.

"value": "product-001"

property.value is only set for options with a selected value, which is imho a bug. At least default values should be set.

What is your idea for an algo to detect that the value should be "product-001"?

@ecattez
Copy link
Author

ecattez commented Nov 12, 2021

I think it should take care of the request body, in my case SelectProductRequest. As I fulfilled explicitely the methodOn(...) with the request body, it should use the specified value.

It works like a charm with query params and path variables. So it should works with request body.

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

Successfully merging a pull request may close this issue.

2 participants