openapi-generator
openapi-generator copied to clipboard
[BUG][scala-akka-http-server] Same definition classes are reused in different schemas
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] 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
)
workaround: make them different using example and so on
*** asis.yaml Thu Oct 13 21:51:54 2022
--- tobe.yaml Thu Oct 13 21:51:40 2022
***************
*** 35,40 ****
--- 35,41 ----
properties:
id:
type: string
+ example: bar
Api2:
type: object
properties:
***************
*** 43,45 ****
--- 44,47 ----
properties:
id:
type: string
+ example: foo