OpenAPITools / OpenAPITools/openapi-generator
[BUG] [SPRING] OpenAPI generated DTO interface doesn't include required properties other than discriminator
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?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generating objects for polymorphism, only the discrminator property is actually included, other properties are ignored from the interface.
For example given the example shown later on, I would expect the interface to look like:
public interface CoreSchema {
public String getDiscriminatorProperty();
public String getAnotherValue();
}
However what I get is just:
public interface CoreSchema {
public String getDiscriminatorProperty();
}
with getAnotherValue() missing. The subclass implementations are all correct and do contain this getter however, so the code does technically work but need to use instanceof (in Java) to be able to access the anotherValue string. This shouldn't be necessary and should be accessible on the incoming interface.
openapi-generator version
7.4.0
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: Test Integration
description: Test API spec for Gradle generation plugin
version: v1
tags:
- name: test
description: Methods relating to testing API spec for Gradle generation plugin
paths:
/pattern-validation:
post:
tags:
- test
description: Returns body
operationId: patternValidationPost
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/CoreSchema'
required: true
responses:
'200':
description: Test requested
'400':
description: Bad request
components:
schemas:
CoreSchema:
type: object
properties:
discriminatorProperty:
type: string
anotherValue:
type: string
required:
- discriminatorProperty
- anotherValue
discriminator:
propertyName: discriminatorProperty
mapping:
ONE: '#/components/schemas/OneSchema'
TWO: '#/components/schemas/TwoSchema'
oneOf:
- $ref: '#/components/schemas/OneSchema'
- $ref: '#/components/schemas/TwoSchema'
OneSchema:
type: object
required:
- anotherValue
properties:
anotherValue:
type: string
pattern: '^\d{3}$'
TwoSchema:
type: object
required:
- anotherValue
properties:
anotherValue:
type: string
pattern: '^\d{8}$'
servers:
- url: 'http://localhost:8080'
Generation Details
Spring Generator, via Gradle plugin
Steps to reproduce
Create an OpenAPI spec with polymorphic components described similar to above structure
Run generator for Spring
Check created DTO classes
Related issues/PRs
Unsure
Suggest a fix
Unsure
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 running the Spring generator through the Gradle plugin with the OpenAPI declaration provided in the issue, then inspect the generated DTO interfaces and subclass implementations. The reproduction is complete when the CoreSchema interface exposes getters for both discriminatorProperty and anotherValue without requiring instanceof access.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100