swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.01k stars 6.03k forks source link

Provide capability to generate server JAX-RS interfaces and model without project #2413

Closed kkrauth closed 8 years ago

kkrauth commented 8 years ago

Generating an entire server (provider) project goes too far when lots of applications only require a list of JAX-RS interfaces and a model so that they can expose services according to a contract defined in the swagger file. There should be a server template that only generates interfaces and a model.

fehguy commented 8 years ago

Hi, we can't possibly support every configuration for a server that people want. So my suggestion is that you create your own templates to do what you want, since that's a supported way to use codegen.

who commented 8 years ago

@kkrauth

Have you tried the Jaxrs CxF generator?

https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf

You can experiment with this by going to http://editor.swagger.io/#/ , open the "Generate Server" menu, and click "Jaxrs CxF".

It only generates resource interfaces and POJO models. No pom.xml, etc.

who commented 8 years ago

@kkrauth

Here's how to play around with it from the command line:

mkdir /tmp/jaxrs-cxf;
cd /tmp/jaxrs-cxf;
mvn -q org.apache.maven.plugins:maven-dependency-plugin:2.8:get -DrepoUrl=https://oss.sonatype.org/content/repositories/snapshots -Dartifact=io.swagger:swagger-codegen-cli:2.1.6-SNAPSHOT -Ddest=swagger-codegen-cli.jar;
java -jar swagger-codegen-cli.jar generate -l jaxrs-cxf -i http://petstore.swagger.io/v2/swagger.json -o output;

Result of above:

output/
└── gen
    └── java
        └── io
            └── swagger
                ├── api
                │   ├── PetApi.java
                │   ├── StoreApi.java
                │   └── UserApi.java
                └── model
                    ├── ApiResponse.java
                    ├── Category.java
                    ├── Order.java
                    ├── Pet.java
                    ├── Tag.java
                    └── User.java
kkrauth commented 8 years ago

@who That looks perfect! Glad to see it's coming in the new version, I'll play around with it. Thanks.

jasusy commented 7 years ago

@who maybe because i am using newer version, it is generated pom.xml and apiImpl LOL And some api description is not generated.

But it is good though, AS it is generating interface instead of class.