OpenAPITools / OpenAPITools/openapi-generator

[REQ] --import-mapping usage not transparent

Open
#6,287 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Copy of my comment here on issue #5909

OPENAPI_GENERATOR_VERSION=4.3.1 ./openapi-generator-cli.sh generate \
                                --input-spec hi.yaml \
				--generator-name python \
				--additional-properties generateSourceCodeOnly=True \
				--template-dir templates \
				--type-mappings array=List \
				--import-mappings List="from typing import List" \
				--import-mappings DateFromISO="from my_package import DateFromISO" \
				--output ../mydir

should produce:

  • list gets typed as List (works)
  • an import statement from typing import List in all files with List (does not work)

Working with custom objects not defined in the schema .yaml file is not transparent at this time. For example, if I have

type = DateFromISO

in my schema file, the generator throws the following warnings multiple times:

WARN o.o.c.languages.PythonClientCodegen - Type DateFromISO not handled properly in toExampleValue
WARN o.o.codegen.DefaultCodegen - Unknown type found in the schema: DateFromISO

I figure the generator would recognise DateFromISO from --import-mappings

Lastly, I am having a hard time finding sample usage of openapi-generator-cli-x.x.x.jar arguments like --import-mappings

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 --import-mappings handling in the CLI and the PythonClientCodegen and DefaultCodegen entry points named by the warnings. Reproduce the command with DateFromISO and List, then inspect the generated Python files and the openapi-generator-cli-x.x.x.jar argument documentation. Done means imported custom types are handled without the reported warnings and the --import-mappings usage is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, python
Domain
api, cli, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.