OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Nim] Generated code fails to compile when the schema of a response is defined without more information than type object

Open
#20,771 0 comments 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
  • [ X] Have you provided a full/minimal spec to reproduce the issue?
    MRE provided

  • [X ] Have you validated the input using an OpenAPI validator (example)?
    File shows no error when uploaded on https://editor.swagger.io/

  • [ X] Have you tested with the latest master to confirm the issue still exists?
    Yes, issue can be reproducted in 7.11 and in master hash 6e9a0559a8d

  • [X ] Have you searched for related issues/PRs?
    Yes. nothing found.

  • [X ] What's the actual output vs expected output?
    The generated nim code can not compile.

  • [Optional] Sponsorship to speed up the bug fix or feature request (example)

Description
openapi-generator version

7.11

OpenAPI declaration file content or url
{
    "openapi": "3.0.0",
    "info": {
      "title" : "mre",
      "version": "1.0.0"
    },
    "servers": [
      {
        "url": "/"
      }
    ],
    "paths": {
      "/foo": {
        "get": {
          "description" : "get operation",
          "parameters": [
            {
              "name": "param1",
              "in": "query",
              "required": false,
              "schema": {
                "type": "string"
              }
            }
          ],
          "responses": {
            "200": {
              "description" : "someresponse",
              "content": {
                "application/json": {
                  "schema": {
                    "type": "object"
                  }
                }
              }
            }
          }
        }
      }
    }
}
Generation Details

java -jar openapi-generator-cli.jar generate -g nim -i mre.json -o mre_client

Steps to reproduce

cd /mre_client
nim compile sample_client.nim

=>
mre_client/openapiclient/apis/api_default.nim(21, 17) Error: cannot open file: ../models/model_object

Related issues/PRs

None to my best knowledge.

Suggest a fix

Issue is that the schema "type" : "object" without further details is wrongly managed in the generated code :
see the code api_default.nim

import ../models/model_object
This is incorrect in case the schema accept 'whatever json object'

The
proc fooGet*(httpClient: HttpClient, param1: string): (Option[object], Response) =

IMHO signature should not be 'object' which is a reserved nim keyword, but it should be JsonNode from the std/json library (import should be added also)
proc fooGet*(httpClient: HttpClient, param1: string): (Option[JsonNode], Response) =

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 the generated api_default.nim import and return type, then inspect models/model_object and sample_client.nim using the provided Nim compile command. Confirm how an inline response schema with only type object is represented, and verify that the generated client compiles with a JSON-object response type and the appropriate std/json import.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.