Skip to content

Restconf server does NOT support multiple key requests on list nodes. #66

@Pawel-Guzik

Description

@Pawel-Guzik

Side Note: Below bug report based on GET request, but this case also applies to DELETE


Actual behavior
In the case of the Yang node request with multiple key values, restconf server response contains only resource coupled with the first key.

  • Considering the following request
    GET .../<list_node>=<key_1>,<key_2>,...,<key_n>
  • Server responds with:
    {<key_1_resource_value>}

Expected behavior
In the case of the Yang node request with multiple key values, restconf server response contains all resources coupled with each requested key.

  • Considering the following request
    GET .../<list_node>=<key_1>,<key_2>,...,<key_n>
  • Server responds with:
    {<key_1_resource_value>, <key_2_resource_value>,...,<key_n_resource_value>}

Reproduction steps
Code used to reproduce the bug can be found in the section below

  1. Start restconf server - go run main.go
  2. Create more than 1 resource within the books Yang node (it is already done, by configuration within startup.json file)
  3. Perform read request, requesting more than 1 resource from the books list-node
    Request:
    curl -X GET http://localhost:8080/restconf/data/library:books=0,1
    Response:
    {"book-id":0,"title":"Book nr 0"}

Code used to reproduce a bug
yang/library.yang

module library {
	revision 2024-10-03;  
	      list books {
	      key book-id;
      
              leaf book-id {
	          description "unique id for book";
                  type int32;
              }
      
              leaf title {
	          description "title of the book";
                  type string;
              }
	}
}

main.go

package main

import (
	"github.com/freeconf/restconf"
	"github.com/freeconf/restconf/device"
	"github.com/freeconf/yang/fc"
	"github.com/freeconf/yang/nodeutil"
	"github.com/freeconf/yang/source"
)

type Book struct {
	BookId int
	Title  string
}

type Library struct {
	Books []*Book
}

type Model struct {
	Library *Library
}

func NewLibrary() *Library {
	lib := &Library{
		Books: []*Book{},
	}
	return lib
}

func main() {
	fc.DebugLog(true)
	ypath := source.Any(source.Path("yang"), restconf.InternalYPath)
	d := device.New(ypath)
	rootNode := &nodeutil.Node{Object: NewLibrary()}
	d.Add("library", rootNode)
	restconf.NewServer(d)
	d.ApplyStartupConfigFile("./startup.json")
	select {}
}

startup.json

{
    "fc-restconf": {
        "web": {
            "port": ":8080"
        }
    },
    "library": {
        "books": [
            {
                "book-id": 0,
                "title": "Book nr 0"
            },
            {
                "book-id": 1,
                "title": "Book nr 1"
            }
        ]
    }
}

Additional informations
Related RESTCONF rfc section - https://datatracker.ietf.org/doc/html/rfc8040#section-3.5.3
go.mod content:

module multiplekeys

go 1.23.0

require (
	github.com/freeconf/restconf v0.0.0-20240627124255-9543e7933a6e // indirect
	github.com/freeconf/yang v0.0.0-20240126135339-ef92ddeb9f99 // indirect
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions