OpenAPITools / OpenAPITools/openapi-generator
I want to use variable that refer to snake case for enum in mustash file.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
I want to create Enum class of python.
In openapi-generator:v5.4.0 , the name including hyphen is not converted to snake case.
petstore.yaml
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/lang:
get:
summary: getLang
operationId: getLang
responses:
'200':
description: foo
content:
application/json:
schema:
$ref: "#/components/schemas/Lang"
components:
schemas:
Lang:
type: string
enum:
- ja-JP
- en-US
template/models.mustache
from enum import Enum
{{#models}}
{{#model}}
{{#isEnum}}
class {{classname}}(Enum):
{{#allowableValues}}
{{#enumVars}}
{{name}} = {{{value}}}
{{/enumVars}}
{{/allowableValues}}
{{/isEnum}}
{{/model}}
{{/models}}
command
$ docker run --rm -u `id -u`:`id -g` -v ${PWD}:/local openapitools/openapi-generator-cli:v5.4.0 generate \
--input-spec /local/petstore.yaml --generator-name python --output /local/out \
--template-dir /local/template --global-property models,modelTests=false,modelDocs=false
out/openapi_client/model/lang.py
from enum import Enum
class Lang(Enum):
JA-JP = "ja-JP"
EN-US = "en-US"
Describe the solution you'd like
I want to use variable that refer to snake case in mustash file.
Additional context
In openapi-generator:v4.3.1 , the name included hyphen is converted to snake case.
Why did the behaivior change?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with petstore.yaml, template/models.mustache, and the generated out/openapi_client/model/lang.py, then reproduce the result using the documented v5.4.0 Docker command. Compare the enum variable names with the v4.3.1 behavior described in the issue; done means the custom template can reference snake-case names for hyphenated enum values without producing invalid Python identifiers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100