OpenAPITools / OpenAPITools/openapi-generator
[BUG] Endpoint returning imported type throws "attribute ... is missing" error
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
Generating for a declaration returning an imported type (type specified using importMappings) for an endpoint will throw an attribute ... is missing error.
openapi-generator version
5.0.1
OpenAPI declaration file
src/main/resources/test.yaml:
openapi: 3.0.3
info:
title: test
version: v1
paths:
/test:
get:
responses:
200:
description: ok
content:
application/json:
schema:
$ref: '#/components/schemas/Test'
#$ref: '#/components/schemas/TestAlias'
components:
schemas:
TestAlias:
$ref: '#/components/schemas/Test'
Generation Details
build.gradle:
plugins { id "org.openapi.generator" version "5.0.1" }
apply plugin: 'java'
sourceCompatibility = '1.8'
openApiGenerate {
generatorName = "spring"
inputSpec = "${sourceSets.main.resources.srcDirs[0]}/test.yaml"
configOptions = [interfaceOnly: "true"]
//skipValidateSpec = true
importMappings = ["Test": "java.lang.String"]
}
Steps to reproduce
project structure:
src/main/resources/test.yaml
build.gradle
run: gradle openApiGenerate
Workaround till it's fixed
Referencing an alias type referring to the imported one (TestAlias the in example above) will make the generator work as expected.
Moreover running the generator for the original declaration (w/ Test) w/ skipValidateSpec = true the output will be exactly the same as running it for the alias type. (Of course the validation of other parts will also be skipped this way.)
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
Reproduce the failure with src/main/resources/test.yaml and build.gradle using the spring generator and gradle openApiGenerate. Compare generation for the imported Test type with the working TestAlias workaround, then trace the reported missing-attribute error. Done means the imported endpoint generates successfully without requiring skipValidateSpec while preserving the expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100