OpenAPITools / OpenAPITools/openapi-generator

[BUG] "default: null" is considered to be an error even with "nullable: true"

Open
#16,775 2 comments 1 reaction 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)?
  • 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)
Description

OpenApiGenerator CLI considers default: null is not correct for an attribute even if it has nullable: true

openapi-generator version

OpenApiGenerator CLI 7.0.1

OpenAPI declaration file content or url
openapi: 3.0.3
info:
 title: test
 version: v0.1
 description: test
paths:
 /api/path:
  get:
   responses:
    '200':
      description: ok
      content:
       application/json:
        schema:
         $ref: '#/components/schemas/MyEntity'
components:
 schemas:
  MyEntity:
   type: object
   properties:
    someField:
     type: array
     items: 
       type: string
     nullable: true
     default: null
Generation Details
Steps to reproduce

java -jar openapi-generator-cli-7.0.1.jar generate --generator-name csharp --input-spec my_spec.yaml --output out_dir

(nb: I'm writing --generator-name csharp because I have to pick a generator name in order to have a valid command, but I'm observing the issue with every generator)

  • Expected behavior: the command runs successfully (ie: it generates code and exits with 0 status code)
  • Actual behavior: the command exits with 1 status code and display the error
 | Error count: 1, Warning count: 0                                           
Errors:
        -attribute components.schemas.MyEntity.default is not of type `array` 

Note that I would expect this command to work because:

default – the default value must conform to the specified schema.

and that value (null) conforms the schema because it has nullable: true

Related issues/PRs
Suggest a fix

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 provided openapi-generator-cli 7.0.1 command with the YAML declaration and reproduce the validation error for components.schemas.MyEntity.default. Trace the CLI validation path to compare default: null with nullable: true; done means the declaration is accepted and generation exits with status 0 for the reported case.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.