Skip to content

gen: allOf and nullable generate broken code #1512

@WinPooh32

Description

@WinPooh32

What version of ogen are you using?

Latest commit at the main branch:
go run github.com/ogen-go/ogen/cmd/ogen@a794ac8

Can this issue be reproduced with the latest version?

Yes

What did you do?

I am trying to add nullable property using allOf:

            schema:
              type: object
              properties:
                field_1: # this field causes issues.
                  allOf:
                    - $ref: "#/components/schemas/dateTime"
                    - nullable: true

Full openapi.yaml:

openapi: 3.0.2
servers:
  - url: http://localhost:8000/api/v1
info:
  version: 1.0.0
  title: issue example
paths:
  /example:
    patch:
      requestBody:
        required: true
        content:
          "application/json":
            schema:
              type: object
              properties:
                field_1: # this field causes issues.
                  allOf:
                    - $ref: "#/components/schemas/dateTime"
                    - nullable: true
                field_2:
                  type: string
                  nullable: true
                field_3: # reference field without issues.
                  type: string
      responses:
        "200":
          description: "OK"
components:
  schemas:
    dateTime:
      type: string
      format: date-time
      description: |
        Date and Time
        [RFC3339](https://www.rfc-editor.org/rfc/rfc3339)
      example: "2006-01-02T15:04:05Z07:00"

What did you expect to see?

No compilation errors and nullable field.

What did you see instead?

$ go run github.com/ogen-go/ogen/cmd/ogen@a794ac8 -v --clean --config generate_config.yaml --target . -package example openapi.yaml
$ go build .
# ogenissue
./oas_json_gen.go:25:20: not enough arguments in call to s.Field1.Encode
        have (*jx.Encoder)
        want (*jx.Encoder, func(*jx.Encoder, time.Time))

Full example of the issue available here: https://github.com/WinPooh32/ogenissue

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions