Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: [oneOf decode failed] #1230

Open
akkuman opened this issue Apr 29, 2024 · 0 comments
Open

[Bug]: [oneOf decode failed] #1230

akkuman opened this issue Apr 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@akkuman
Copy link

akkuman commented Apr 29, 2024

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?

@akkuman akkuman added the bug Something isn't working label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant