swagger-api / swagger-api/swagger-codegen
[Java] Is there a way to reference other Domains in oas3, but not generate the models?
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I am attempting to build an object in Java from multiple smaller objects that can be referenced in multiple different Domains or APIs whose models are already generated and in use. Using the swagger-codegen-maven-plugin, I am able to generate and add cli options.
When I do generate the object, it will extend the first allOf entry and add the fields of all subsequent entries (expected and wanted). For the subsequent entries, it will still generate and import the model, which I would like to prevent.
Swagger-codegen version
version 3.0.25 (This is the version for swagger-codegen-maven-plugin)
Swagger declaration file content or url
MasterYml
components:
schemas:
MainObject:
allOf:
- $ref: 'some/path/SubYml#components/schemas/SubObject1' #want to extend and import
- $ref: 'some/path/SubYml#components/schemas/SubObject2' #only want fields
- $ref: 'some/path/SubYml#components/schemas/SubObject3' #only want fields
SubYml
components:
schemas:
SubObject1:
properties:
prop1: string
SubObject2:
properties:
prop2: string
SubObject3:
properties:
prop3: string
Results
This generates a class named MainObject that extends SubObject1 and contains all fields from SubObject2 and SubObject3 as well as generates and imports SubObject2 and 3. I would have already overridden the import for SubObject1 using the import mappings option to import the current existing object.
Again, the outcome I would like is to not generate the "extra" allOf models and just use them to apply their fields to the MainObject
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 swagger-codegen-maven-plugin behavior for the provided MasterYml/SubYml allOf references and import mappings, reproducing the example with version 3.0.25. Done means SubObject1 can remain an imported superclass while SubObject2 and SubObject3 contribute fields without generated model classes or imports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100