Amartus / yang2swagger

Yang to swagger generator
Eclipse Public License 1.0
32 stars 21 forks source link

JSON Body structure according to RESTCONF standard #37

Closed arthurMll closed 4 years ago

arthurMll commented 5 years ago

Reviewing the current output of the conversion tool, I have detected an issue with the structure of the body message included in the GET operations expected schemas.

According to RESCONF Specification RFC8040 GET examples point to YANG Container nodes and list nodes, both include the referenced object included in the expected body message, e.g.,:

Container example https://tools.ietf.org/html/rfc8040#appendix-B.3.1

GET /restconf/data/example-events:events?\ content=all HTTP/1.1 Host: example.com Accept: application/yang-data+json

The server might respond as follows:

  HTTP/1.1 200 OK
  Date: Thu, 26 Jan 2017 20:56:30 GMT
  Server: example-server
  Cache-Control: no-cache
  Content-Type: application/yang-data+json

  {
    "example-events:events" : {
      "event" : [
        {
          "name" : "interface-up",
          "description" : "Interface up notification count",
          "event-count" : 42
        },
        {
          "name" : "interface-down",
          "description" : "Interface down notification count",
          "event-count" : 4
        }
      ]
    }
  }

List ítem example https://tools.ietf.org/html/rfc8040#appendix-B.3.9

GET /restconf/data/example:interfaces/interface=eth1 HTTP/1.1 Host: example.com Accept: application/yang-data+json

The server might respond as follows:

  HTTP/1.1 200 OK
  Date: Thu, 26 Jan 2017 20:56:30 GMT
  Server: example-server
  Content-Type: application/yang-data+json

  {
    "example:interface" : [
      {
        "name" : "eth1",
        "status" : "up"
      }
    ]
  }

However the output of the current versión of the tool generates the content of the object itself, without the name of the container/list node, e.g., for the previous examples the output would be:

Container current Swagger spec example https://tools.ietf.org/html/rfc8040#appendix-B.3.1

GET /restconf/data/example-events:events?\ content=all HTTP/1.1 Host: example.com Accept: application/yang-data+json

The server might respond as follows:

  HTTP/1.1 200 OK
  Date: Thu, 26 Jan 2017 20:56:30 GMT
  Server: example-server
  Cache-Control: no-cache
  Content-Type: application/yang-data+json

  {
      "event" : [
        {
          "name" : "interface-up",
          "description" : "Interface up notification count",
          "event-count" : 42
        },
        {
          "name" : "interface-down",
          "description" : "Interface down notification count",
          "event-count" : 4
        }
      ]
  }

List ítem current Swagger spec example https://tools.ietf.org/html/rfc8040#appendix-B.3.9

GET /restconf/data/example:interfaces/interface=eth1 HTTP/1.1 Host: example.com Accept: application/yang-data+json

The server might respond as follows:

  HTTP/1.1 200 OK
  Date: Thu, 26 Jan 2017 20:56:30 GMT
  Server: example-server
  Content-Type: application/yang-data+json

      {
        "name" : "eth1",
        "status" : "up"
      }
bartoszm commented 5 years ago

Hi Arthur, Thanks for reporting

arthurMll commented 5 years ago

Your welcome, are you planning to fix it in the next release? BR,

arthurMll commented 4 years ago

Hi,

I checked the latest patch and it seems it is almost 100% correct but still there is a miror mistake in the response. Taking the same example used in the original comment: List ítem example https://tools.ietf.org/html/rfc8040#appendix-B.3.9

GET /restconf/data/example:interfaces/interface=eth1 HTTP/1.1 Host: example.com Accept: application/yang-data+json The server might respond as follows:

  HTTP/1.1 200 OK
  Date: Thu, 26 Jan 2017 20:56:30 GMT
  Server: example-server
  Content-Type: application/yang-data+json

  {
    "example:interface" : [
      {
        "name" : "eth1",
        "status" : "up"
      }
    ]
  }

Right now the answer of the tool miss the brackets and it would return this:

GET /restconf/data/example:interfaces/interface=eth1 HTTP/1.1 Host: example.com Accept: application/yang-data+json The server might respond as follows:

  HTTP/1.1 200 OK
  Date: Thu, 26 Jan 2017 20:56:30 GMT
  Server: example-server
  Content-Type: application/yang-data+json

  {
    "example:interface" :  {
        "name" : "eth1",
        "status" : "up"
      }
  }

Could you take a look?

Thanks in advance and great job!

bartoszm commented 4 years ago

I will try to resolve it - should be an easy fix

bartoszm commented 4 years ago

fixed in 1.1.14 release