swagger-api / swagger-api/swagger-codegen

allOf needs `$ref` first

Open
#2,924 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature: Composition / Inheritance Issue: Bug Issue: Workaround available
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When generating a library with an allOf construct in a model definition, the codegen seems to have problems if the first array item is an inline object vs. a model reference

Swagger-codegen version

2.1.6

Command line used for generation

Occurs on java with this trace:

Exception in thread "main" java.lang.RuntimeException: Could not process model 'XXXX'
    at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:244)
    at io.swagger.codegen.cmd.Generate.run(Generate.java:223)
    at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:36)
Caused by: java.lang.ClassCastException: io.swagger.models.ModelImpl cannot be cast to io.swagger.models.RefModel
    at io.swagger.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:955)
    at io.swagger.codegen.languages.JavaClientCodegen.fromModel(JavaClientCodegen.java:541)
    at io.swagger.codegen.DefaultGenerator.processModels(DefaultGenerator.java:799)
    at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:237)

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 at DefaultGenerator.generate and trace the stack into DefaultCodegen.fromModel and JavaClientCodegen.fromModel. Reproduce Java generation with an allOf whose inline object precedes a model reference; done means generation no longer fails with the reported ModelImpl-to-RefModel ClassCastException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.