Skip to content

[BUG] [JAVA] Compilation error of array field in oneOf field, value of complextype is empty #18274

@fanqiewanzi

Description

@fanqiewanzi

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

A compilation error occurs in the generated code when using the oneof field.

By checking the template, we found that the corresponding complextype is empty.

As you can see from the picture below, something was missing.

image

openapi-generator version

7.4.0 (7.3.0 also tried)

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: SDK API
  description: SDK API
  version: 1.0.0
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
  
servers:
  - url: https://test.com:443

paths:
  /sdk/test:
    get:
      tags:
        - test
      summary: test
      description: test
      operationId: test
      responses:
        '200':
          $ref: '#/components/responses/TestResponse'

components:
  responses:
    TestResponse:
      description: test return
      content:
        application/json:
          schema:
            allOf:
            - type: object
              properties:
                data:
                  type: object
                  description: test
                  properties:
                    rule_config:
                      type: object
                      description: test
                      properties:
                        operator:
                          oneOf:
                          - type: array
                            items:
                              type: string
                          - type: string
                            example: 'gt'
                          description: test operator
Generation Details

Target Language: Java
Config.yaml:

additionalProperties:
  withAWSV4Signature: true
  library: okhttp-gson
  useBeanValidation: true
  useSingleRequestParameter: true
  apiPackage: com.sdk.v2018
  modelPackage: com.sdk.v2018.model
  artifactDescription:  SDK for Java
  artifactId: sdk2018
  artifactVersion: 1.0.0
  useOneOfInterfaces: true
Steps to reproduce
  1. generate sdk using openapi-generator-cli
  2. pack sdk code to jar using maven
Related issues/PRs
Suggest a fix

I guess there may be a problem with the template or a problem with complextype processing in the children of the oneOf filed.
the anyof filed probably has the same problem.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions