OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA][SPRING] Invalid allOf generation for RestAssured library

Open
#7,951 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Java Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • [ x ] Have you provided a full/minimal spec to reproduce the issue?
  • [ x ] Have you validated the input using an OpenAPI validator (example)?
  • [ x ] Have you tested with the latest master to confirm the issue still exists?
  • [ x ] Have you searched for related issues/PRs?
  • [ x ] What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Yaml files containing the allOf keywords don't work well with the rest-assured library. I'm getting a list of objects instead of a list of something reasonable, so I don't have direct access to its field.

openapi-generator version

I tested with the latest beta release (v5.0.0-beta2) and latest stable release

OpenAPI declaration file content or url
openapi: 3.0.2
info:
  title: ''
  description: ''
  version: 0.1.0
servers:
  - url: /v1/bar
paths:
  /foo:
    get:
      description: ''
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  foo:
                    description: ''
                    type: array
                    items:
                      allOf:
                        - type: object
                          properties:
                            first_id:
                              type: number
                              format: int64
                        - type: object
                          properties:
                            second_id:
                              type: number
                              format: int64
Generation Details

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i example.yaml -o /var/tmp/restassured --library rest-assured

Steps to reproduce, actual/expected output
  • Generate classes
  • Look inside InlineResponse200 class. Foo field is a list of Objects, not list of special generated POJOs
Related issues/PRs
Suggest a fix

It could be fixed by merging properties of each object into single object, but it requires time and this is manual operation

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 by running the command from the issue with the provided example.yaml and inspect the generated InlineResponse200 class. Trace how the Java rest-assured generator handles array items using allOf. Done means the foo field is generated as a typed list with access to first_id and second_id, with a regression test covering the specification.

Written by the indexing model from the issue text.

Assessment

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