Swagger-Codegen is creating wrong import for domain models
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
Research direction
Start in io.swagger.codegen.languages.DefaultCodegenConfig.java, specifically getSchemaType, and compare its handling of #/definitions/ references with the generated Pagination.java import. Reproduce the supplied Pagination and PageLink models, then verify that the generated import uses PageLink rather than DefinitionsPageLink and that the Java output compiles.
Written by the indexing model from the issue text.
Description
Description:
Swagger codegen is creating wrong import statements in java model class for domain models which results in compile errors.
Swagger-codegen version
3.0.0-rc1
Created following domain models
##Pagination Data models
Pagination:
type: object
description: "Pagination Metada which is used to communicate pagination related fields between consumer and API implementation"
properties:
correlationid:
type: string
maxLength: 50
description: "Used to identify the record cache if the pagination logic uses a server side cache."
example: "BLUSRLIST_101"
pageSize:
type: integer
default: 10
description: "Number of records to be returned in a single page. API will use default value if this is not supplied"
example: 10
totalRecords:
type: integer
readOnly: true
description: "Total number of records. This can be used by the consumer to decide the page size."
example: 100
pageNumber:
type: integer
readOnly: true
description: "Page number of the current records."
example: 1
lastPageNumber:
type: integer
readOnly: true
description: "Page number of the last page based on total records."
example: 10
startIndex:
type: string
readOnly: true
description: "Start index/ID of records in the current page. This is the start cursor of the record set representing a page.This can be continutation token to fetch the previous page."
example: "u1001"
endIndex:
type: string
readOnly: true
description: "End index/ID of records in the current page.This is the end cursor of the record set representing a page. This can be continutation token to fetch the next page."
example: "u1010"
links:
type: array
description: "Page links for previous, next, first and last pages"
items:
$ref: "#/definitions/PageLink"
PageLink:
type: object
description: "Represents first, last, previous and next page links in a pagination context."
properties:
next:
type: string
maxLength: 150
description: "Represents the next page link"
prev:
type: string
maxLength: 150
description: "Represents the previous page link"
first:
type: string
maxLength: 150
description: "Represents the first page link"
last:
type: string
maxLength: 150
description: "Represents the last page link"
When we generate code in Pagination.java file it add DefinitionsPageLink this should be only PageLink.
package io.swagger.rest.model.v1;
import io.swagger.rest.model.v1.DefinitionsPageLink;
import io.swagger.annotations.ApiModel;
import java.util.ArrayList;
import java.util.List;
Suggest a fix/enhancement
Need to handle following condition in getSchemaType method of
io.swagger.codegen.languages.DefaultCodegenConfig.java of swagger-codegen-generators-1.0.0-rc1.jar
if(datatype.indexOf("#/definitions/") == 0) {
datatype = datatype.substring("#/definitions/".length());
return datatype;
}
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
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.
More from swagger-api/swagger-codegen
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
swagger-api/swagger-codegen#12755 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
swagger-api/swagger-codegen#12445 ·
-
security vulnerability
Difficulty 1/5 Under an hour Newbie friendliness 62/100
swagger-api/swagger-codegen#11942 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
swagger-api/swagger-codegen#11812 · 1 reaction ·
-
security vulnerability
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
swagger-api/swagger-codegen#11594 ·
All issues in swagger-api/swagger-codegen
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
newrelic-experimental/preflight#793 · 1 comment ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
babalae/bettergi-scripts-list#3674 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
caddyserver/caddy#8046 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zilliztech/memsearch#759 ·
-
comp/cron P2 sweeper:risk-automation type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NousResearch/hermes-agent#117792 · 1 comment ·