diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..61de0e90 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM openjdk:8-jdk-alpine + +RUN apk add --no-cache curl tar bash + +ARG MAVEN_VERSION=3.5.4 +ARG USER_HOME_DIR="/root" +ARG SHA=ce50b1c91364cb77efe3776f756a6d92b76d9038b0a0782f7d53acf1e997a14d +ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries + +RUN mkdir -p /usr/share/maven /usr/share/maven/ref \ + && curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \ + && echo "${SHA} /tmp/apache-maven.tar.gz" | sha256sum -c - \ + && tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \ + && rm -f /tmp/apache-maven.tar.gz \ + && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn + +ENV MAVEN_HOME /usr/share/maven +ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2" + +RUN mkdir -p $USER_HOME_DIR/.m2 +RUN wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > $USER_HOME_DIR/.m2/settings.xml + +COPY . /usr/src/app + +WORKDIR /usr/src/app + +RUN mvn clean install + +RUN ["chmod", "+x", "/usr/src/app/docker-entrypoint.sh"] + +ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 21b944d7..47d0f7b0 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ ### Yang2Swagger generator ### -Project is a YANG to Swagger ([OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md)) generator tool. OpenAPI describes and documents RESTful APIs. The Swagger definition generated with our tool is meant to be compliant with [RESTCONF specification](https://tools.ietf.org/html/draft-ietf-netconf-restconf-16). +Project is a YANG to Swagger ([OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md)) generator tool. OpenAPI describes and documents RESTful APIs. The Swagger definition generated with our tool is meant to be compliant with [RESTCONF specification](https://tools.ietf.org/html/draft-ietf-netconf-restconf-16). Having the definition you are able to build live documentation services, and generate client or server code using Swagger tools. Our tool supports: - * rpc - which are translated into POST operations + * rpc - which are translated into POST operations * containers and lists - which are represented in RESTCONF data space URI and Swagger modules. * leafs and leaf lists - that are translated into Swagger models' attributes. Generator handles enums as well. * leafrefs - which are represented as model attributes with typesUsageTreeBuilder of the referred leafs @@ -14,14 +14,14 @@ Our tool supports: * YANG modules documentation - which is added to generated swagger API specification -In this project we use YANG parser from [OpenDaylight](https://www.opendaylight.org/) (ODL) yang-tools project. The generated Swagger specification is available as Java object or serialized either to YAML or JSON file. +In this project we use YANG parser from [OpenDaylight](https://www.opendaylight.org/) (ODL) yang-tools project. The generated Swagger specification is available as Java object or serialized either to YAML or JSON file. The project contains a customized Jersey code-generator that can be use to generate server side scaffolding compatible with API specification. Contact: * Bartosz Michalik bartosz.michalik@amartus.com - * Christopher Murch cmurch@mrv.com + * Christopher Murch cmurch@mrv.com ### How do I get set up? ### @@ -29,8 +29,8 @@ Project is build with standard maven ```maven clean install```. As project depen The main component of the project is ```SwaggerGenerator``` which can be run standalone as well as can be configured as maven plugin. Examples of usage can be found in *examples* directory in the project. -The generated yaml.swagger file might be used in swagger editor or standalone code generator. -As [mustache](https://mustache.github.io/) templates used in original jersey code generator apply HTML escaping to ```@Path``` parameters +The generated yaml.swagger file might be used in swagger editor or standalone code generator. +As [mustache](https://mustache.github.io/) templates used in original jersey code generator apply HTML escaping to ```@Path``` parameters we have prepared our own version of the code generator. You might run it standalone or as maven plugin. ### Command-line Execution ### @@ -62,6 +62,26 @@ java -jar ~/.m2/repository/com/mrv/yangtools/swagger-generator-cli/1.0-SNAPSHOT/ mef-services ``` +#### Running the CLI in a Docker image #### + +To run yang2swagger in a Docker image or to build and extract the Jar file, run +the following in this repo's directory: + +``` +docker build -t yang2swagger . +``` + +To use the docker image, gather all the YANG files into a single directory and +from inside that directory run the following: + +``` +docker run -it -v $(pwd):/usr/src/yang yang2swagger +``` + +Where `` can either be the arguments for the jar file, enclosed in +quotes, or `EXTRACT_JAR` if you need to extract the JAR file to the mounted +docker volume. + ### Maven integration ### You can generate ```yaml.swagger``` as part of resource generation step in your maven module. You can also choose the name by editing base-module and swagger-format additionalConfigs. To do so please add following plugin configuration to your project: @@ -141,15 +161,15 @@ You might also consider to plug-in code generator into your model definition: ${swaggerGeneratorPath}/yang.swagger - + jaxrs-mrv - + java8 - + false target/generated-sources/jaxRS diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 00000000..9dc3a4a4 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# dynamically grab jar name in /usr/src/app/cli/target/ +JAR_FILE=$(find /usr/src/app/cli/target -name \*executable.jar) + +if [ -z ${1+x} ]; then + echo 'No module selected. Skipping.' +elif [ "$1" == "EXTRACT_JAR" ]; then + echo "cp ${JAR_FILE} /usr/src/yang" + cp ${JAR_FILE} /usr/src/yang +else + echo "java -jar ${JAR_FILE} ${1}" + java -jar ${JAR_FILE} ${1} +fi diff --git a/settings.xml b/settings.xml new file mode 100644 index 00000000..79c62a49 --- /dev/null +++ b/settings.xml @@ -0,0 +1,80 @@ + + + + + + + + opendaylight-release + + + opendaylight-mirror + opendaylight-mirror + https://nexus.opendaylight.org/content/repositories/public/ + + true + never + + + false + + + + + + opendaylight-mirror + opendaylight-mirror + https://nexus.opendaylight.org/content/repositories/public/ + + true + never + + + false + + + + + + + opendaylight-snapshots + + + opendaylight-snapshot + opendaylight-snapshot + https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/ + + false + + + true + + + + + + opendaylight-snapshot + opendaylight-snapshot + https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/ + + false + + + true + + + + + + + + opendaylight-release + opendaylight-snapshots + + \ No newline at end of file