OpenAPI: Improve anydata example 76/111976/3
authorlubos-cicut <lubos.cicut@pantheon.tech>
Tue, 4 Jun 2024 12:15:57 +0000 (14:15 +0200)
committerlubos-cicut <lubos.cicut@pantheon.tech>
Fri, 28 Jun 2024 06:40:51 +0000 (08:40 +0200)
Example template for anydata was
"<%s> ... </%s>", localName, localName
for both XML and JSON, which was incorrect.

Now we create empty object that is translatable to XML/JSON.
Into schema added description which informs the users that this is
unknown data and needs to be filled in by them.

JIRA: NETCONF-1319
Change-Id: I6440ff95f06ffa3d320ff50b93ee996ca1398052
Signed-off-by: lubos-cicut <lubos.cicut@pantheon.tech>
restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/model/PropertyEntity.java
restconf/restconf-openapi/src/test/resources/yang-document/controller-all.json
restconf/restconf-openapi/src/test/resources/yang-document/controller-typed-params.json
restconf/restconf-openapi/src/test/resources/yang-document/device-all.json
restconf/restconf-openapi/src/test/resources/yang-document/device-typed-params.json
restconf/restconf-openapi/src/test/resources/yang/typed-params.yang

index 84cf242491814b1adefed99da65225018bf14941..34baef96ef1cc9d1c76f40570c165c9fd4efb137 100644 (file)
@@ -292,11 +292,12 @@ public class PropertyEntity {
         assert (leafNode instanceof AnydataSchemaNode || leafNode instanceof AnyxmlSchemaNode);
 
         final var leafDescription = leafNode.getDescription().orElse("");
-        generator.writeStringField(DESCRIPTION, leafDescription);
+        generator.writeStringField(DESCRIPTION,
+            leafDescription + " (This is unknown data, need to be filled by user.)");
 
-        final var localName = leafNode.getQName().getLocalName();
-        generator.writeStringField(EXAMPLE, String.format("<%s> ... </%s>", localName, localName));
-        generator.writeStringField(TYPE, STRING_TYPE);
+        generator.writeObjectFieldStart(EXAMPLE);
+        generator.writeEndObject();
+        generator.writeStringField(TYPE, OBJECT_TYPE);
         if (!leafNode.getQName().getNamespace().equals(parentNamespace)) {
             // If the parent is not from the same model, define the child XML namespace.
             buildXmlParameter(leafNode);
index 647afab087aac4e6185e235295069b86eab1f7f2..fd5e55844c995ec73e605c3e2418d7f49d756397 100644 (file)
         ],
         "parameters": []
       }
