|
| 1 | +### Swagger Codegen 2.x Standalone generator development (separate project/repo) |
| 2 | + |
| 3 | +As described in [Readme](https://github.com/swagger-api/swagger-codegen/tree/master#making-your-own-codegen-modules), |
| 4 | +a new generator can be implemented by starting with a project stub generated by the `meta` command of `swagger-codegen-cli`. |
| 5 | + |
| 6 | +This can be achieved without needing to clone the `swagger-codegen` repo, by downloading and running the jar, e.g.: |
| 7 | + |
| 8 | +``` |
| 9 | +wget https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.13/swagger-codegen-cli-2.4.13.jar -O swagger-codegen-cli.jar |
| 10 | +java -jar swagger-codegen-cli.jar meta -o output/myLibrary -n myClientCodegen -p com.my.company.codegen |
| 11 | +``` |
| 12 | + |
| 13 | +Such generator can be then made available to the CLI by adding it to the classpath, allowing to run/test it via the command line CLI, |
| 14 | +add it to the build pipeline and so on, as mentioned in [Readme](https://github.com/swagger-api/swagger-codegen/tree/master#making-your-own-codegen-modules). |
| 15 | + |
| 16 | + |
| 17 | +#### Development in docker |
| 18 | + |
| 19 | +Similar to what mentioned in Readme [development in docker section](https://github.com/swagger-api/swagger-codegen/tree/master#development-in-docker), a standalone generator can be built and run in docker, without need of a java/maven environment on the local machine. |
| 20 | + |
| 21 | +Generate the initial project: |
| 22 | + |
| 23 | +```bash |
| 24 | + |
| 25 | +# project dir |
| 26 | +TARGET_DIR=/tmp/codegen/mygenerator |
| 27 | +mkdir -p $TARGET_DIR |
| 28 | +cd $TARGET_DIR |
| 29 | +# generated code location |
| 30 | +GENERATED_CODE_DIR=generated |
| 31 | +mkdir -p $GENERATED_CODE_DIR |
| 32 | +# download desired version |
| 33 | +wget https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.13/swagger-codegen-cli-2.4.13.jar -O swagger-codegen-cli.jar |
| 34 | +wget https://raw.githubusercontent.com/swagger-api/swagger-codegen/master/standalone-gen-dev/docker-stub.sh -O docker-stub.sh |
| 35 | +wget https://raw.githubusercontent.com/swagger-api/swagger-codegen/master/standalone-gen-dev/generator-stub-docker.sh -O generator-stub-docker.sh |
| 36 | +chmod +x *.sh |
| 37 | +# generated initial stub: -p <root package> -n <generator name> |
| 38 | +./generator-stub-docker.sh -p io.swagger.codegen.custom -n custom |
| 39 | + |
| 40 | +``` |
| 41 | + |
| 42 | +A test definition if we don't have one: |
| 43 | + |
| 44 | +```bash |
| 45 | +wget https://raw.githubusercontent.com/swagger-api/swagger-codegen/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -O petstore.yaml |
| 46 | +``` |
| 47 | + |
| 48 | + |
| 49 | +Build the generator and run it against a definition (first time will be slower as it needs to download deps) |
| 50 | + |
| 51 | +```bash |
| 52 | +wget https://raw.githubusercontent.com/swagger-api/swagger-codegen/master/standalone-gen-dev/run-in-docker.sh -O run-in-docker.sh |
| 53 | +wget https://raw.githubusercontent.com/swagger-api/swagger-codegen/master/standalone-gen-dev/docker-entrypoint.sh -O docker-entrypoint.sh |
| 54 | +chmod +x *.sh |
| 55 | +./run-in-docker.sh generate -i petstore.yaml -l custom -o /gen/$GENERATED_CODE_DIR |
| 56 | +``` |
| 57 | + |
| 58 | + |
0 commit comments