OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.62k stars 6.29k forks source link

[BUG] CodegenConfigurator crashing when allOf overridden #2811

Open medwards opened 5 years ago

medwards commented 5 years ago

When trying to override a basic type alias with a default I get a stacktrace failure and com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting ('true', 'false' or 'null') and SwaggerCompatConverter - failed to read resource listing.

The guilty part of the spec looks something like (obviously simplified):

SomeThing:
  properties:
    duration:
      description: "The duration of SomeThing"
      default: 0
      allOf:
        - $ref: 'Duration'
Duration:
  type: integer
  description: Duration in seconds

Alternative forms fail the same way:

SomeThing:
  properties:
    duration:
      allOf:
        - $ref: 'Duration'
        - description: "The duration of SomeThing"
          default: 0

Duration:
  type: integer
  description: Duration in seconds
openapi-generator version

master, I think its a regression as I was using an older version of master /wo the issue

Command line used for generation

Occurs when I just validate. Also when generating rust /w reqwest but the bug hits way before any codegen happens

Steps to reproduce

Validate a spec that sets a default for an inherited schema object. Deleting the default allows it to validate.

wing328 commented 5 years ago

com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting ('true', 'false' or 'null')

Looks like a spec issue. Can you validate it using https://apidevtools.org/swagger-parser/online/ ?

medwards commented 5 years ago

The following example passes validation on the linked swagger parser: https://pastebin.com/ShkPm323

It crashes the openapi-generator validation command in its current version on 5b7dbd1 (I have some commits on top but the crash comes well before anything these commits affect). I also tried changing:

        duration:
          allOf:
            - $ref: '#/components/schemas/Duration'
            - default: 0

This also crashes. Removing default: 0 passes.

wing328 commented 5 years ago
      allOf:
       - $ref: '#/components/schemas/Duration'
       - default: 0

I agree the generator shouldn't crash. What does "default: 0" mean here? does it mean the default value of '#/components/schemas/Duration' ?

medwards commented 5 years ago

sorry for the late reply: Yes, it does.