Skip to content

OpenAPI3 type property should always be set when nullable property is present #4584

@akishichinibu

Description

@akishichinibu

Discussed in #4543

Originally posted by akishichinibu September 26, 2024
https://typespec.io/playground?c=c2NhbGFyIE15U3RyIGV4dGVuZHMgc3RyaW5nOwoKbW9kZWwgQSB7CiAgeDrHJnwgbnVsbAp9Cg%3D%3D&e=%40typespec%2Fopenapi3&options=%7B%7D

Consider the following TypeSpec definition:

scalar MyStr extends string;

model A {
  x: MyStr | null;
}
openapi: 3.0.0
info:
  title: (title)
  version: 0.0.0
tags: []
paths: {}
components:
  schemas:
    A:
      type: object
      required:
        - x
      properties:
        x:
          oneOf:
            - $ref: '#/components/schemas/MyStr'
          nullable: true
    MyStr:
      type: string

This generates the following OpenAPI specification, which violates the Redoc rule spec.

The `type` field must be defined when the `nullable` field is used.

In this case, the error occurs because the nullable field is used without defining the type explicitly within the oneOf clause, which Redoc requires for proper validation.

How can I fix this?

Metadata

Metadata

Assignees

Type

No type
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