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

"merging two sets of defaults is undefined" is occured when allOf with default value

Open podhmo opened this issue 2 years ago • 5 comments

This is completely correct OpenAPI doc, but the error is occured.

          schema:
            allOf:
              - $ref: '#/components/schemas/TaskSortEnum'
              - default: -createdAt

result

$ oapi-codegen /tmp/openapi.yaml 
error generating code: error creating operation definitions: error describing global parameters for GET//tasks: error generating type for param (sort): error merging schemas: error merging schemas for AllOf: merging two sets of defaults is undefined

full OpenAPI doc is here

openapi: 3.0.0
info:
  description: ""
  title: tutorial tasklist API
  version: 0.1.0
servers:
  - description: local development server
    url: http://localhost:8888
components:
  schemas:
    Error:
      properties:
        code:
          description: Error code
          format: int32
          type: integer
        message:
          description: Error message
          type: string
      required:
        - code
        - message
      title: Error
      type: object
    Task:
      properties:
        title:
          type: string
        done:
          type: boolean
        createdAt:
          type: string
        updatedAt:
          type: string
      required:
        - title
        - done
        - createdAt
        - updatedAt
      type: object
    TaskSortEnum:
      enum:
        - createdAt
        - -createdAt
        - updatedAt
        - -updatedAt
      type: string
paths:
  /tasks:
    get:
      description: ""
      operationId: ListTask
      parameters:
        - in: query
          name: sort
          schema:
            allOf:
              - $ref: '#/components/schemas/TaskSortEnum'
              - default: -createdAt
      responses:
        '200':
          content:
            application/json:
              schema:
                items:
                  $ref: '#/components/schemas/Task'
                type: array
          description: ''
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: default error

podhmo avatar Dec 08 '23 05:12 podhmo

Ah, OK. This is bug. && is correct instead of ||

https://github.com/deepmap/oapi-codegen/blob/1f53862bcc64573d3d0c4c105c71a8143e7b1816/pkg/codegen/merge_schemas.go#L142-L151

podhmo avatar Dec 08 '23 05:12 podhmo

we need more work in kin-openapi repository

  • https://github.com/getkin/kin-openapi/issues/884

podhmo avatar Dec 08 '23 08:12 podhmo

@jamietanna hello there! can we get this merged? 🙏

it's been fixed on kin-openapi as well.

florentchauveau avatar Mar 19 '24 08:03 florentchauveau

I ran into this today, is there anything I can do to help #1379?

dharmab avatar Oct 03 '24 21:10 dharmab

This PR is already ready for review, so a merge should fix it.

  • https://github.com/oapi-codegen/oapi-codegen/pull/1380

podhmo avatar Oct 04 '24 12:10 podhmo