+    },
+    "/rests/data/typed-params:typed/anydata={key}": {
+      "put": {
+        "description": "",
+        "summary": "PUT - typed-params - Controller - anydata",
+        "requestBody": {
+          "description": "anydata",
+          "content": {
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "typed-params:anydata": {
+                    "type": "array",
+                    "items": {
+                      "$ref": "#/components/schemas/typed-params_typed_anydata",
+                      "type": "object"
+                    }
+                  }
+                }
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/typed-params_typed_anydata"
+              }
+            }
+          }
+        },
+        "responses": {
+          "201": {
+            "description": "Created"
+          },
+          "204": {
+            "description": "Updated"
+          }
+        },
+        "tags": [
+          "Controller typed-params"
+        ],
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          }
+        ]
+      },
+      "patch": {
+        "description": "",
+        "summary": "PATCH - typed-params - Controller - anydata",
+        "requestBody": {
+          "description": "anydata",
+          "content": {
+            "application/yang-data+json": {
+              "schema": {
+                "properties": {
+                  "typed-params:anydata": {
+                    "type": "array",
+                    "items": {
+                      "$ref": "#/components/schemas/typed-params_typed_anydata",
+                      "type": "object"
+                    }
+                  }
+                }
+              }
+            },
+            "application/yang-data+xml": {
+              "schema": {
+                "$ref": "#/components/schemas/typed-params_typed_anydata"
+              }
+            }
+          }
+        },
+        "responses": {
+          "200": {
+            "description": "OK"
+          },
+          "204": {
+            "description": "Updated"
+          }
+        },
+        "tags": [
+          "Controller typed-params"
+        ],
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          }
+        ]
+      },
+      "delete": {
+        "description": "",
+        "summary": "DELETE - Controller - typed-params - anydata",
+        "responses": {
+          "204": {
+            "description": "Deleted"
+          }
+        },
+        "tags": [
+          "Controller typed-params"
+        ],
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          }
+        ]
+      },
+      "get": {
+        "description": "",
+        "summary": "GET - Controller - typed-params - anydata",
+        "responses": {
+          "200": {
+            "description": "200",
+            "content": {
+              "application/xml": {
+                "schema": {
+                  "$ref": "#/components/schemas/typed-params_typed_anydata"
+                }
+              },
+              "application/json": {
+                "schema": {
+                  "properties": {
+                    "anydata": {
+                      "type": "array",
+                      "items": {
+                        "$ref": "#/components/schemas/typed-params_typed_anydata",
+                        "type": "object"
+                      }
+                    }
+                  }
+                }
+              }
+            }
+          }
+        },
+        "tags": [
+          "Controller typed-params"
+        ],
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          },
+          {
+            "name": "content",
+            "in": "query",
+            "required": false,
+            "schema": {
+              "enum": [
+                "config",
+                "nonconfig",
+                "all"
+              ],
+              "type": "string"
+            }
+          }
+        ]
+      }
     }
   },
   "components": {
             "items": {
               "$ref": "#/components/schemas/typed-params_typed_uint32"
             }
+          },
+          "anydata": {
+            "description": "",
+            "items": {
+              "$ref": "#/components/schemas/typed-params_typed_anydata"
+            },
+            "type": "array"
           }
         },
         "xml": {
           "name": "output",
           "namespace": "urn:ietf:params:xml:ns:yang:test:action:types"
         }
+      },
+      "typed-params_typed_anydata": {
+        "properties": {
+          "key": {
+            "description": "",
+            "example": "Some key",
+            "type": "string"
+          },
+          "value": {
+            "description": "Anydata value. (This is unknown data, need to be filled by user.)",
+            "example": {},
+            "type": "object"
+          }
+        },
+        "title": "typed-params_typed_anydata",
+        "type": "object",
+        "xml": {
+          "name": "anydata",
+          "namespace": "urn:typed-params"
+        }
       }
     },
     "securitySchemes": {
index b9e9a94e1f3990c9a08e248942c186107e108d61..0fa4d30a3b0397a2fe8d7ef6f55f56dd2bd88179 100644 (file)
         "description": "",
         "summary": "PATCH - typed-params - Controller - enumeration"
       }
+    },
+    "/rests/data/typed-params:typed/anydata={key}": {
+      "put": {
+        "description": "",
+        "summary": "PUT - typed-params - Controller - anydata",
+        "requestBody": {
+          "description": "anydata",
+          "content": {
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "typed-params:anydata": {
+                    "type": "array",
+                    "items": {
+                      "$ref": "#/components/schemas/typed-params_typed_anydata",
+                      "type": "object"
+                    }
+                  }
+                }
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/typed-params_typed_anydata"
+              }
+            }
+          }
+        },
+        "responses": {
+          "201": {
+            "description": "Created"
+          },
+          "204": {
+            "description": "Updated"
+          }
+        },
+        "tags": [
+          "Controller typed-params"
+        ],
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          }
+        ]
+      },
+      "patch": {
+        "description": "",
+        "summary": "PATCH - typed-params - Controller - anydata",
+        "requestBody": {
+          "description": "anydata",
+          "content": {
+            "application/yang-data+json": {
+              "schema": {
+                "properties": {
+                  "typed-params:anydata": {
+                    "type": "array",
+                    "items": {
+                      "$ref": "#/components/schemas/typed-params_typed_anydata",
+                      "type": "object"
+                    }
+                  }
+                }
+              }
+            },
+            "application/yang-data+xml": {
+              "schema": {
+                "$ref": "#/components/schemas/typed-params_typed_anydata"
+              }
+            }
+          }
+        },
+        "responses": {
+          "200": {
+            "description": "OK"
+          },
+          "204": {
+            "description": "Updated"
+          }
+        },
+        "tags": [
+          "Controller typed-params"
+        ],
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          }
+        ]
+      },
+      "delete": {
+        "description": "",
+        "summary": "DELETE - Controller - typed-params - anydata",
+        "responses": {
+          "204": {
+            "description": "Deleted"
+          }
+        },
+        "tags": [
+          "Controller typed-params"
+        ],
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          }
+        ]
+      },
+      "get": {
+        "description": "",
+        "summary": "GET - Controller - typed-params - anydata",
+        "responses": {
+          "200": {
+            "description": "200",
+            "content": {
+              "application/xml": {
+                "schema": {
+                  "$ref": "#/components/schemas/typed-params_typed_anydata"
+                }
+              },
+              "application/json": {
+                "schema": {
+                  "properties": {
+                    "anydata": {
+                      "type": "array",
+                      "items": {
+                        "$ref": "#/components/schemas/typed-params_typed_anydata",
+                        "type": "object"
+                      }
+                    }
+                  }
+                }
+              }
+            }
+          }
+        },
+        "tags": [
+          "Controller typed-params"
+        ],
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          },
+          {
+            "name": "content",
+            "in": "query",
+            "required": false,
+            "schema": {
+              "enum": [
+                "config",
+                "nonconfig",
+                "all"
+              ],
+              "type": "string"
+            }
+          }
+        ]
+      }
     }
   },
   "components": {
             "items": {
               "$ref": "#/components/schemas/typed-params_typed_int16"
             }
+          },
+          "anydata": {
+            "description": "",
+            "items": {
+              "$ref": "#/components/schemas/typed-params_typed_anydata"
+            },
+            "type": "array"
           }
         },
         "xml": {
         },
         "title": "typed-params_typed_string",
         "type": "object"
+      },
+      "typed-params_typed_anydata": {
+        "properties": {
+          "key": {
+            "description": "",
+            "example": "Some key",
+            "type": "string"
+          },
+          "value": {
+            "description": "Anydata value. (This is unknown data, need to be filled by user.)",
+            "example": {},
+            "type": "object"
+          }
+        },
+        "title": "typed-params_typed_anydata",
+        "type": "object",
+        "xml": {
+          "name": "anydata",
+          "namespace": "urn:typed-params"
+        }
       }
     },
     "securitySchemes": {
index 18247a38cc9d9849824b2d21333b25bdd36c404d..091629188044bf864d421ff463d3db8cd5bcfd26 100644 (file)
         ],
         "parameters": []
       }
