OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.24k stars 6.43k forks source link

[BUG][Crystal] Uncompilable crystal code is generated #10775

Open SEbbaDK opened 2 years ago

SEbbaDK commented 2 years ago

Bug Report Checklist

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.

cyangle commented 2 years ago

@SEbbaDK Check out my custom crystal templates, it fixed some issues.