Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Schema: oneOf with const #1925

Open
roquie opened this issue Apr 17, 2024 · 0 comments
Open

JSON Schema: oneOf with const #1925

roquie opened this issue Apr 17, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@roquie
Copy link

roquie commented Apr 17, 2024

Describe the bug
Does not generate an enumeration for oneOf + cost. For example, autocomplete in Jetbrains IDE works fine for this case.

To Reproduce

  1. create a schema
  2. generate
  3. get an incorrect result generation

Example schema:

# definition

  nodeJsModeEnum:
    title: NodeJS mode
    type: string
    description: |
       A long description here.
    default: npm
    oneOf:
      - title: npm
        const: npm
      - title: yarn
        const: yarn
      - title: npm ci
        const: npm_ci

# usage
        properties:
          mode:
            $ref: "#/definitions/nodejsModeEnum"

Used commandline:

pdm run datamodel-codegen --input config/schema/cd.schema.yaml --input-file-type jsonschema --output src/config/cd_model.py --output-model-type pydantic_v2.BaseModel

# pyproject.toml options
#[tool.datamodel-codegen]
#field-constraints = true
#snake-case-field = true
#strip-default-none = false
#target-python-version = "3.11"

Expected behavior

# expects
class NodeJsModeEnum(Enum):
    npm = 'npm'
    yarn = 'yarn'
    npm_ci = 'npm_ci'

# actual
class NodeJsModeEnum(RootModel[str]):
    root: str = Field(
        ..., description='...'
    )

Version:

  • OS: MacOS
  • Python version: 3.11
  • datamodel-code-generator version: 0.25.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants