OpenAPITools / OpenAPITools/openapi-generator

[BUG] [C-libcurl] The parameter "import mappings" does not take effect

Open
#10,994 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

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

I use below command line to generate a c-libcurl client with the parameters
--type-mappings "int-or-string=IntOrString"
--import-mappings "IntOrString=../custom-model/int_or_string

java -DdebugModels -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i /root/swagger.json   -g c    -o /root/output --skip-validate-spec --type-mappings "int-or-string=IntOrString" --import-mappings "IntOrString=../custom-model/int_or_string"

The type-mappings takes effect but import-mappings does not.

#include "int_or_string.h"    <---- This should be "../custom-model/int_or_string.h"

typedef struct v1_service_port_t {
...
    int_or_string_t *target_port; 
}

I think this is a bug or "import mappings" is not implemented for the C-libcurl generator.

Hi @wing328 @zhemant

Could you please give any advice to fix this issue ?

Maybe it shoud be implemented in the file CLibcurlClientCodegen.java

openapi-generator version

master

OpenAPI declaration file content or url
    "intstr.IntOrString": {
      "description": "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.",
      "format": "int-or-string",
      "type": "string"
    },
...

        "targetPort": {
          "$ref": "#/definitions/intstr.IntOrString",
          "description": "Number or name of the port to access on the pods targeted by the service. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. If this is a string, it will be looked up as a named port in the target Pod's container ports. If this is not specified, the value of the 'port' field is used (an identity map). This field is ignored for services with clusterIP=None, and should be omitted or set equal to the 'port' field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service"
        }


Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction command and the referenced modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java. Compare how --type-mappings and --import-mappings are processed for the C-libcurl generator, then regenerate the sample and verify that the include uses ../custom-model/int_or_string.h instead of int_or_string.h.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, java
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.