OpenAPITools / OpenAPITools/openapi-generator

v7.0.1 Usage Question: reserved word mapping with custom templates

Open
#17,368 21 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Rust
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

I have a set of custom templates for generating rust code.
It is based of v5.4 rust / request client templates.

Generating code with openapi definition with properties like 'type' works with
the standard v7.0.1 generation, but not with my custom template.
I have a configuration file with all kinds of options set.
Like

# java -jar openapi-generator-cli-5.4.0.jar generate -c d42/OpenAPI_Gen.yml --skip-validate-spec > d42\Generated.out
#  --global-propery apiDocs=false,apiTests=true,modelDocs=false,modelTests=true
generatorName: rust
outputDir: d42
library: reqwest
#direct 
inputSpec: d42/device42.yaml
#inputSpec: d42\spec2.json
templateDir: ../openapi_templates5/
skipFormModel: false
apiDocs: false
apiTests: true
modelDocs: false
modelTests: true
#reserved-words-mappings: type=r#type
files: # https://openapi-generator.tech/docs/customization/
  impl/api_impl.mustache:
    templateType: API
    folder: src/api_impl
    destinationFilename: _impl.rs_
  impl/model_impl.mustache:
    templateType: Model
    folder: src/model_impl
    destinationFilename: _impl.rs_
  impl/errors_impl.mustache:
    templateType: SupportingFiles
    folder: src/model_impl
    destinationFilename: errors_impl.rs_
  impl/api_mod_impl.mustache:
    destinationFilename: mod.rs_
    templateType: SupportingFiles
    folder: src/api_impl
  impl/model_mod_impl.mustache:
    destinationFilename: mod.rs_
    templateType: SupportingFiles
    folder: src/model_impl
  impl/warp_impl.mustache:
    destinationFilename: warp_impl.rs_
    templateType: SupportingFiles
    folder: src
  impl/sensor_impl.mustache:
    destinationFilename: sensor_impl.rs_
    templateType: SupportingFiles
    folder: src
  impl/build.mustache:
    destinationFilename: build.rs_
    templateType: SupportingFiles
  impl/main_impl.mustache:
    destinationFilename: src/main.rs_
    templateType: SupportingFiles
additionalProperties:
  vendorExtensions.x-outputDir: d42
  httpUserAgent: prtgclib_rust
  vendorExtensions.x-gen-exe: prtgc_d42
  supportAsync: true
  supportMultipleResponses: true
  packageName: prtgclib_d42api
  packageVersion: 0.2.33
  vendorExtensions.x-moahclient: true
Exception in thread "main" java.lang.RuntimeException: Could not generate model 'device'
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:583)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:960)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:511)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.RuntimeException: reserved word type not allowed

How to I force the generator to use the standard rust reserved word substitution?

openapi-generator version

v 7.0.1

OpenAPI declaration file content or url

https://api.device42.com/device42.yaml

Command line used for generation

java -jar ../openapi-generator-cli-7.0.1.jar generate -c d42/OpenAPI_Gen.yml --skip-validate-spec > d42\Generated.out

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/pull/16103

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 org.openapitools.codegen.DefaultGenerator.generateModels and compare the standard Rust templates with the custom files under ../openapi_templates5/. Reproduce generation using the supplied OpenAPI_Gen.yml and device42.yaml, then verify that a property named type is handled successfully with the custom templates.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.