"merging two sets of defaults is undefined" is occured when allOf with default value
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
Ah, OK. This is bug. && is correct instead of ||
https://github.com/deepmap/oapi-codegen/blob/1f53862bcc64573d3d0c4c105c71a8143e7b1816/pkg/codegen/merge_schemas.go#L142-L151
we need more work in kin-openapi repository
- https://github.com/getkin/kin-openapi/issues/884
@jamietanna hello there! can we get this merged? 🙏
it's been fixed on kin-openapi as well.
I ran into this today, is there anything I can do to help #1379?
This PR is already ready for review, so a merge should fix it.
- https://github.com/oapi-codegen/oapi-codegen/pull/1380