forked from Amartus/yang2swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add docker support
- Loading branch information
Showing
4 changed files
with
154 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,23 +14,23 @@ 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 [email protected] | ||
* Christopher Murch [email protected] | ||
* Christopher Murch [email protected] | ||
|
||
### How do I get set up? ### | ||
|
||
Project is build with standard maven ```maven clean install```. As project depends on ODL components ```settings.xml``` file configuration might be required as explained https://wiki.opendaylight.org/view/GettingStarted:Development_Environment_Setup#Edit_your_.7E.2F.m2.2Fsettings.xml | ||
|
||
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 <arguments> | ||
``` | ||
|
||
Where `<arguments>` 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: | |
<configuration> | ||
<!-- specify the swagger yaml --> | ||
<inputSpec>${swaggerGeneratorPath}/yang.swagger</inputSpec> | ||
<!-- target to generate --> | ||
<language>jaxrs-mrv</language> | ||
<!-- pass any necessary config options --> | ||
<configOptions> | ||
<dateLibrary>java8</dateLibrary> | ||
</configOptions> | ||
<addCompileSourceRoot>false</addCompileSourceRoot> | ||
<output>target/generated-sources/jaxRS</output> | ||
</configuration> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- vi: set et smarttab sw=2 tabstop=2: --> | ||
<!-- | ||
Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved. | ||
This program and the accompanying materials are made available under the | ||
terms of the Eclipse Public License v1.0 which accompanies this distribution, | ||
and is available at http://www.eclipse.org/legal/epl-v10.html | ||
--> | ||
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> | ||
|
||
<profiles> | ||
<profile> | ||
<id>opendaylight-release</id> | ||
<repositories> | ||
<repository> | ||
<id>opendaylight-mirror</id> | ||
<name>opendaylight-mirror</name> | ||
<url>https://nexus.opendaylight.org/content/repositories/public/</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
<updatePolicy>never</updatePolicy> | ||
</releases> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>opendaylight-mirror</id> | ||
<name>opendaylight-mirror</name> | ||
<url>https://nexus.opendaylight.org/content/repositories/public/</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
<updatePolicy>never</updatePolicy> | ||
</releases> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
</profile> | ||
|
||
<profile> | ||
<id>opendaylight-snapshots</id> | ||
<repositories> | ||
<repository> | ||
<id>opendaylight-snapshot</id> | ||
<name>opendaylight-snapshot</name> | ||
<url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url> | ||
<releases> | ||
<enabled>false</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>opendaylight-snapshot</id> | ||
<name>opendaylight-snapshot</name> | ||
<url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url> | ||
<releases> | ||
<enabled>false</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
</profile> | ||
</profiles> | ||
|
||
<activeProfiles> | ||
<activeProfile>opendaylight-release</activeProfile> | ||
<activeProfile>opendaylight-snapshots</activeProfile> | ||
</activeProfiles> | ||
</settings> |