OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][SPRING] model class for parameter component cannot be resolved
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 the OpenAPI spec contains reference to a parameter component, i.e. something under components/parameters, the generated code does not compile. It says:

Looking at the code:

openapi-generator version
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.2.0</version>
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Foo API
version: 2.1.0
description: Foo
contact:
name: foo
servers:
- url: http://localhost
tags:
- name: Foo
paths:
/foo/{bar}:
get:
description: get bar
operationId: getBar
tags:
- Foo
parameters:
- $ref: "#/components/parameters/bar"
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Foo"
components:
parameters:
bar:
name: bar
in: path
required: true
schema:
$ref: "#/components/schemas/Foo/properties/bar"
schemas:
Foo:
properties:
bar:
type: string
example: bar
Generation Details
Using openapi-generator-maven-plugin to generate. In pom.xml, I have:
<execution>
<id>1</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/foo.api.yaml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.example.foo.api</apiPackage>
<modelPackage>com.example.foo.model</modelPackage>
<configOptions>
<dateLibrary>java8</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<openApiNullable>false</openApiNullable>
<serializableModel>true</serializableModel>
</configOptions>
</configuration>
</execution>
Steps to reproduce
mvn clean compile
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 with the foo.api.yaml reproduction and the openapi-generator-maven-plugin configuration in pom.xml, then run mvn clean compile with the spring generator. Trace how the components/parameters reference is handled in generated Java code; done means the generated code resolves the parameter model and compiles successfully.
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
- 35/100