Skip to content

Unable to specify null value #961

@justrag

Description

@justrag

I have this case where I need to specify two fields where exactly one is given a value and the other is null (not omitted, but exactly null):
{fieldA: number, fieldB; null} | {fieldA: null, fieldB: string}
I can't seem to get it working.

              oneOf:
                - type: object
                  properties:
                    fieldA:
                      type: integer
                      minimum: 0
                    fieldB:
                      type: string
                      nullable: true
                      enum:
                        - null
                  required:
                    - fieldA
                    - fieldB
                - type: object
                  properties:
                    fieldA:
                      type: string
                      nullable: true
                      enum:
                        - null
                    fieldB:
                      type: string
                  required:
                    - fieldA
                    - fieldB

seems like should be the way to go, but the generator translates this into:
{fieldA: number, fieldB: string | null} | {fieldA: string | null, fieldB: string}

Is this the generator's error or is my spec not doing what I think it does?
I suspect a bug, as

              oneOf:
                - type: object
                  properties:
                    fieldA:
                      type: integer
                      minimum: 0
                    fieldB:
                      type: string
                      nullable: true
                      enum:
                        - dummy
                        - null
                  required:
                    - fieldA
                    - fieldB
                - type: object
                  properties:
                    fieldA:
                      type: string
                      nullable: true
                      enum:
                        - dummy
                        - null
                    fieldB:
                      type: string
                  required:
                    - fieldA
                    - fieldB

gives
{fieldA: number, fieldB: 'dummy' | null} | {fieldA: 'dummy' | null, fieldB: string}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions