OpenAPI schema generation from YANG 32/6432/26
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Sun, 28 Oct 2018 15:12:42 +0000 (16:12 +0100)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Tue, 6 Nov 2018 11:44:21 +0000 (12:44 +0100)
Change-Id: Id687fbeefd6aa23b2d34a07511847751b3f67b50
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
Dockerfile
Makefile

index 1e89c8f..419f8db 100644 (file)
@@ -20,7 +20,8 @@ RUN  apt-get update && \
   DEBIAN_FRONTEND=noninteractive apt-get -y install git make wget python \
                                             python3 python3-all python3-pip python-pip \
                                             debhelper tox python-setuptools \
-                                            python3-setuptools build-essential dh-make && \
+                                            python3-setuptools build-essential dh-make \
+                                            openjdk-8-jdk maven && \
   DEBIAN_FRONTEND=noninteractive pip3 install pip==9.0.3 && \
   DEBIAN_FRONTEND=noninteractive pip3 install -U pyang pyangbind && \
   DEBIAN_FRONTEND=noninteractive pip3 install -U stdeb && \
index abab90e..9f0d92b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,7 @@
 
 # NOTE: pyang and pyangbind are required for build
 
-.PHONY: all clean package trees deps yang-ietf
+.PHONY: all clean package trees deps yang-ietf openapi_schemas yang2swagger
 PYANG:= pyang
 PYBINDPLUGIN:=$(shell /usr/bin/env python3 -c \
                    'import pyangbind; import os; print("{}/plugin".format(os.path.dirname(pyangbind.__file__)))')
@@ -28,6 +28,7 @@ YANG_DESC_TREES := $(addsuffix .tree.txt, $(YANG_DESC_MODELS))
 YANG_DESC_JSTREES := $(addsuffix .html, $(YANG_DESC_MODELS))
 YANG_RECORD_TREES := $(addsuffix .rec.tree.txt, $(YANG_RECORD_MODELS))
 YANG_RECORD_JSTREES := $(addsuffix .rec.html, $(YANG_RECORD_MODELS))
+OPENAPI_SCHEMAS := osm.yaml
 
 OUT_DIR := osm_im
 TREES_DIR := osm_im_trees
@@ -36,11 +37,13 @@ Q?=@
 
 PYANG_OPTIONS := -Werror
 
-all: $(PYTHON_MODELS) trees
+all: $(PYTHON_MODELS) trees openapi_schemas
        $(MAKE) package
 
 trees: $(YANG_DESC_TREES) $(YANG_DESC_JSTREES) $(YANG_RECORD_TREES) $(YANG_RECORD_JSTREES)
 
+openapi_schemas: $(OPENAPI_SCHEMAS)
+
 $(OUT_DIR):
        $(Q)mkdir -p $(OUT_DIR)
        $(Q)touch $(OUT_DIR)/__init__.py
@@ -74,10 +77,20 @@ $(TREES_DIR):
        $(Q)sed -r -i 's|<a href=\"http://www.tail-f.com">|<a href="http://osm.etsi.org">|g' $(TREES_DIR)/$@
        $(Q)mv $(TREES_DIR)/$@ $(TREES_DIR)/$*.html
 
+osm.yaml: $(OUT_DIR) yang-ietf yang2swagger
+       $(Q)echo generating $@
+       $(Q)java -jar ${HOME}/.m2/repository/com/mrv/yangtools/swagger-generator-cli/*-SNAPSHOT/swagger-generator-cli-*-SNAPSHOT-executable.jar -yang-dir $(MODEL_DIR) -output $(OUT_DIR)/$@
+
 yang-ietf:
        $(Q)wget -q https://raw.githubusercontent.com/YangModels/yang/master/standard/ietf/RFC/ietf-yang-types%402013-07-15.yang -O models/yang/ietf-yang-types.yang
        $(Q)wget -q https://raw.githubusercontent.com/YangModels/yang/master/standard/ietf/RFC/ietf-inet-types%402013-07-15.yang -O models/yang/ietf-inet-types.yang
 
+yang2swagger:
+       $(Q)mkdir -p ${HOME}/.m2
+       $(Q)wget -q -O ${HOME}/.m2/settings.xml https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml
+       git clone https://github.com/bartoszm/yang2swagger.git
+       mvn -f yang2swagger/pom.xml clean install
+
 package:
        tox -e build
        tox -e build3
@@ -93,4 +106,4 @@ deps:
        $(Q)cp -n ~/.m2/settings.xml{,.orig} ; wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml
 
 clean:
-       $(Q)rm -rf dist osm_im.egg-info deb deb_dist *.gz $(OUT_DIR) $(TREES_DIR)
+       $(Q)rm -rf dist osm_im.egg-info deb deb_dist *.gz yang2swagger $(OUT_DIR) $(TREES_DIR)