Skip to content

Support for nullable object #2733

Closed
Closed

Description

@Poorva17

Hello team,

I am interested in marking object type as nullable.

Following did not work for me. Student is not shown as nullable in api spec.

components:
  schemas:
    Student:
      type: object
      nullable: true // does NOT work
      properties:
        name:
          type: string
          nullable: true // works

Am I missing anything here?
Note: name property is being shown as null or string but not student object.

Activity

  1. loqusion commented on Oct 1, 2021

    @loqusion

    Assuming you're using version 3.1.0, nullable was apparently removed in favor of the 'null' type.

    See https://stackoverflow.com/a/48114322/17003575

  2. patrickuhlmann commented on Dec 7, 2021

    @patrickuhlmann

    I also noticed that if you define a property with the type string and nullable:true as required, the openapi-generator-maven-plugin with the generator spring will add the @NotNull annotation which seems wrong to me.

    Definition:

        SomeDto:
          type: object
          description: SomeDesc
          title: SomeTitle
          properties:
            abfahrt:
              type: string
              description: 'SomeDesc'
              example: '2021-12-03T09:26:22Z'
              format: date-time
              nullable: true
          required:
            - abfahrt
    

    Results in:

        @ApiModelProperty(
            example = "2021-12-03T09:26:22Z",
            required = true,
            value = "SomeDesc"
        )
        @NotNull
        @Valid
        public OffsetDateTime getAbfahrt() {
            return this.abfahrt;
        }
    
  3. handrews commented on Jan 25, 2024

    @handrews
    Member

    This was answered quite some time ago (use type: [object, "null"] in 3.1, where "null" must be a string and not a literal null), so I'm closing it as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions