cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2023
Views
5
Helpful
1
Replies

yanger: Correct formatting of swagger format?

DTtb
Level 1
Level 1

Hi all,

 

I tried to generate a swagger api documentation based on a ncs service with yanger.

 

How to interpret the swagger output? Is this the correct output?

 

I cannot find any information about the ncs service inside the swagger output.

 

YANG model:

module: testservice

  augment /ncs:services:
    +--rw testservice* [infra-type infra-location]
       +---x check-sync
       |  +---w input
       |  |  +---w outformat?                  outformat4
       |  |  +---w (depth)?
       |  |  |  +--:(deep)

[Omitted output]

 

Command:

yanger --format=swagger --output=/tmp/testservice.swagger -t expand --swagger-host 127.0.0.1:8080 --swagger-basepath /restconf /var/opt/ncs/packages/testservice/src/yang/testservice.yang

Output:

screenshot.PNG

Common information:

$ ncs --version
4.7.2.1
$ yanger --version
yanger 1.0

Thanks.

1 Accepted Solution

Accepted Solutions

gmuloche
Cisco Employee
Cisco Employee

Hello,

 

you are augmenting the /ncs:services container in your model so you need to get the swagger output of this module to see your service.

 

this is working using a package test:

yanger --swagger-path-filter=/data/tailf-ncs-services:services/test:test --format=swagger -t expand --output=/tmp/testservice.swagger --swagger-host 127.0.0.1:8080  /var/nso-5.2.0.3/src/ncs/yang/tailf-ncs.yang /path/to/file/test.yang

(Note with the current version of yanger - using yanger 1.0 coming with NSO 5.2.0.3 here this works for me because I don't have any "data" in my augmenting module as swagger currently accept only one data module for swagger plugin)

 

My package yang model looks like:

module test {

  namespace "http://example.com/test";
  prefix test;

  import ietf-inet-types {
    prefix inet;
  }
  import tailf-common {
    prefix tailf;
  }
  import tailf-ncs {
    prefix ncs;
  }

  description
    "Bla bla...";

  revision 2016-01-01 {
    description
      "Initial revision.";
  }

  augment "/ncs:services" {
    list test {
      description "This is an RFS skeleton service";

      key name;
      leaf name {
        tailf:info "Unique service id";
        tailf:cli-allow-range;
        type string;
      }

      uses ncs:service-data;
      ncs:servicepoint test-servicepoint;

      // may replace this with other ways of refering to the devices.
      leaf-list device {
        type leafref {
          path "/ncs:devices/ncs:device/ncs:name";
        }
      }

      // replace with your own stuff here
      leaf dummy {
        type inet:ipv4-address;
      }
    }
  }
}

View solution in original post

1 Reply 1

gmuloche
Cisco Employee
Cisco Employee

Hello,

 

you are augmenting the /ncs:services container in your model so you need to get the swagger output of this module to see your service.

 

this is working using a package test:

yanger --swagger-path-filter=/data/tailf-ncs-services:services/test:test --format=swagger -t expand --output=/tmp/testservice.swagger --swagger-host 127.0.0.1:8080  /var/nso-5.2.0.3/src/ncs/yang/tailf-ncs.yang /path/to/file/test.yang

(Note with the current version of yanger - using yanger 1.0 coming with NSO 5.2.0.3 here this works for me because I don't have any "data" in my augmenting module as swagger currently accept only one data module for swagger plugin)

 

My package yang model looks like:

module test {

  namespace "http://example.com/test";
  prefix test;

  import ietf-inet-types {
    prefix inet;
  }
  import tailf-common {
    prefix tailf;
  }
  import tailf-ncs {
    prefix ncs;
  }

  description
    "Bla bla...";

  revision 2016-01-01 {
    description
      "Initial revision.";
  }

  augment "/ncs:services" {
    list test {
      description "This is an RFS skeleton service";

      key name;
      leaf name {
        tailf:info "Unique service id";
        tailf:cli-allow-range;
        type string;
      }

      uses ncs:service-data;
      ncs:servicepoint test-servicepoint;

      // may replace this with other ways of refering to the devices.
      leaf-list device {
        type leafref {
          path "/ncs:devices/ncs:device/ncs:name";
        }
      }

      // replace with your own stuff here
      leaf dummy {
        type inet:ipv4-address;
      }
    }
  }
}