OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] JSON SubType case wrong in Java class reference

Open
#2,413 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

v3.3.4

yaml below produces a class "MyEvent" (.java) - initial letter capitalized -, but consumes that very class with lower-case (e.g. myEvent.class).

Steps:

  • generate for Java
  • mvn clean compile

// exp: compiles
// act: breaks "cannot find symbol symbol: class myEvent"

Root cause is apparently that code generator does capitalize, but that this capitalization is not sent into all dependent generators.

---
swagger: '2.0'
basePath: "/v1"
info:
  version: "1.0.0"

schemes:
  - https
consumes:
  - application/json
produces:
  - application/json
paths:
  /events:
    get:
      tags:
        - events
      operationId: "getEvents"
      responses:
        '200':
          description: Events
          schema:
            $ref: '#/definitions/eventCollection'
definitions:
  eventCollection:
    type: object
    properties:
      events:
        type: array
        items:
          $ref: '#/definitions/event'
      count:
        type: integer
        format: int32
        example: 1
    required:
      - events
      - count
  event:
    type: object
    discriminator: eventType
    properties:
      sequenceOffset:
        type: integer
        format: int64
      eventType:
        type: string

  myEvent:
    allOf:
      - $ref: '#/definitions/event'
      - type: object
        properties:
          id:
            type: string

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 supplied Swagger YAML and generate the Java client, then run mvn clean compile to reproduce the myEvent versus MyEvent reference error. Trace how the Java generator propagates model names to dependent generators; done means the generated Java sources compile and consistently use the capitalized class name.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.