OpenAPITools / OpenAPITools/openapi-generator
[BUG] `is not of type 'object'` when `#/` referencing
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failures with MySchema.yaml, src/spec.yaml, and MySchemaProps.yaml using the generator version described, then compare behavior with a bundled and dereferenced spec. Inspect the validation and reference-resolution path for schema properties and the Kotlin allOf example; done means valid local references and composition generate without the reported errors or clunky loss of context.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100