Skip to content

[Bug]: [oneOf decode failed] #1230

@akkuman

Description

@akkuman

What version of ogen are you using?

v1.1.0

Can this issue be reproduced with the latest version?

Yes

What did you do?

command: go run -mod=mod github.com/ogen-go/ogen/cmd/ogen -clean -config gen.cfg.yml -target api -package api openapi.yaml

  • gen.cfg.yml
generator:
  features:
    disable:
      - 'paths/server'
  • openapi.yaml
openapi: 3.0.1
info:
  title: test
  description: ''
  version: 1.0.0
tags: []
paths:
  /tasks/{id}/data:
    get:
      tags: []
      parameters:
        - name: id
          in: path
          description: ''
          required: true
          schema:
            type: string
        - name: page
          in: query
          description: ''
          required: false
          schema:
            type: number
        - name: size
          in: query
          description: ''
          required: false
          schema:
            type: number
      responses:
        '200':
          description: success
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                  message:
                    type: string
                    enum:
                      - error
                      - success
                  total:
                    type: integer
                  error:
                    type: string
                  data:
                    type: array
                    items:
                      allOf:
                        - type: object
                          additionalProperties: false
                          properties:
                            _id:
                              type: string
                            _tid:
                              type: string
                          required:
                            - _id
                            - _tid
                        - oneOf:
                            - $ref: '#/components/schemas/baiduwenku'
                            - $ref: '#/components/schemas/doc88'
                            - $ref: '#/components/schemas/xianlanben'
                required:
                  - status
                  - message
                  - total
                  - data
                  - error
      security:
        - apikey-header-Authorization: []
components:
  schemas:
    xianlanben:
      type: object
      properties:
        bundleid:
          type: string
          title: bundleid
        dataType:
          type: integer
        description:
          type: string
        onlineStatus:
          type: integer
          enum:
            - 1
            - 0
        validBundleid:
          type: string
        logo:
          type: string
        name:
          type: string
        prid:
          type: string
        comments:
          type: integer
        developer:
          type: string
        platform:
          type: string
        category:
          type: string
        version:
          type: string
        appcreatedate:
          type: string
        appmodifydate:
          type: string
      required:
        - bundleid
        - dataType
        - description
        - onlineStatus
        - validBundleid
        - logo
        - name
        - prid
        - comments
        - developer
        - platform
        - category
        - version
        - appcreatedate
        - appmodifydate
      description: app list
    doc88:
      type: object
      properties:
        title:
          type: string
        link:
          type: string
        desc:
          type: string
        created_time:
          type: string
        pagetotal:
          type: string
        file_type:
          type: string
          description: docx\pdf
        viewcount:
          type: string
      required:
        - title
        - link
        - desc
        - created_time
        - pagetotal
        - file_type
        - viewcount
    baiduwenku:
      type: object
      properties:
        file_type:
          type: string
          description: docx/pdf
        cover_imgs:
          type: array
          items:
            type: string
        title:
          type: string
        tags:
          type: string
        desc:
          type: string
        score:
          type: string
        pagetotal:
          type: string
        viewcount:
          type: string
        link:
          type: string
      required:
        - file_type
        - cover_imgs
        - title
        - tags
        - desc
        - score
        - pagetotal
        - viewcount
        - link
  securitySchemes:
    apikey-header-Authorization:
      type: apiKey
      in: header
      name: Authorization
servers: []
  • test.go
func TestOneOf(t *testing.T) {
	data := `{
		"status": "string",
		"message": "error",
		"total": 0,
		"error": "string",
		"data": [
			{
				"_id": "string",
				"_tid": "string",
				"file_type": "string",
				"cover_imgs": [
					"string"
				],
				"title": "string",
				"tags": "string",
				"desc": "string",
				"score": "string",
				"pagetotal": "string",
				"viewcount": "string",
				"link": "string"
			}
		]
	}`
	d := jx.DecodeBytes([]byte(data))
	var response api.TasksIDDataGetOK
	if err := response.Decode(d); err != nil {
		t.Error(err)
	}
}

error: decode TasksIDDataGetOK: callback: decode field "data": callback: decode TasksIDDataGetOKDataItem: callback: unexpected field "file_type"

What did you expect to see?

What did you see instead?

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