forked from loafle/openapi-generator-original
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 {{paramName}}{{#description}} {{{.}}}{{/description}}{{/pathParams}}
|
||||
@return {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request
|
||||
@return {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request
|
||||
{{#isDeprecated}}
|
||||
|
||||
Deprecated
|
||||
{{/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}}
|
||||
// @return {{{.}}}{{/returnType}}
|
||||
{{#isDeprecated}}
|
||||
// Deprecated
|
||||
{{/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}}
|
||||
}
|
||||
{{/generateInterfaces}}
|
||||
@ -48,7 +48,7 @@ type {{classname}} interface {
|
||||
type {{classname}}Service service
|
||||
{{#operation}}
|
||||
|
||||
type {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request struct {
|
||||
type {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request struct {
|
||||
ctx context.Context{{#generateInterfaces}}
|
||||
ApiService {{classname}}
|
||||
{{/generateInterfaces}}{{^generateInterfaces}}
|
||||
@ -67,14 +67,14 @@ type {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request s
|
||||
{{#isDeprecated}}
|
||||
// Deprecated
|
||||
{{/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}}
|
||||
return r
|
||||
}
|
||||
|
||||
{{/isPathParam}}
|
||||
{{/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)
|
||||
}
|
||||
|
||||
@ -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 {{paramName}}{{#description}} {{{.}}}{{/description}}{{/pathParams}}
|
||||
@return {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request
|
||||
@return {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request
|
||||
{{#isDeprecated}}
|
||||
|
||||
Deprecated
|
||||
{{/isDeprecated}}
|
||||
*/
|
||||
func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request {
|
||||
return {{#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}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request{
|
||||
ApiService: a,
|
||||
ctx: ctx,
|
||||
{{#pathParams}}
|
||||
@ -108,7 +108,7 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#pathParams
|
||||
{{#isDeprecated}}
|
||||
// Deprecated
|
||||
{{/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 (
|
||||
localVarHTTPMethod = http.Method{{httpMethod}}
|
||||
localVarPostBody interface{}
|
||||
|
@ -25,7 +25,9 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
@ -179,4 +181,25 @@ public class GoClientCodegenTest {
|
||||
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\")}");
|
||||
}
|
||||
|
||||
@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