OpenAPITools / OpenAPITools/openapi-generator

[BUG] NPE when validating schema with allOf with inline values

Open
#4,681 1 comment 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)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

Using a schema with an allOf with an inline object, i.e.

components:
  schemas:
    allOfInline:
      allOf:
        - type: object
          properties:
            name:
              type: string

causes the validator (with recommend, which is default with the Maven job) to fail with a NullPointerException:

java.lang.NullPointerException: element cannot be mapped to a null key                                                      at java.util.Objects.requireNonNull (Objects.java:246)                                                                  at java.util.stream.Collectors.lambda$groupingBy$53 (Collectors.java:1127)                                              at java.util.stream.ReduceOps$3ReducingSink.accept (ReduceOps.java:169)                                                 at java.util.stream.ReferencePipeline$2$1.accept (ReferencePipeline.java:177)                                           at java.util.Iterator.forEachRemaining (Iterator.java:133)                                                              at java.util.Spliterators$IteratorSpliterator.forEachRemaining (Spliterators.java:1801)                                 at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:484)                                               at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:474)                                        at java.util.stream.ReduceOps$ReduceOp.evaluateSequential (ReduceOps.java:913)                                          at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)                                               at java.util.stream.ReferencePipeline.collect (ReferencePipeline.java:578)                                              at org.openapitools.codegen.utils.ModelUtils.getChildrenMap (ModelUtils.java:880)                                       at org.openapitools.codegen.utils.ModelUtils.getUnusedSchemas (ModelUtils.java:120)                                     at org.openapitools.codegen.config.CodegenConfigurator.toContext (CodegenConfigurator.java:462)                         at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput (CodegenConfigurator.java:498)                  at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:705)
openapi-generator version

4.2.2

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  version: 1.0.0
  title: Example
  license:
    name: MIT
servers:
  - url: http://api.example.xyz/v1
paths:
  /person:
    get:
      operationId: list
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/allOfInline"
components:
  schemas:
    allOfInline:
      allOf:
        - type: object
          properties:
            name:
              type: string

Command line used for generation

java -jar openapi-generator-cli.jar validate -i allOf-inline.yaml --recommend

(or use Maven)

Steps to reproduce

Execute command as above

Related issues/PRs

Regression was introduced in 10627ed5cc3f4703b0f02662ea568353e8d26e00 during the fix of #4335

Suggest a fix

PR incoming

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 in org.openapitools.codegen.utils.ModelUtils, especially getChildrenMap and getUnusedSchemas, using the supplied allOf-inline.yaml and the validate command with --recommend. Trace the null key reported in the stack trace and verify that validation completes without a NullPointerException for the reproduction schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.