-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generating c code for url paths that require replacing parameters in the url path the section that does the url path replacement is generated twice.
openapi-generator version
Tried with openapi-generator and openapi-generator-cli 7.1.0 and latest master (7.2.0) SNAPSHOT.
OpenAPI declaration file content or url
The following simplified yaml schema passes validation and is enough to reproduce the error
openapi: 3.0.3
info:
title: API
version: 1.0.0
description: API
paths:
/api/gates/{id}/:
get:
operationId: gates_retrieve
parameters:
- in: path
name: id
schema:
type: string
format: uuid
description: A UUID string identifying this Gate.
required: true
tags:
- gates
security:
- jwtAuth: []
- {}
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Gate'
description: ''
components:
schemas:
Gate:
type: object
properties:
id:
type: string
format: uuid
readOnly: true
name:
type: string
maxLength: 255
description:
type: string
maxLength: 255
required:
- id
- name
securitySchemes:
jwtAuth:
type: http
scheme: bearer
bearerFormat: JWTGeneration Details
java -jar ../openapi-generator-cli-7.2.0-20231220.132735-115.jar generate -g c -i ../schema.yaml
Steps to reproduce
Use the above command to generate the C api. Examine api/GatesAPI.c line 31 - 47 and witness the following section of duplicated code. In particular notice that char* localVarToReplace_id is declared twice which causes a compile time error.
// Path Params
long sizeOfPathParams_id = strlen(id)+3 + strlen("{ id }");
if(id == NULL) {
goto end;
}
char* localVarToReplace_id = malloc(sizeOfPathParams_id);
sprintf(localVarToReplace_id, "{%s}", "id");
localVarPath = strReplace(localVarPath, localVarToReplace_id, id);
if(id == NULL) {
goto end;
}
char* localVarToReplace_id = malloc(sizeOfPathParams_id);
sprintf(localVarToReplace_id, "{%s}", "id");
localVarPath = strReplace(localVarPath, localVarToReplace_id, id);Related issues/PRs
I did some searching for this particular bit of duplicated code and could not find anything.
Suggest a fix
Out of curiosity I went looking for the C generator files but it was not obvious to me where they are located, this seems like a probable cut/paste error during refactoring or something like that and I could probably make an attempt at fixing it myself if I could get a little pointer to where in the repo the affected files might be.
Thanks!