mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 22:20:56 +00:00
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.
This commit is contained in:
parent
aa51d421cc
commit
4fbe64d4fb
@ -26,20 +26,20 @@ type {{classname}} interface {
|
|||||||
|
|
||||||
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().{{#pathParams}}
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().{{#pathParams}}
|
||||||
@param {{paramName}}{{#description}} {{{.}}}{{/description}}{{/pathParams}}
|
@param {{paramName}}{{#description}} {{{.}}}{{/description}}{{/pathParams}}
|
||||||
@return {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request
|
@return {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request
|
||||||
{{#isDeprecated}}
|
{{#isDeprecated}}
|
||||||
|
|
||||||
Deprecated
|
Deprecated
|
||||||
{{/isDeprecated}}
|
{{/isDeprecated}}
|
||||||
*/
|
*/
|
||||||
{{{nickname}}}(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request
|
{{{nickname}}}(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request
|
||||||
|
|
||||||
// {{nickname}}Execute executes the request{{#returnType}}
|
// {{nickname}}Execute executes the request{{#returnType}}
|
||||||
// @return {{{.}}}{{/returnType}}
|
// @return {{{.}}}{{/returnType}}
|
||||||
{{#isDeprecated}}
|
{{#isDeprecated}}
|
||||||
// Deprecated
|
// Deprecated
|
||||||
{{/isDeprecated}}
|
{{/isDeprecated}}
|
||||||
{{nickname}}Execute(r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request) ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}*{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}}*http.Response, error)
|
{{nickname}}Execute(r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request) ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}*{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}}*http.Response, error)
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
}
|
}
|
||||||
{{/generateInterfaces}}
|
{{/generateInterfaces}}
|
||||||
@ -48,7 +48,7 @@ type {{classname}} interface {
|
|||||||
type {{classname}}Service service
|
type {{classname}}Service service
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
|
|
||||||
type {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request struct {
|
type {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request struct {
|
||||||
ctx context.Context{{#generateInterfaces}}
|
ctx context.Context{{#generateInterfaces}}
|
||||||
ApiService {{classname}}
|
ApiService {{classname}}
|
||||||
{{/generateInterfaces}}{{^generateInterfaces}}
|
{{/generateInterfaces}}{{^generateInterfaces}}
|
||||||
@ -67,14 +67,14 @@ type {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request s
|
|||||||
{{#isDeprecated}}
|
{{#isDeprecated}}
|
||||||
// Deprecated
|
// Deprecated
|
||||||
{{/isDeprecated}}
|
{{/isDeprecated}}
|
||||||
func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request) {{vendorExtensions.x-export-param-name}}({{paramName}} {{{dataType}}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request {
|
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 {
|
||||||
r.{{paramName}} = &{{paramName}}
|
r.{{paramName}} = &{{paramName}}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
{{/isPathParam}}
|
{{/isPathParam}}
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request) Execute() ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}*{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}}*http.Response, error) {
|
func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request) Execute() ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}*{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}}*http.Response, error) {
|
||||||
return r.ApiService.{{nickname}}Execute(r)
|
return r.ApiService.{{nickname}}Execute(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,14 +87,14 @@ func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Reques
|
|||||||
|
|
||||||
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().{{#pathParams}}
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().{{#pathParams}}
|
||||||
@param {{paramName}}{{#description}} {{{.}}}{{/description}}{{/pathParams}}
|
@param {{paramName}}{{#description}} {{{.}}}{{/description}}{{/pathParams}}
|
||||||
@return {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request
|
@return {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request
|
||||||
{{#isDeprecated}}
|
{{#isDeprecated}}
|
||||||
|
|
||||||
Deprecated
|
Deprecated
|
||||||
{{/isDeprecated}}
|
{{/isDeprecated}}
|
||||||
*/
|
*/
|
||||||
func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request {
|
func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request {
|
||||||
return {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request{
|
return {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request{
|
||||||
ApiService: a,
|
ApiService: a,
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
{{#pathParams}}
|
{{#pathParams}}
|
||||||
@ -108,7 +108,7 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#pathParams
|
|||||||
{{#isDeprecated}}
|
{{#isDeprecated}}
|
||||||
// Deprecated
|
// Deprecated
|
||||||
{{/isDeprecated}}
|
{{/isDeprecated}}
|
||||||
func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request) ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}*{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}}*http.Response, error) {
|
func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request) ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}*{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}}*http.Response, error) {
|
||||||
var (
|
var (
|
||||||
localVarHTTPMethod = http.Method{{httpMethod}}
|
localVarHTTPMethod = http.Method{{httpMethod}}
|
||||||
localVarPostBody interface{}
|
localVarPostBody interface{}
|
||||||
|
@ -25,7 +25,9 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.openapitools.codegen.CodegenConstants;
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
import org.openapitools.codegen.CodegenOperation;
|
import org.openapitools.codegen.CodegenOperation;
|
||||||
@ -179,4 +181,25 @@ public class GoClientCodegenTest {
|
|||||||
Path docFile = Paths.get(output + "/docs/PetApi.md");
|
Path docFile = Paths.get(output + "/docs/PetApi.md");
|
||||||
TestUtils.assertFileContains(docFile, "openapiclient.pet{Cat: openapiclient.NewCat(\"Attr_example\")}, openapiclient.pet{Cat: openapiclient.NewCat(\"Attr_example\")}, openapiclient.pet{Cat: openapiclient.NewCat(\"Attr_example\")}");
|
TestUtils.assertFileContains(docFile, "openapiclient.pet{Cat: openapiclient.NewCat(\"Attr_example\")}, openapiclient.pet{Cat: openapiclient.NewCat(\"Attr_example\")}, openapiclient.pet{Cat: openapiclient.NewCat(\"Attr_example\")}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStructPrefix() throws IOException {
|
||||||
|
Map<String, Object> properties = new HashMap<>();
|
||||||
|
properties.put(GoClientCodegen.STRUCT_PREFIX, true);
|
||||||
|
|
||||||
|
File output = Files.createTempDirectory("test").toFile();
|
||||||
|
output.deleteOnExit();
|
||||||
|
|
||||||
|
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||||
|
.setGeneratorName("go")
|
||||||
|
.setAdditionalProperties(properties)
|
||||||
|
.setInputSpec("src/test/resources/3_0/petstore.yaml")
|
||||||
|
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||||
|
|
||||||
|
DefaultGenerator generator = new DefaultGenerator();
|
||||||
|
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||||
|
files.forEach(File::deleteOnExit);
|
||||||
|
|
||||||
|
TestUtils.assertFileContains(Paths.get(output + "/api_pet.go"), "type PetApiAddPetRequest struct");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user