+    },
+    "/rests/data/nodes/node=123/yang-ext:mount/typed-params:typed/anydata={key}": {
+      "delete": {
+        "description": "",
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          }
+        ],
+        "responses": {
+          "204": {
+            "description": "Deleted"
+          }
+        },
+        "summary": "DELETE - 123 - typed-params - anydata",
+        "tags": [
+          "123 typed-params"
+        ]
+      },
+      "get": {
+        "description": "",
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          },
+          {
+            "name": "content",
+            "in": "query",
+            "required": false,
+            "schema": {
+              "enum": [
+                "config",
+                "nonconfig",
+                "all"
+              ],
+              "type": "string"
+            }
+          }
+        ],
+        "responses": {
+          "200": {
+            "content": {
+              "application/json": {
+                "schema": {
+                  "properties": {
+                    "anydata": {
+                      "items": {
+                        "$ref": "#/components/schemas/typed-params_typed_anydata",
+                        "type": "object"
+                      },
+                      "type": "array"
+                    }
+                  }
+                }
+              },
+              "application/xml": {
+                "schema": {
+                  "$ref": "#/components/schemas/typed-params_typed_anydata"
+                }
+              }
+            },
+            "description": "200"
+          }
+        },
+        "summary": "GET - 123 - typed-params - anydata",
+        "tags": [
+          "123 typed-params"
+        ]
+      },
+      "patch": {
+        "description": "",
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          }
+        ],
+        "requestBody": {
+          "content": {
+            "application/yang-data+json": {
+              "schema": {
+                "properties": {
+                  "typed-params:anydata": {
+                    "items": {
+                      "$ref": "#/components/schemas/typed-params_typed_anydata",
+                      "type": "object"
+                    },
+                    "type": "array"
+                  }
+                }
+              }
+            },
+            "application/yang-data+xml": {
+              "schema": {
+                "$ref": "#/components/schemas/typed-params_typed_anydata"
+              }
+            }
+          },
+          "description": "anydata"
+        },
+        "responses": {
+          "200": {
+            "description": "OK"
+          },
+          "204": {
+            "description": "Updated"
+          }
+        },
+        "summary": "PATCH - typed-params - 123 - anydata",
+        "tags": [
+          "123 typed-params"
+        ]
+      },
+      "put": {
+        "description": "",
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          }
+        ],
+        "requestBody": {
+          "content": {
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "typed-params:anydata": {
+                    "items": {
+                      "$ref": "#/components/schemas/typed-params_typed_anydata",
+                      "type": "object"
+                    },
+                    "type": "array"
+                  }
+                }
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/typed-params_typed_anydata"
+              }
+            }
+          },
+          "description": "anydata"
+        },
+        "responses": {
+          "201": {
+            "description": "Created"
+          },
+          "204": {
+            "description": "Updated"
+          }
+        },
+        "summary": "PUT - typed-params - 123 - anydata",
+        "tags": [
+          "123 typed-params"
+        ]
+      }
     }
   },
   "components": {
             "items": {
               "$ref": "#/components/schemas/typed-params_typed_bits"
             }
+          },
+          "anydata": {
+            "description": "",
+            "items": {
+              "$ref": "#/components/schemas/typed-params_typed_anydata"
+            },
+            "type": "array"
           }
         },
         "xml": {
           "name": "output",
           "namespace": "urn:ietf:params:xml:ns:yang:test:action:types"
         }
+      },
+      "typed-params_typed_anydata": {
+        "properties": {
+          "key": {
+            "description": "",
+            "example": "Some key",
+            "type": "string"
+          },
+          "value": {
+            "description": "Anydata value. (This is unknown data, need to be filled by user.)",
+            "example": {},
+            "type": "object"
+          }
+        },
+        "title": "typed-params_typed_anydata",
+        "type": "object",
+        "xml": {
+          "name": "anydata",
+          "namespace": "urn:typed-params"
+        }
       }
     },
     "securitySchemes": {
index a936d5b213e5fee3eae79f612fb37cbfc99ebfa1..4567ec6a420d686482c85443a1a0e0344eafdbb6 100644 (file)
         "description": "\n\nNote:\nIn example payload, you can see only the first data node child of the resource to be created, following the\nguidelines of RFC 8040, which allows us to create only one resource in POST request.\n",
         "summary": "POST - 123 - typed-params - typed-params"
       }
