Duplicate classes / Models are generated if ( $ref) referenced externally.
See original GitHub issueDescription
If Schemas are referenced in cyclic manner, the Models are generated twice. In below code,the Model ProblemDetails is generated twice as
ProblemDetails.javaProblemDetails2.java
Is the correct way to reference? If Not why? and How to fix the above case?
openapi-generator version
openapi-generator-cli-4.0.0-beta3
OpenAPI declaration file content or url
openapi.yaml
openapi: 3.0.0
info:
title: Common Data Types
version: "1.0"
paths:
/{appId}/subscriptions:
get:
summary: read all of the active subscriptions for the app.
operationId: getSubscriptionsById
parameters:
- name: appId
in: path
description: App ID
required: true
schema:
type: integer
format: int64
responses:
'200':
description: OK (Successful)
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Subscription'
'500':
$ref: './common.yaml#/components/responses/E500'
components:
schemas:
ProblemDetails:
type: object
properties:
title:
type: string
description: A short, human-readable summary of the problem
status:
type: integer
description: The HTTP status code for this occurrence of the problem.
Subscription:
type: string
common.yaml
openapi: 3.0.0
info:
title: Common Data Types
version: "1.0"
paths: {}
components:
responses:
E500:
description: Server Error
content:
application/json:
schema:
$ref: './openapi.yaml#/components/schemas/ProblemDetails'
Command line used for generation
java -jar openapi-generator-cli-4.0.0-beta3.jar generate -i openapi.yaml -g spring -o ./temp
Issue Analytics
- State:
- Created 4 years ago
- Reactions:14
- Comments:38 (12 by maintainers)
Top Results From Across the Web
Turn off the generation of externally referenced models in ...
I am aware of this method. I am looking for something like the external reference is not generated all together.
Read more >Convert Subsystems to Referenced Models - MathWorks
Convert Subsystems to Referenced Models. Model reference offers benefits for modeling large, complex systems and for team-based development.
Read more >The difference between class duplication and class extension
When we duplicate a class we effectively create a separate instance or copy of that class. Any changes to the original class or...
Read more >Using classes - JavaScript - MDN Web Docs - Mozilla
We will be playing with the well-abstracted class model in this tutorial, ... On the first line, we created an instance of the...
Read more >Duplicate classes in managed assets can cause issues ... - IBM
If your code is correct, then the issue can be caused by duplicate classes loaded into the system. The classloader can load only...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
After playing around with external refs for a bit I discovered that swagger-parser will do some normalization on them, but it seems to happen lazily.
If you have a ref like
then it will become
inside the parser after the first time this ref is resolved. Internally
SomeSchemais cached when it is first read, when accessed the second time its source is different (somefile.yml != ./somefile.yml) so a number is appended to its name to avoid conflicts.Prefixing relative paths with
./solves this problem, but it seems the parser still has problems normalizing the paths relative to the root spec file as having complex relative references (e.g. different levels, from different subdirectories) still break the parser.Hi all, For example insted of: ‘./common.yaml#/components/responses/E500’ write ‘./common.yaml/#/components/responses/E500’
After this modification I was able to remove duplicity 😉