swagger-api / swagger-api/swagger-codegen
[JAVA] Generating allOf model does not use typeMappings
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I would like to map existing type of generated code to another type (as a workaround for #10029 ) by typeMapping. It work partially: the name of class has been changed but the inheritance types have not and it causes compilation error.
Swagger-codegen version
2.4.15
Swagger declaration file content or url
swagger: '2.0'
info:
title: Swagger Petstore
description: Generating allOf model does not use typeMappings
version: 1.0.0
paths:
/pet/:
get:
responses:
200:
description: successful operation
schema:
$ref: '#/definitions/Pet'
/pet-summary/:
get:
responses:
200:
description: successful operation
schema:
$ref: '#/definitions/Pet-Summary'
definitions:
Pet:
allOf:
- $ref: '#/definitions/Pet-Summary'
type: object
properties:
eye-color:
type: string
example: hazel
Pet-Summary:
type: object
properties:
name:
type: string
example: doggie
task generateServerStub {
doLast {
def config = new CodegenConfigurator()
config.setInputSpec(sourceFile)
config.setOutputDir("$projectDir")
config.setLang('spring')
config.setAdditionalProperties([
'interfaceOnly': 'true',
'useOptional' : 'true',
'apiPackage' : 'com.test.api',
'modelPackage' : 'com.test.model',
'dateLibrary' : 'java8',
'sourceFolder' : swaggerOutputDir,
'useTags' : 'true'
])
config.setTypeMappings(['PetSummary': 'AnotherPetSummary'])
new DefaultGenerator().opts(config.toClientOptInput()).generate()
}
Command line used for generation
gradlew generateServerStub
Steps to reproduce
- Create your this groovy task
- Create api.yml in src/main/resources in a project directory
- Run gradlew generateServerStub
Related issues/PRs
Suggest a fix/enhancement
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 CodegenConfigurator type mappings and the DefaultGenerator path used by the Spring generator for allOf models. Reproduce the issue with the supplied Swagger declaration and Gradle task, then verify that the mapped PetSummary type is also used for generated inheritance and that the generated Java code compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java, openapi
- 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