Skip to content

Commit 8e0e429

Browse files
Mill Module (#22652)
* Initial Mill support * Updated Docs after changing git and pom settings to case classes * Update Docs * include Mill plugin in Docker build * fix scaladoc * fix cubic-dev-ai findings
1 parent e0b2748 commit 8e0e429

File tree

18 files changed

+2957
-0
lines changed

18 files changed

+2957
-0
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ COPY ./google_checkstyle.xml ${GEN_DIR}
1313
# All poms are copied, then we go offline, to allow for better caching of code changes without fetching all dependencies each time
1414
COPY ./modules/openapi-generator-gradle-plugin/pom.xml ${GEN_DIR}/modules/openapi-generator-gradle-plugin/
1515
COPY ./modules/openapi-generator-maven-plugin/pom.xml ${GEN_DIR}/modules/openapi-generator-maven-plugin/
16+
COPY ./modules/openapi-generator-mill-plugin/pom.xml ${GEN_DIR}/modules/openapi-generator-mill-plugin/
1617
COPY ./modules/openapi-generator-online/pom.xml ${GEN_DIR}/modules/openapi-generator-online/
1718
COPY ./modules/openapi-generator-cli/pom.xml ${GEN_DIR}/modules/openapi-generator-cli/
1819
COPY ./modules/openapi-generator-core/pom.xml ${GEN_DIR}/modules/openapi-generator-core/
@@ -23,6 +24,7 @@ RUN mvn dependency:go-offline
2324
# Modules are copied individually here to allow for caching of docker layers between major.minor versions
2425
COPY ./modules/openapi-generator-gradle-plugin ${GEN_DIR}/modules/openapi-generator-gradle-plugin
2526
COPY ./modules/openapi-generator-maven-plugin ${GEN_DIR}/modules/openapi-generator-maven-plugin
27+
COPY ./modules/openapi-generator-mill-plugin ${GEN_DIR}/modules/openapi-generator-mill-plugin
2628
COPY ./modules/openapi-generator-online ${GEN_DIR}/modules/openapi-generator-online
2729
COPY ./modules/openapi-generator-cli ${GEN_DIR}/modules/openapi-generator-cli
2830
COPY ./modules/openapi-generator-core ${GEN_DIR}/modules/openapi-generator-core

docs/plugins.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,56 @@ openApiGenerate {
120120
```
121121
122122
*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) { ... }`.*
123+
124+
## Mill
125+
126+
This Mill library provides a Mill module that can be used to generate code from OpenAPI specifications.
127+
128+
### Example
129+
130+
```scala
131+
//| mill-version: 1.0.6
132+
//| mvnDeps:
133+
//| - org.openapitools:openapi-generator-mill-plugin:7.19.0 # 1.
134+
135+
import mill.*
136+
137+
import org.openapitools.generator.mill.OpenApiModule // 2.
138+
139+
object `package` extends JavaModule with MavenModule with OpenApiModule { // 3.
140+
141+
// other Mill config...
142+
143+
object openapi extends OpenApiConfig { // 4.
144+
def inputSpec: T[PathRef] = Task.Source(BuildCtx.workspaceRoot / "api" / "petstore.yaml")
145+
// other config options...
146+
}
147+
148+
override def generatedSources: T[Seq[PathRef]] = Seq(
149+
PathRef(Task.dest),
150+
openapi.generate(), // 5.
151+
)
152+
}
153+
```
154+
155+
1. Add the plugin to your `build.mill` as `mvnDeps` in the header section
156+
2. import `org.openapitools.generator.mill.OpenApiModule`
157+
3. add `OpenApiModule` to the module definition
158+
4. configure 1-n `OpenApiConfig` as sub-modules
159+
5. run the generation as part of the `compile` task
160+
161+
This gives access to the following tasks:
162+
163+
| Task | Description |
164+
|---------------------------|---------------------------------------------------------------------------------------------|
165+
| <configName>.generate | Generate code via Open API Tools Generator for Open API 2.0 or 3.x specification documents. |
166+
| <configName>.validateSpec | Validates the configured spec |
167+
168+
and a command
169+
170+
| Command | Description |
171+
|---------------------|------------------------------------------------|
172+
| validateOpenapiSpec | Takes the path to a spec file and validates it |
173+
174+
175+
For full details of all options, see the [plugin README](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-mill-plugin).

modules/openapi-generator-mill-plugin/README.md

Lines changed: 173 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
To test the Mill plugin, this project can be used.
2+
3+
> ![NOTE]
4+
> The `mill-build` folder is only needed to look up the plugin from the local Maven repository for development purposes.
5+
6+
It requires that the current SNAPSHOT version of the plugin is installed in the local Maven repository.
7+
Replace the version in `build.mill` or set the environment variable `$MILL_OPENAPITOOLS_PLUGIN_VERSION` to the desired version.
8+
9+
Run `./mill __.compile` to test if the plugin works or some of the modules tasks like `./mill openapi.validate`.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
openapi: "3.0.0"
2+
servers:
3+
- url: http://petstore.swagger.io/v1
4+
paths:
5+
/pets:
6+
get:
7+
summary: List all pets
8+
operationId: listPets
9+
tags:
10+
- pets
11+
parameters:
12+
- name: limit
13+
in: query
14+
description: How many items to return at one time (max 100)
15+
required: false
16+
schema:
17+
type: integer
18+
format: int32
19+
responses:
20+
'200':
21+
description: A paged array of pets
22+
headers:
23+
x-next:
24+
description: A link to the next page of responses
25+
schema:
26+
type: string
27+
content:
28+
application/json:
29+
schema:
30+
$ref: "#/components/schemas/Pets"
31+
default:
32+
description: unexpected error
33+
content:
34+
application/json:
35+
schema:
36+
$ref: "#/components/schemas/Error"
37+
post:
38+
summary: Create a pet
39+
tags:
40+
- pets
41+
responses:
42+
'201':
43+
description: Null response
44+
default:
45+
description: unexpected error
46+
content:
47+
application/json:
48+
schema:
49+
$ref: "#/components/schemas/Error"
50+
/pets/{petId}:
51+
get:
52+
summary: Info for a specific pet
53+
operationId: showPetById
54+
tags:
55+
- pets
56+
parameters:
57+
- name: petId
58+
in: path
59+
required: true
60+
description: The id of the pet to retrieve
61+
schema:
62+
type: string
63+
responses:
64+
'200':
65+
description: Expected response to a valid request
66+
content:
67+
application/json:
68+
schema:
69+
$ref: "#/components/schemas/Pets"
70+
default:
71+
description: unexpected error
72+
content:
73+
application/json:
74+
schema:
75+
$ref: "#/components/schemas/Error"
76+
components:
77+
schemas:
78+
Pet:
79+
required:
80+
- id
81+
- name
82+
properties:
83+
id:
84+
type: integer
85+
format: int64
86+
name:
87+
type: string
88+
tag:
89+
type: string
90+
Pets:
91+
type: array
92+
items:
93+
$ref: "#/components/schemas/Pet"
94+
Error:
95+
required:
96+
- code
97+
- message
98+
properties:
99+
code:
100+
type: integer
101+
format: int32
102+
message:
103+
type: string

0 commit comments

Comments
 (0)