Skip to content

Commit 833d1d3

Browse files
thibautretyRL6172
andauthored
[REQ-22001] Add MCP server support to apiService.mustache (#22197)
* Add MCP server support to apiService.mustache Refactor apiService.mustache to include MCP server support and enhance operation methods. * Update samples * update samples in wsl * remove useless import when mcp is disabled --------- Co-authored-by: RL6172 <[email protected]>
1 parent 8e7fd3c commit 833d1d3

File tree

10 files changed

+1127
-140
lines changed

10 files changed

+1127
-140
lines changed

modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/apiService.mustache

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,90 @@ package {{package}};
22

33
import {{package}}.*;
44
import {{modelPackage}}.*;
5-
{{#operations}}{{#operation}}{{#isMultipart}}import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
6-
{{/isMultipart}}{{/operation}}{{/operations}}
5+
{{#vendorExtensions.x-enable-mcp-server}}
6+
import io.quarkiverse.mcp.server.Tool;
7+
import io.quarkiverse.mcp.server.ToolArg;
8+
import jakarta.enterprise.context.ApplicationScoped;
9+
import lombok.AllArgsConstructor;
10+
{{/vendorExtensions.x-enable-mcp-server}}
711

8-
{{#imports}}import {{import}};
12+
{{#operations}}
13+
{{#operation}}
14+
{{#isMultipart}}
15+
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
16+
{{/isMultipart}}
17+
{{/operation}}
18+
{{/operations}}
19+
20+
{{#imports}}
21+
import {{import}};
922
{{/imports}}
1023

1124
import java.util.List;
1225
import {{package}}.NotFoundException;
13-
1426
import java.io.InputStream;
1527

1628
{{#useBeanValidation}}
1729
import {{javaxPackage}}.validation.constraints.*;
1830
import {{javaxPackage}}.validation.Valid;
1931
{{/useBeanValidation}}
32+
2033
import {{javaxPackage}}.ws.rs.core.Response;
2134
import {{javaxPackage}}.ws.rs.core.SecurityContext;
2235

2336
{{>generatedAnnotation}}
2437

2538
{{#operations}}
2639
public interface {{classname}}Service {
27-
{{#operation}}
28-
Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{^isMultipart}}{{>serviceFormParams}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}SecurityContext securityContext)
29-
throws NotFoundException;
30-
{{/operation}}
40+
{{#operation}}
41+
Response {{nickname}}(
42+
{{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}
43+
{{#allParams}}
44+
{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{^isMultipart}}{{>serviceFormParams}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}},{{/isFormParam}}{{/isMultipart}}
45+
{{/allParams}}
46+
SecurityContext securityContext
47+
) throws NotFoundException;
48+
49+
default Response {{nickname}}(
50+
{{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}
51+
{{#allParams}}
52+
{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{^isMultipart}}{{>serviceFormParams}}{{^last}}, {{/last}}{{/isMultipart}}{{#isMultipart}}{{^isFormParam}}{{^last}}, {{/last}}{{/isFormParam}}{{/isMultipart}}
53+
{{/allParams}}
54+
String context
55+
) throws NotFoundException {
56+
return {{nickname}}(
57+
{{#isMultipart}}input,{{/isMultipart}}
58+
{{#allParams}}{{paramName}},{{/allParams}}
59+
(SecurityContext)null
60+
);
61+
}
62+
{{/operation}}
63+
}
64+
{{#vendorExtensions.x-enable-mcp-server}}
65+
@ApplicationScoped
66+
@AllArgsConstructor
67+
class Mcp{{classname}}Service {
68+
{{classname}}Service service;
69+
70+
{{#operation}}
71+
{{#vendorExtensions.x-enable-mcp-operation}}
72+
@Tool(description = "{{summary}}")
73+
public Response {{nickname}}(
74+
{{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}
75+
{{#allParams}}
76+
@ToolArg(description = "{{description}}", required = false)
77+
{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{^isMultipart}}{{>serviceFormParams}}{{^last}}, {{/last}}{{/isMultipart}}{{#isMultipart}}{{^isFormParam}}{{^last}}, {{/last}}{{/isFormParam}}{{/isMultipart}}
78+
{{/allParams}}
79+
String context
80+
) throws NotFoundException {
81+
return service.{{nickname}}(
82+
{{#isMultipart}}input,{{/isMultipart}}
83+
{{#allParams}}{{paramName}},{{/allParams}}
84+
(SecurityContext)null
85+
);
86+
}
87+
{{/vendorExtensions.x-enable-mcp-operation}}
88+
{{/operation}}
3189
}
90+
{{/vendorExtensions.x-enable-mcp-server}}
3291
{{/operations}}

samples/server/petstore/jaxrs-resteasy/default/src/gen/java/org/openapitools/api/PetApiService.java

Lines changed: 146 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,167 @@
22

33
import org.openapitools.api.*;
44
import org.openapitools.model.*;
5-
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
65

6+
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
77

88
import java.io.File;
99
import org.openapitools.model.ModelApiResponse;
1010
import org.openapitools.model.Pet;
1111

1212
import java.util.List;
1313
import org.openapitools.api.NotFoundException;
14-
1514
import java.io.InputStream;
1615

1716
import javax.validation.constraints.*;
1817
import javax.validation.Valid;
18+
1919
import javax.ws.rs.core.Response;
2020
import javax.ws.rs.core.SecurityContext;
2121

2222
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaResteasyServerCodegen", comments = "Generator version: 7.18.0-SNAPSHOT")
2323
public interface PetApiService {
24-
Response addPet(Pet body,SecurityContext securityContext)
25-
throws NotFoundException;
26-
Response deletePet(Long petId,SecurityContext securityContext)
27-
throws NotFoundException;
28-
Response findPetsByStatus(List<String> status,SecurityContext securityContext)
29-
throws NotFoundException;
30-
Response findPetsByTags(List<String> tags,SecurityContext securityContext)
31-
throws NotFoundException;
32-
Response getPetById(Long petId,SecurityContext securityContext)
33-
throws NotFoundException;
34-
Response updatePet(Pet body,SecurityContext securityContext)
35-
throws NotFoundException;
36-
Response updatePetWithForm(Long petId,String name,String status,SecurityContext securityContext)
37-
throws NotFoundException;
38-
Response uploadFile(MultipartFormDataInput input,Long petId,SecurityContext securityContext)
39-
throws NotFoundException;
24+
Response addPet(
25+
26+
Pet body,
27+
SecurityContext securityContext
28+
) throws NotFoundException;
29+
30+
default Response addPet(
31+
32+
Pet body,
33+
String context
34+
) throws NotFoundException {
35+
return addPet(
36+
37+
body,
38+
(SecurityContext)null
39+
);
40+
}
41+
Response deletePet(
42+
43+
Long petId,
44+
SecurityContext securityContext
45+
) throws NotFoundException;
46+
47+
default Response deletePet(
48+
49+
Long petId,
50+
String context
51+
) throws NotFoundException {
52+
return deletePet(
53+
54+
petId,
55+
(SecurityContext)null
56+
);
57+
}
58+
Response findPetsByStatus(
59+
60+
List<String> status,
61+
SecurityContext securityContext
62+
) throws NotFoundException;
63+
64+
default Response findPetsByStatus(
65+
66+
List<String> status,
67+
String context
68+
) throws NotFoundException {
69+
return findPetsByStatus(
70+
71+
status,
72+
(SecurityContext)null
73+
);
74+
}
75+
Response findPetsByTags(
76+
77+
List<String> tags,
78+
SecurityContext securityContext
79+
) throws NotFoundException;
80+
81+
default Response findPetsByTags(
82+
83+
List<String> tags,
84+
String context
85+
) throws NotFoundException {
86+
return findPetsByTags(
87+
88+
tags,
89+
(SecurityContext)null
90+
);
91+
}
92+
Response getPetById(
93+
94+
Long petId,
95+
SecurityContext securityContext
96+
) throws NotFoundException;
97+
98+
default Response getPetById(
99+
100+
Long petId,
101+
String context
102+
) throws NotFoundException {
103+
return getPetById(
104+
105+
petId,
106+
(SecurityContext)null
107+
);
108+
}
109+
Response updatePet(
110+
111+
Pet body,
112+
SecurityContext securityContext
113+
) throws NotFoundException;
114+
115+
default Response updatePet(
116+
117+
Pet body,
118+
String context
119+
) throws NotFoundException {
120+
return updatePet(
121+
122+
body,
123+
(SecurityContext)null
124+
);
125+
}
126+
Response updatePetWithForm(
127+
128+
Long petId,
129+
String name,
130+
String status,
131+
SecurityContext securityContext
132+
) throws NotFoundException;
133+
134+
default Response updatePetWithForm(
135+
136+
Long petId,
137+
String name,
138+
String status,
139+
String context
140+
) throws NotFoundException {
141+
return updatePetWithForm(
142+
143+
petId,name,status,
144+
(SecurityContext)null
145+
);
146+
}
147+
Response uploadFile(
148+
MultipartFormDataInput input,
149+
Long petId,
150+
151+
152+
SecurityContext securityContext
153+
) throws NotFoundException;
154+
155+
default Response uploadFile(
156+
MultipartFormDataInput input,
157+
Long petId,
158+
159+
160+
String context
161+
) throws NotFoundException {
162+
return uploadFile(
163+
input,
164+
petId,additionalMetadata,_file,
165+
(SecurityContext)null
166+
);
167+
}
40168
}

samples/server/petstore/jaxrs-resteasy/default/src/gen/java/org/openapitools/api/StoreApiService.java

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,80 @@
99

1010
import java.util.List;
1111
import org.openapitools.api.NotFoundException;
12-
1312
import java.io.InputStream;
1413

1514
import javax.validation.constraints.*;
1615
import javax.validation.Valid;
16+
1717
import javax.ws.rs.core.Response;
1818
import javax.ws.rs.core.SecurityContext;
1919

2020
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaResteasyServerCodegen", comments = "Generator version: 7.18.0-SNAPSHOT")
2121
public interface StoreApiService {
22-
Response deleteOrder(String orderId,SecurityContext securityContext)
23-
throws NotFoundException;
24-
Response getInventory(SecurityContext securityContext)
25-
throws NotFoundException;
26-
Response getOrderById(Long orderId,SecurityContext securityContext)
27-
throws NotFoundException;
28-
Response placeOrder(Order body,SecurityContext securityContext)
29-
throws NotFoundException;
22+
Response deleteOrder(
23+
24+
String orderId,
25+
SecurityContext securityContext
26+
) throws NotFoundException;
27+
28+
default Response deleteOrder(
29+
30+
String orderId,
31+
String context
32+
) throws NotFoundException {
33+
return deleteOrder(
34+
35+
orderId,
36+
(SecurityContext)null
37+
);
38+
}
39+
Response getInventory(
40+
41+
SecurityContext securityContext
42+
) throws NotFoundException;
43+
44+
default Response getInventory(
45+
46+
String context
47+
) throws NotFoundException {
48+
return getInventory(
49+
50+
51+
(SecurityContext)null
52+
);
53+
}
54+
Response getOrderById(
55+
56+
Long orderId,
57+
SecurityContext securityContext
58+
) throws NotFoundException;
59+
60+
default Response getOrderById(
61+
62+
Long orderId,
63+
String context
64+
) throws NotFoundException {
65+
return getOrderById(
66+
67+
orderId,
68+
(SecurityContext)null
69+
);
70+
}
71+
Response placeOrder(
72+
73+
Order body,
74+
SecurityContext securityContext
75+
) throws NotFoundException;
76+
77+
default Response placeOrder(
78+
79+
Order body,
80+
String context
81+
) throws NotFoundException {
82+
return placeOrder(
83+
84+
body,
85+
(SecurityContext)null
86+
);
87+
}
3088
}

0 commit comments

Comments
 (0)