OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.35k stars 6.46k forks source link

[BUG] `is not of type 'object'` when `#/` referencing #14317

Open wingsofovnia opened 1 year ago

wingsofovnia commented 1 year ago

Bug Report Checklist

Description

I've been following the idea from https://github.com/OAI/OpenAPI-Specification/issues/1590#issuecomment-786447707 to "override" required field.

MySchema.yaml

type: object
properties:
  foo: 
    type: integer
  bar:
    type: integer
required:
  - foo
  - bar

src/spec.yaml

patch:      
  summary: Update something
  requestBody:
    content:                                     
      application/json:
        schema:
          type: object
          properties:
            $ref: ../components/schemas/MySchema.yaml#/properties

The generator fails on:

-attribute paths.'.....requestBody.content.'application/json'.schema.properties is not of type `object`

It feels like validation ignores #/properties. bundling with -dereference however recognizes the reference correctly and works fine but applying generator on a bundled & dereferenced spec is a so-so workaround because it loses the filename context and generated DTOs have very clunky naming.

I also tried to walk around this by having: MySchemaProps.yaml

foo: 
    type: integer
  bar:
    type: integer

MySchema.yaml

type: object
properties:
  $ref: './MySchemaProps.yaml'

to avoid #/ ref, but I get

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `io.swagger.v3.oas.models.media.ObjectSchema` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('./MySchemaProps.yaml')
 at [Source: UNKNOWN; byte offset: #UNKNOWN]

Again, bundling with -dereference works fine on this too but not generator.

Neither works an example from spec: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#models-with-composition all allOf props in Kotlin generator goes to some weird allOf-prefixed data class and there is no DTO with all of the properties in one place.

openapi-generator version

6.2.1

Related issues/PRs
simonwfarrow commented 1 year ago

Hi - is there a fix to this? The workaround of dereference'ing did not work for me. Thanks