Skip to content

[BUG][typescript-fetch] nullable arrays with a default null throws an error. #19825

Description

@yannickl88

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)

We have a schema which can either be null or a list of object. This is mainly to allow the parameter to be optionally passed and to detect if the property was set to do case distinction on. So passing null vs [] behaves differently. (Similarly, as passing and empty string vs null)

However, when encoding this in a spec and trying to generate an typescript-fetch client for this, it results in an error.

Description
openapi-generator version

7.9.0

OpenAPI declaration file content or url
openapi: '3.0.3'

info:
  title: Test
  version: 0.1.0

paths: {}

components:
  schemas:
    Test:
      type: array
      items:
        type: string
      default: null
      nullable: true
Generation Details
$ java -jar "/node_modules/@openapitools/openapi-generator-cli/versions/7.9.0.jar" generate --input-spec="/test_schema.yaml" --generator-name="typescript-fetch" --output="/tmp/" --additional-properties="withInterfaces=true"
Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 1, Warning count: 3
Errors: 
     -attribute components.schemas.PaymentConfigurationResponse.default is not of type `array`
Warnings: 
     -attribute components.schemas.PaymentConfigurationResponse.default is not of type `array`

     at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:717)
     at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:744)
     at org.openapitools.codegen.cmd.Generate.execute(Generate.java:527)
     at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
     at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Steps to reproduce

Run the command with the given schema

Related issues/PRs

None

Suggest a fix

null defaults are allowed when nullable, regardless of the type (array in this case).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions