OpenAPITools / OpenAPITools/openapi-generator

[BUG][Crystal] Uncompilable crystal code is generated

Open
#10,775 1 comment 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

If the crystal generator is used, and the templates partial_model_generic.mustache, base_object.mustache or partial_oneof_module.mustache are instanced, we generate code using ....get_const(...) which isn't a thing in crystal, so the resulting code is unusable. (see https://github.com/crystal-lang/crystal/issues/8180 for proof of no const_get in crystal)

openapi-generator version

This seems to be from crystal introduction until latest master branch. (b3ec7faa8fc)

Reproducing

I encounter it when creating enum schemas, which is only used as a subtype in the petstore example which makes this not occur.

...
  content:
    schema:
      type: string
      enum:
      - "a"
      - "b"

Using some spec with the above contents trigger it.

Suggest a fix

The generator files mentioned should be fixed so it is not producing ruby code that doesn't work in crystal.

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 partial_model_generic.mustache, base_object.mustache, and partial_oneof_module.mustache, then reproduce the issue using an enum schema with values "a" and "b". Inspect the generated Crystal code for get_const calls; done means the affected templates generate usable Crystal code without that unsupported call.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.