OpenAPITools / OpenAPITools/openapi-generator

[BUG] [scala-client]Models not generated properly if additionalProperties referenced schema is array

Open
#11,721 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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

scala client generator doesn't generate the model properly if its additionalProperties refer to a schema which type is array, the referenced schema wasn't generated. The issue occurs in the both scala-sttp and scala-akka

openapi-generator version

The version 5.3.x, 5.4.x and the latest master branch (6.0.0)

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: stringToModelMapping
  version: "3.0.0"
paths:
  /:
    get:
      summary: Empty Route
      responses:
        "200":
          description: Good Request.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/FreeformObjectTypes'
        "400":
          description: Bad Request.
        "403":
          description: Forbidden. Access denied.
components:
  schemas:
    SimpleModel:
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
    ArrayModel:
      type: array
      items:
        $ref: '#/components/schemas/SimpleModel'
    FreeformObjectTypes:
      type: object
      properties:
        stringToModelMapping:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/SimpleModel'
        stringToArrayModelMapping:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/ArrayModel'
Generation Details

Command line used for generation

openapi-generator-cli generate \
  -g scala-sttp \
  -i name_of_file.yaml \
  -p mainPackage=myPackage \
  -o myApi

Issues in the generated client:

  • No model class of referenced schema ArrayModel;
  • The model class of FreeformObjectTypes refer to Seq without type.
case class FreeformObjectTypes(
  stringToModelMapping: Option[Map[String, SimpleModel]] = None,
  stringToArrayModelMapping: Option[Map[String, Seq]] = None
)

Expect:

case class FreeformObjectTypes(
  stringToModelMapping: Option[Map[String, SimpleModel]] = None,
  stringToArrayModelMapping: Option[Map[String, Seq[SimpleModel]]] = None
)
Steps to reproduce
Related issues/PRs
Suggest a fix

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

Run the supplied openapi-generator-cli command with the YAML declaration and inspect the generated scala-sttp models, then compare scala-akka output. Trace handling of additionalProperties referencing ArrayModel; done means ArrayModel is generated and FreeformObjectTypes uses Map[String, Seq[SimpleModel]] rather than an untyped Seq.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, scala
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.