[NETCONF-1165] OpenAPI generate multiple resources/subresources in POST request Created: 22/Sep/23  Updated: 31/Oct/23  Resolved: 31/Oct/23

Status: Resolved
Project: netconf
Component/s: restconf-openapi
Affects Version/s: None
Fix Version/s: 7.0.0, 4.0.9, 6.0.5, 5.0.10

Type: Bug Priority: Medium
Reporter: Peter Suna Assignee: Samuel Schneider
Resolution: Done Votes: 0
Labels: pt
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File toaster-example@2009-11-20.yang    
Issue Links:
Relates
relates to NETCONF-1164 OpenAPI POST request generates incorr... Resolved

 Description   

For provided model, OpenAPI generate incorrect JSON example:

curl -X 'POST' \
  'http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=36001-sim-device/yang-ext:mount/toaster-example:lst=data/cont1/cont11' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -d '{
  "lf111": 0,
  "lf112": "Some lf112"
}' 

Response:

{
  "errors": {
    "error": [
      {
        "error-tag": "operation-failed",
        "error-info": "Normalized Node result was already set.",
        "error-message": "Error parsing json input: Failed to create new parse result data. Are you creating multiple resources/subresources in POST request?",
        "error-type": "application"
      }
    ]
  }
} 

 
Operation object:

  "post": {
    "deprecated": false,
    "tags": [
      "36001-sim-device toaster-example"
    ],
    "parameters": [
      {
        "name": "lf1",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        }
      }
    ],
    "requestBody": {
      "content": {
        "application/json": {
          "schema": {
            "properties": {
              "cont11": {
                "$ref": "#/components/schemas/toaster-example_lst_cont1_cont11"
              }
            }
          }
        },
        "application/xml": {
          "schema": {
            "$ref": "#/components/schemas/toaster-example_lst_cont1_cont11"
          }
        }
      },
      "description": "cont11"
    }
  }

Schema object:

  "toaster-example_lst_cont1_cont11": {
    "properties": {
      "lf111": {
        "description": "",
        "type": "integer",
        "example": 0,
        "format": "int64",
        "uniqueItems": false
      },
      "lf112": {
        "description": "",
        "type": "string",
        "example": "Some lf112",
        "uniqueItems": false
      }
    },
    "xml": {
      "name": "cont11",
      "namespace": "http://netconfcentral.org/ns/toaster/example",
      "attribute": false,
      "wrapped": false
    },
    "description": "",
    "title": "toaster-example_lst_cont1_cont11",
    "type": "object"
  }  


 Comments   
Comment by Ivan Hrasko [ 27/Sep/23 ]

The issue is that we can have only one child of creating resource in the payload. This has been fixed for lists and container in NETCONF-1054. Now we have to deal with leafs.

Comment by Ivan Hrasko [ 27/Sep/23 ]

We can do this for JSON but there are problems for XML that:

  1. We are not generating schemas for leafs - and we do not want to.
  2. We cannot reference (via $ref) something which is not in schemas.
  3. We cannot even "manually" create payload as done in NETCONF-1054 because we have no XML root element for single value.

Thus we can only eliminate this kind requests - when there is no list or container child available.

Comment by Ivan Hrasko [ 27/Sep/23 ]

Thus NETCONF-1164 and NETCONF-1165 can be fixed by one patch.

Generated at Wed Feb 07 20:16:50 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.