1. I use this command to generate the following typescript code
java -jar swagger-codegen-cli-2.2.1.jar generate -i http://127.0.0.1:8080/wx_sdk_api.yaml -l typescript-fetch -o output/typescript-fetch-client -c config.json
the result is:
export interface CardQrcodeCreateBody {
}
2 but the code generated by http://editor.swagger.io/#/ is different from the code above,
the following is the code generated by http://editor.swagger.io/#/
export interface CardQrcodeCreateBody extends QrcodeCreatSingleCard {
/**
* QR_MULTIPLE_CARD.
*/
"actionName"?: number;
/**
* expire_seconds.
*/
"expireSeconds"?: number;
"actionInfo"?: QrcodeCreatMultipleActionInfo;
}
3
typescript-node has the same issue.
4
Question: the code generated by online swagger editor is the result I expect, how to use swagger-codegen-cli-2.2.1.jar to generate the code which is same with the code generated by online editor?
the version is swagger-codegen-cli-2.2.1.jar
the version of online swagger editor is 2.10.3
java -jar swagger-codegen-cli-2.2.1.jar generate -i http://127.0.0.1:8080/wx_sdk_api.yaml -l typescript-fetch -o output/typescript-fetch-client -c config.json
@fish2016 editor.swagger.io is using generator.swagger.io to generate code and generator.swagger.io should be using the latest stable version, which is 2.2.1.
Can you share wx_sdk_api.yaml so that we can try to reproduce the issue?
To enjoy the latest enhancement and bug fixes, we would suggest you to build the latest master.
I am seeing the same thing but also with Java and Spring generators. Specifically with model classes. The code generated from generator.swagger.io generates polymorphic classes when using allOf where code generated from the CLI do not extend any base class. I have a schema definition like so:
swagger: '2.0'
# This is your document metadata
info:
version: "0.0.0"
title: Test
# Describe your paths here
paths:
/base:
get:
responses:
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
definitions:
Error:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
fields:
type: string
Base:
type: object
properties:
id:
type: string
label:
type: string
description:
type: string
required:
- id
Event:
allOf:
- $ref: '#/definitions/Base'
- type: object
properties:
duration:
type: integer
format: int32
durationUnits:
type: string
The CLI will generate the following
public class Base { ...
public class Event { ...
Where generator.swagger.io will generate something like this:
public class Base { ...
public class Event extends Base { ...
I'd love to know what version generates polymorphic model classes?
Having same issue here, my allOfcomposition doesn't work with swagger-cogeden 2.2.1 for typescript-node.
@fish2016 @damnhandy Did you find any workaround?
Tried with latest code in master (2.2.2-SNAPSHOT) and works.
With Java, the CLI works when I added a discriminator, which is probably the correct behavior. But for some reason, generator.swagger.io does not need a discriminator value to generate polymorphic classes. That's probably incorrect behavior.
I noticed that too, but in my case I don't have/need discriminator in the swagger file (that is maintained by a different team), I don't know if it is required.
With latest code in master, the behavior is the expected one, with or without discriminator, it works (just like editor.swagger.io), maybe any swagger member can clarify us.
I had the same results with 2.2.1,2.2.2-SNAPSHOT and 2.3.0-SNAPSHOT, the last two being built from source. All three get the same results and only generated subclasses when a discriminator was present. I haven't looked at the servlet code that drives generator.swagger.io yet, but there's either a very different version being used, or the servlet is doing something different than the CLI.
@damnhandy when you built the JAR locally, did you run mvn clean package?
I did.
@damnhandy we don't deploy the snapshots on every build to the online generator. I can see about updating it
@damnhandy I did confirm that the online generator uses the v2.2.1 release version. So the changes in the 2.2.2-SNAPSHOT would not be reflected there.
There have been a number of fixes in master, so I've deployed it to the online service.