+    },
+    "/rests/data/nodes/node=123/yang-ext:mount/typed-params:typed/anydata={key}": {
+      "delete": {
+        "description": "",
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          }
+        ],
+        "responses": {
+          "204": {
+            "description": "Deleted"
+          }
+        },
+        "summary": "DELETE - 123 - typed-params - anydata",
+        "tags": [
+          "123 typed-params"
+        ]
+      },
+      "get": {
+        "description": "",
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          },
+          {
+            "name": "content",
+            "in": "query",
+            "required": false,
+            "schema": {
+              "enum": [
+                "config",
+                "nonconfig",
+                "all"
+              ],
+              "type": "string"
+            }
+          }
+        ],
+        "responses": {
+          "200": {
+            "content": {
+              "application/json": {
+                "schema": {
+                  "properties": {
+                    "anydata": {
+                      "items": {
+                        "$ref": "#/components/schemas/typed-params_typed_anydata",
+                        "type": "object"
+                      },
+                      "type": "array"
+                    }
+                  }
+                }
+              },
+              "application/xml": {
+                "schema": {
+                  "$ref": "#/components/schemas/typed-params_typed_anydata"
+                }
+              }
+            },
+            "description": "200"
+          }
+        },
+        "summary": "GET - 123 - typed-params - anydata",
+        "tags": [
+          "123 typed-params"
+        ]
+      },
+      "patch": {
+        "description": "",
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          }
+        ],
+        "requestBody": {
+          "content": {
+            "application/yang-data+json": {
+              "schema": {
+                "properties": {
+                  "typed-params:anydata": {
+                    "items": {
+                      "$ref": "#/components/schemas/typed-params_typed_anydata",
+                      "type": "object"
+                    },
+                    "type": "array"
+                  }
+                }
+              }
+            },
+            "application/yang-data+xml": {
+              "schema": {
+                "$ref": "#/components/schemas/typed-params_typed_anydata"
+              }
+            }
+          },
+          "description": "anydata"
+        },
+        "responses": {
+          "200": {
+            "description": "OK"
+          },
+          "204": {
+            "description": "Updated"
+          }
+        },
+        "summary": "PATCH - typed-params - 123 - anydata",
+        "tags": [
+          "123 typed-params"
+        ]
+      },
+      "put": {
+        "description": "",
+        "parameters": [
+          {
+            "name": "key",
+            "in": "path",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          }
+        ],
+        "requestBody": {
+          "content": {
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "typed-params:anydata": {
+                    "items": {
+                      "$ref": "#/components/schemas/typed-params_typed_anydata",
+                      "type": "object"
+                    },
+                    "type": "array"
+                  }
+                }
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/typed-params_typed_anydata"
+              }
+            }
+          },
+          "description": "anydata"
+        },
+        "responses": {
+          "201": {
+            "description": "Created"
+          },
+          "204": {
+            "description": "Updated"
+          }
+        },
+        "summary": "PUT - typed-params - 123 - anydata",
+        "tags": [
+          "123 typed-params"
+        ]
+      }
     }
   },
   "components": {
             "items": {
               "$ref": "#/components/schemas/typed-params_typed_int16"
             }
+          },
+          "anydata": {
+            "description": "",
+            "items": {
+              "$ref": "#/components/schemas/typed-params_typed_anydata"
+            },
+            "type": "array"
           }
         },
         "xml": {
         },
         "title": "typed-params_typed_string",
         "type": "object"
+      },
+      "typed-params_typed_anydata": {
+        "properties": {
+          "key": {
+            "description": "",
+            "example": "Some key",
+            "type": "string"
+          },
+          "value": {
+            "description": "Anydata value. (This is unknown data, need to be filled by user.)",
+            "example": {},
+            "type": "object"
+          }
+        },
+        "title": "typed-params_typed_anydata",
+        "type": "object",
+        "xml": {
+          "name": "anydata",
+          "namespace": "urn:typed-params"
+        }
       }
     },
     "securitySchemes": {
index 67bc93cd78eeae1b864c5e3e644f4db829506277..b5dbc3b3a70468012b676da4489c4783db2fef13 100644 (file)
@@ -172,5 +172,14 @@ module typed-params {
                 type string;
             }
         }
+        list anydata {
+            key key;
+            leaf key {
+                type string;
+            }
+            anydata value {
+                description "Anydata value.";
+            }
+        }
     }
 }
\ No newline at end of file