Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/mill-plugin-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Mill plugin tests

on:
push:
paths:
- modules/openapi-generator-mill-plugin/**
pull_request:
paths:
- modules/openapi-generator-mill-plugin/**

jobs:
test:
name: Mill plugin tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Set up JDK 11
uses: actions/setup-java@v5
with:
java-version: 11
distribution: 'temurin'
- name: Restore cache (read-only)
# only use restore keys, no save key because we need to clear the cache before running the examples
uses: actions/cache/restore@v4
with:
path: |
~/.m2/repository
~/.gradle
~/.cache/coursier
!~/.gradle/caches/*/plugin-resolution/
!~/.m2/repository/org/openapitools/
!~/.cache/coursier/v1/https/repo1.maven.org/maven2/org/openapitools/
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }}

- name: Maven Clean Install
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
run: |
./mvnw clean install -DskipTests -Dmaven.javadoc.skip=true
# This is needed because of differences in how Maven and Coursier download artifacts
# Maven will only download the pom when the transitive dependency is not needed in the current projects compile classpath
# whereas Coursier expects the artifact (jar) to be present in a Maven repository. When Coursier encounters a
# artifact folder with a pom it considers the artifact to be available and will then crash when the jar is missing.
- name: Clear m2 cache except openapitools (because otherwise coursier will fail to resolve artifacts where only poms are downloaded)
run: |
mv ~/.m2/repository/org/openapitools /tmp/openapitools-backup || true
rm -rf ~/.m2/repository/*
mkdir -p ~/.m2/repository/org
mv /tmp/openapitools-backup ~/.m2/repository/org/openapitools || true
- name: Mill Example - Test Validation Command
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
run: |
(cd modules/openapi-generator-mill-plugin/example/ && ./mill validateOpenapiSpec $(pwd)/api/petstore-invalid.yaml)
- name: Mill Example - Test Validation Task
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
run: |
(cd modules/openapi-generator-mill-plugin/example/ && ./mill openapi.validate)
- name: Mill Example - Test Compile Task
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
run: |
(cd modules/openapi-generator-mill-plugin/example/ && ./mill __.compile)
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ COPY ./google_checkstyle.xml ${GEN_DIR}
# All poms are copied, then we go offline, to allow for better caching of code changes without fetching all dependencies each time
COPY ./modules/openapi-generator-gradle-plugin/pom.xml ${GEN_DIR}/modules/openapi-generator-gradle-plugin/
COPY ./modules/openapi-generator-maven-plugin/pom.xml ${GEN_DIR}/modules/openapi-generator-maven-plugin/
COPY ./modules/openapi-generator-mill-plugin/pom.xml ${GEN_DIR}/modules/openapi-generator-mill-plugin/
COPY ./modules/openapi-generator-online/pom.xml ${GEN_DIR}/modules/openapi-generator-online/
COPY ./modules/openapi-generator-cli/pom.xml ${GEN_DIR}/modules/openapi-generator-cli/
COPY ./modules/openapi-generator-core/pom.xml ${GEN_DIR}/modules/openapi-generator-core/
Expand All @@ -23,6 +24,7 @@ RUN mvn dependency:go-offline
# Modules are copied individually here to allow for caching of docker layers between major.minor versions
COPY ./modules/openapi-generator-gradle-plugin ${GEN_DIR}/modules/openapi-generator-gradle-plugin
COPY ./modules/openapi-generator-maven-plugin ${GEN_DIR}/modules/openapi-generator-maven-plugin
COPY ./modules/openapi-generator-mill-plugin ${GEN_DIR}/modules/openapi-generator-mill-plugin
COPY ./modules/openapi-generator-online ${GEN_DIR}/modules/openapi-generator-online
COPY ./modules/openapi-generator-cli ${GEN_DIR}/modules/openapi-generator-cli
COPY ./modules/openapi-generator-core ${GEN_DIR}/modules/openapi-generator-core
Expand Down
1 change: 1 addition & 0 deletions bin/utils/release/release_version_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ declare -a xml_files=(
declare -a properties_files=(
"${root}/modules/openapi-generator-gradle-plugin/gradle.properties"
"${root}/modules/openapi-generator-gradle-plugin/samples/local-spec/gradle.properties"
"${root}/modules/openapi-generator-mill-plugin/example/mill-build/version.properties"
)

${cwd}/bump.sh -f ${version} -i ${inc} ${xml_files[@]}
Expand Down
53 changes: 53 additions & 0 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,56 @@ openApiGenerate {
```

*If you want to create separate tasks (for example when you have more than one api spec and require different parameters for each), this is how to do so in Gradle 7+: `tasks.register('taskName', org.openapitools.generator.gradle.plugin.tasks.GenerateTask) { ... }`.*

## Mill

This Mill library provides a Mill module that can be used to generate code from OpenAPI specifications.

### Example

```scala
//| mill-version: 1.0.6
//| mvnDeps:
//| - org.openapitools:openapi-generator-mill-plugin:7.20.0 # 1.

import mill.*

import org.openapitools.generator.mill.OpenApiModule // 2.

object `package` extends JavaModule with MavenModule with OpenApiModule { // 3.

// other Mill config...

object openapi extends OpenApiConfig { // 4.
def inputSpec: T[PathRef] = Task.Source(BuildCtx.workspaceRoot / "api" / "petstore.yaml")
// other config options...
}

override def generatedSources: T[Seq[PathRef]] = Seq(
PathRef(Task.dest),
openapi.generate(), // 5.
)
}
```

1. Add the plugin to your `build.mill` as `mvnDeps` in the header section
2. import `org.openapitools.generator.mill.OpenApiModule`
3. add `OpenApiModule` to the module definition
4. configure 1-n `OpenApiConfig` as sub-modules
5. run the generation as part of the `compile` task

This gives access to the following tasks:

| Task | Description |
|---------------------------|---------------------------------------------------------------------------------------------|
| <configName>.generate | Generate code via Open API Tools Generator for Open API 2.0 or 3.x specification documents. |
| <configName>.validateSpec | Validates the configured spec |

and a command

| Command | Description |
|---------------------|------------------------------------------------|
| validateOpenapiSpec | Takes the path to a spec file and validates it |


For full details of all options, see the [plugin README](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-mill-plugin).
Loading
Loading