Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nullable arrays with a default null throws an error #2125

Open
yannickl88 opened this issue Oct 10, 2024 · 1 comment
Open

nullable arrays with a default null throws an error #2125

yannickl88 opened this issue Oct 10, 2024 · 1 comment

Comments

@yannickl88
Copy link

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.

Spec I tried:

openapi: '3.0.3'

info:
  title: Test
  version: 0.1.0

paths: {}

components:
  schemas:
    Test:
      type: array
      items:
        type: string
      default: null
      nullable: true

When running this through the OpenAPI generator, the swagger validation seems to fail.

$ 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)

My expectation is that this would be valid. I expect null defaults are allowed when nullable, regardless of the type (array in this case).

PS: I initially reported this at OpenAPITools/openapi-generator, OpenAPITools/openapi-generator#19825

@GabeK0
Copy link

GabeK0 commented Nov 26, 2024

I've encountered the same thing, would love to get a fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants