Skip to content

Commit 4fbe64d

Browse files
authored
Fix duplication of "Api" when structPrefix is set (#12128)
This fixes a minor duplication of the word "Api", which is already part of the classname template parameter and doesn't need to be repeated when structPrefix is set.
1 parent aa51d42 commit 4fbe64d

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

modules/openapi-generator/src/main/resources/go/api.mustache

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ type {{classname}} interface {
2626

2727
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().{{#pathParams}}
2828
@param {{paramName}}{{#description}} {{{.}}}{{/description}}{{/pathParams}}
29-
@return {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request
29+
@return {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request
3030
{{#isDeprecated}}
3131

3232
Deprecated
3333
{{/isDeprecated}}
3434
*/
35-
{{{nickname}}}(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request
35+
{{{nickname}}}(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request
3636

3737
// {{nickname}}Execute executes the request{{#returnType}}
3838
// @return {{{.}}}{{/returnType}}
3939
{{#isDeprecated}}
4040
// Deprecated
4141
{{/isDeprecated}}
42-
{{nickname}}Execute(r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request) ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}*{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}}*http.Response, error)
42+
{{nickname}}Execute(r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request) ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}*{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}}*http.Response, error)
4343
{{/operation}}
4444
}
4545
{{/generateInterfaces}}
@@ -48,7 +48,7 @@ type {{classname}} interface {
4848
type {{classname}}Service service
4949
{{#operation}}
5050

51-
type {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request struct {
51+
type {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request struct {
5252
ctx context.Context{{#generateInterfaces}}
5353
ApiService {{classname}}
5454
{{/generateInterfaces}}{{^generateInterfaces}}
@@ -67,14 +67,14 @@ type {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request s
6767
{{#isDeprecated}}
6868
// Deprecated
6969
{{/isDeprecated}}
70-
func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request) {{vendorExtensions.x-export-param-name}}({{paramName}} {{{dataType}}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request {
70+
func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request) {{vendorExtensions.x-export-param-name}}({{paramName}} {{{dataType}}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request {
7171
r.{{paramName}} = &{{paramName}}
7272
return r
7373
}
7474

7575
{{/isPathParam}}
7676
{{/allParams}}
77-
func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request) Execute() ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}*{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}}*http.Response, error) {
77+
func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request) Execute() ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}*{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}}*http.Response, error) {
7878
return r.ApiService.{{nickname}}Execute(r)
7979
}
8080

@@ -87,14 +87,14 @@ func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Reques
8787

8888
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().{{#pathParams}}
8989
@param {{paramName}}{{#description}} {{{.}}}{{/description}}{{/pathParams}}
90-
@return {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request
90+
@return {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request
9191
{{#isDeprecated}}
9292

9393
Deprecated
9494
{{/isDeprecated}}
9595
*/
96-
func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request {
97-
return {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request{
96+
func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request {
97+
return {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request{
9898
ApiService: a,
9999
ctx: ctx,
100100
{{#pathParams}}
@@ -108,7 +108,7 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#pathParams
108108
{{#isDeprecated}}
109109
// Deprecated
110110
{{/isDeprecated}}
111-
func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request) ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}*{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}}*http.Response, error) {
111+
func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request) ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}*{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}}*http.Response, error) {
112112
var (
113113
localVarHTTPMethod = http.Method{{httpMethod}}
114114
localVarPostBody interface{}

modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import java.nio.file.Files;
2626
import java.nio.file.Path;
2727
import java.nio.file.Paths;
28+
import java.util.HashMap;
2829
import java.util.List;
30+
import java.util.Map;
2931

3032
import org.openapitools.codegen.CodegenConstants;
3133
import org.openapitools.codegen.CodegenOperation;
@@ -179,4 +181,25 @@ public void testMultipleRequiredPropertiesHasSameOneOfObject() throws IOExceptio
179181
Path docFile = Paths.get(output + "/docs/PetApi.md");
180182
TestUtils.assertFileContains(docFile, "openapiclient.pet{Cat: openapiclient.NewCat(\"Attr_example\")}, openapiclient.pet{Cat: openapiclient.NewCat(\"Attr_example\")}, openapiclient.pet{Cat: openapiclient.NewCat(\"Attr_example\")}");
181183
}
184+
185+
@Test
186+
public void testStructPrefix() throws IOException {
187+
Map<String, Object> properties = new HashMap<>();
188+
properties.put(GoClientCodegen.STRUCT_PREFIX, true);
189+
190+
File output = Files.createTempDirectory("test").toFile();
191+
output.deleteOnExit();
192+
193+
final CodegenConfigurator configurator = new CodegenConfigurator()
194+
.setGeneratorName("go")
195+
.setAdditionalProperties(properties)
196+
.setInputSpec("src/test/resources/3_0/petstore.yaml")
197+
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
198+
199+
DefaultGenerator generator = new DefaultGenerator();
200+
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
201+
files.forEach(File::deleteOnExit);
202+
203+
TestUtils.assertFileContains(Paths.get(output + "/api_pet.go"), "type PetApiAddPetRequest struct");
204+
}
182205
}

0 commit comments

Comments
 (0)