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

[PHP] Handle non-required property as nullable

Open fMads opened this issue 8 years ago • 2 comments

Description

When a property isn't required, it is not shown in Doc Block, that the getter can actually return "null". Also it is not shown in the setter, that "null" is a valid value

Swagger-codegen version

2.3

Swagger declaration file content or url
  /path
    post:
      parameters:
        - in: body
          required: true
          name: objectName
          schema:
            type: object
            required:
              - requiredPropertyName
            properties:
              requiredPropertyName:
                type: string
              notRequiredPropertyName:
                type: string
Suggest a fix/enhancement

Change returnType in Doc Block for getters to correctly show, that the returned value can be null (if the property is not required). Also shown in Doc Block for setters, that value can be null (if property is not required)

fMads avatar May 09 '18 08:05 fMads

How does required interact with nullable? https://swagger.io/docs/specification/data-models/data-types/#null

  /path
    post:
      parameters:
        - in: body
          required: true
          name: objectName
          schema:
            type: object
            required:
              - requiredPropertyName
              - requiredNullablePropertyName
            properties:
              requiredPropertyName:
                type: string
              notRequiredPropertyName:
                type: string
              requiredNullablePropertyName:
                type: string
                nullable: true
              notRequiredNullablePropertyName:
                type: string
                nullable: true

Isn't |null supposed to be defined by the nullable property instead of required? I think:

  • a required nullable property must be present in the object but the value may be null.
  • a required not-nullable property must be present and cannot be null
  • a non-required nullable property might not be present but if present can have a null value
  • a non-required not-nullable property might not be present, but if present cannot have a null value

Am I missing something?

cognifloyd avatar Jul 21 '18 06:07 cognifloyd

@cognifloyd That sounds correct :) The issue though is, that we only have null to represent optional. If the field is optional, and it's not filled, then it's value will be "null".

fMads avatar Aug 03 '18 08:08 fMads