If I define a model definition as just an array, then the created model ts file says "extends models.Array" instead of just "extends Array"
swagger: "2.0"
host: localhost
schemes:
- http
consumes:
- application/json
produces:
- application/json
paths:
/test:
get:
tags:
- test
operationId: test
description: test
responses:
"200":
description: Success
schema:
$ref: "#/definitions/TestArray"
definitions:
TestArray:
type: array
items:
$ref: "#/definitions/TestItem"
TestItem:
properties:
val:
type: string
The invalid generated model for TestArray is then:
export interface TestArray extends models.Array<models.TestItem> {
}
whereas it should just be as follows (without "models."):
export interface TestArray extends Array<models.TestItem> {
}
java -jar swagger-codegen-cli-2.2.1.jar generate -i ./swagger.yaml -l typescript-angular2 --additional-properties modelPropertyNaming=original
For the time-being, I have my codegen run within a script that uses sed to replace the values after generation:
sed -i '' 's/extends models\.Array/extends Array/g' *
@Emmpa To return an array of model, can you defined as follows instead? https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml#L114
I could, but that seems like a work-around, when I believe the example provided is still valid swagger spec. And while the example is very simple, there are cases where I use an array model multiple times, so I would rather avoid code duplication. As I said though, the sed work-around works for now too.
I'm noticing that this may be related to another problem where I have simple models defined without 'properties'. The following two models are not generated (but are referenced in numerous places):
UnixTime:
type: integer
description: UNIX time stamp (num seconds since Jan 1, 1970)
BoolInt:
type: integer
description: DB storage of boolean
minimum: 0
maximum: 1
Confirm: model typed as array become interface with model prefix:
SomeArrayLikeDefinition:
type: array
items:
$ref: '#/definitions/SomeDefinition'
produces
export interface SomeArrayLikeDefinition extends models.Array<models.SomeDefinition> {
}
Am I right that models.Array<models.SomeDefinition> should be
Array<models.SomeDefinition>?
I had the same issue and worked around it by using a custom generator to replace the first line of modelGeneric.mustache from:
export interface {{classname}} {{#parent}}extends models.{{{parent}}} {{/parent}}{
to:
export interface {{classname}} {{#parent}}extends {{#parentModel}}models.{{/parentModel}}{{{parent}}} {{/parent}}{
I believe it should be explicitly fixed in 2.2.2 also. I can make a PR if needed.
Hi, I'm having trouble with this one too. How is the fix going?
Having the same problem as well, would definitely love a fix
Most helpful comment
I could, but that seems like a work-around, when I believe the example provided is still valid swagger spec. And while the example is very simple, there are cases where I use an array model multiple times, so I would rather avoid code duplication. As I said though, the sed work-around works for now too.