OpenAPITools / OpenAPITools/openapi-generator

[BUG][Clojure] Generated library imports non-existent specs

Open
#18,377 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
  • 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?
    Actual output: imports are being generated for models of primitive types, causing import errors like
Execution error (FileNotFoundException) at plaid-clj.api.plaid/eval25975$loading (plaid.clj:1).
Could not locate plaid_clj/specs/iso8601_date__init.class, plaid_clj/specs/iso8601_date.clj or plaid_clj/specs/iso8601_date.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.

Expected output: Only models of complex types should be imported

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

openapi-generator is generating imports for non-existent specs in the API file. When I looked into which kinds of specs are non-existent, I noticed they were all models of primitive types. This makes sense – a spec of a primitive type cannot be generated without more information (like enum, format, etc). However, when I try to import the API into another project, I get errors such as the one above.

openapi-generator version

v.7.5.0-snapshot (the most recent one)

OpenAPI declaration file content or url

https://github.com/plaid/plaid-openapi/raw/master/2020-09-14.yml

Generation Details

openapi-generator generate -g clojure -i 2020-09-14.yml -o ./build/plaid-clj -p projectName=plaid-clj,projectVersion=0.1.0

Steps to reproduce
  1. Clone plaid-openapi
  2. Install the latest 7.5.0 snapshot of OpenAPI Generator
  3. Run the above command (in "Generation Details") at the root of the cloned repo
Related issues/PRs

This is sort of similar to #14831, in that primitive types are being included in import statement generation.

Suggest a fix

It seems like we shouldn't be adding all models here; instead we should only add all models that are not of a type contained in baseSpecs.
If models is used for something else other than import generation, maybe we can edit this line of api.mustache to not include models of primitive type. (I tried doing this, but wasn't successful. I don't understand how to use variables with mustache well.)

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

Reproduce the issue with the plaid-openapi 2020-09-14.yml input and the documented Clojure generation command. Read ClojureClientCodegen.java around line 217 and clojure/api.mustache around line 6, then inspect related generator tests. Done means generated API files import only models that have generated complex-type specs.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure, java
Domain
api, 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.