OpenAPITools / OpenAPITools/openapi-generator
[BUG][scala-akka-http-server] Same definition classes are reused in different schemas
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 same schemas are exists in schema difinition, openapi-generator reuse generated one scehma in different schemas.
openapi-generator version
master branch in this commit.
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: XXX API
version: 1.0.0
paths:
/api1:
description: api1
get:
operationId: api1
responses:
"200":
description: api1
content:
application/json:
schema:
$ref: "#/components/schemas/Api1"
/api2:
description: api2
get:
operationId: api2
responses:
"200":
description: api2
content:
application/json:
schema:
$ref: "#/components/schemas/Api2"
components:
schemas:
Api1:
type: object
properties:
data:
type: object
properties:
id:
type: string
Api2:
type: object
properties:
data:
type: object
properties:
id:
type: string
Steps to reproduce
With following code, Api2 contains Api1Data.
> git pull origin master
> ./mvnw clean install
> java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-g scala-akka-http-server \
-i sample.yaml \
-o /var/tmp/scala-akka-http-server
> cat /var/tmp/scala-akka-http-server/src/main/scala/org/openapitools/server/model/Api*
package org.openapitools.server.model
/**
* @param data for example: ''null''
*/
final case class Api1 (
data: Option[Api1Data] = None
)
package org.openapitools.server.model
/**
* @param id for example: ''null''
*/
final case class Api1Data (
id: Option[String] = None
)
package org.openapitools.server.model
/**
* @param data for example: ''null''
*/
final case class Api2 (
data: Option[Api1Data] = None
)
Related issues/PRs
Suggest a fix
In this result, Api1Data is reused in Api1 and Api2. I think openapi-generator should generate following 4 classes.
final case class Api1 (
data: Option[Api1Data] = None
)
final case class Api1Data (
id: Option[String] = None
)
final case class Api2 (
data: Option[Api2Data] = None
)
final case class Api2Data (
id: Option[String] = None
)
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 documented scala-akka-http-server generation command with the supplied OpenAPI YAML, then inspect the generated Api1 and Api2 model files under src/main/scala/org/openapitools/server/model. Trace how the nested data schemas are named and reused; done means Api1Data and Api2Data are generated separately and Api2 refers to Api2Data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100