swagger-editor icon indicating copy to clipboard operation
swagger-editor copied to clipboard

"default: null" on non nullable object isn't considered as an error

Open gturri opened this issue 10 months ago • 0 comments

Q&A (please complete the following information)

  • OS: Windows
  • Browser: Firefox
  • Version: 118.0.1 (64 bits)
  • Method of installation: Not installed: I'm using it directly from https://editor-next.swagger.io/
  • Swagger-Editor version: 5.0.0-alpha78
  • Swagger/OpenAPI version: OpenApi 3.0.3

Content & configuration

Example Swagger/OpenAPI definition:

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
     default: null

Describe the bug you're encountering

  • Expected behavior: it detects an error on the last line of my spec because null is an invalid default value for an attribute of type array which does not have nullable: true Because according to the OAS spec (https://swagger.io/docs/specification/data-models/keywords/ ) :

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

  • Actual behavior: https://editor-next.swagger.io/ reports no error on the spec shared just above

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor-next.swagger.io/
  2. Copy / paste the spec above

Expected behavior

An error saying that the default value cannot be null, is detected

Screenshots

As shown on this screenshot: in practice I don't have any error image

Additional context or thoughts

FTR: OpenApiGenerator does detect that error: when I run OpenApiGenerator CLI like this

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

it fails with message

Errors:                                                                      
        -attribute components.schemas.MyEntity.default is not of type `array`

gturri avatar Oct 10 '23 09:10 gturri