Skip to content

Commit

Permalink
Merge pull request #2 from ktjn/master
Browse files Browse the repository at this point in the history
fix testcases
  • Loading branch information
justusth committed Mar 3, 2016
2 parents dd36ef7 + cb6a71a commit d89deba
Show file tree
Hide file tree
Showing 44 changed files with 1,189 additions and 802 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Check out [Swagger-Spec](https://github.com/OAI/OpenAPI-Specification) for addit
- [Ruby Sinatra](#ruby-sinatra)
- [Scala Scalatra](#scala-scalatra)
- [Java JAX-RS (Java JAX-RS (Jersey v1.18)](#java-jax-rs-jersey-v118)
- [Java JAX-RS (Apache CXF 3)](#java-jax-rs-apache-cxf-3)
- [Java JAX-RS (Apache CXF 2 / 3)](#java-jax-rs-apache-cxf-2--3)
- [Java Spring MVC](#java-spring-mvc)
- [Haskell Servant](#haskell-servant)
- [ASP.NET 5 Web API](#aspnet-5-web-api)
Expand Down Expand Up @@ -619,7 +619,7 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-o samples/server/petstore/jaxrs-jersey
```

### Java JAX-RS (Apache CXF 3)
### Java JAX-RS (Apache CXF 2 / 3)

```
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
Expand All @@ -628,6 +628,23 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-o samples/server/petstore/jaxrs-cxf
```

This Codegen only generate a minimalist server stub. You must add the CXF dependency to your classpath (eg: with Maven)
If you are using CXF v2.x, you must provided a custom ```ResourceComparator``` class. This class will help CXF to choose the good resource interface for mapping an incomming request. The default behavior of CXF v2.x is not correct when many resources interface have the same global path.
See: See http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Customselectionbetweenmultipleresources

You can found this class here: https://github.com/hiveship/CXF2-resource-comparator/blob/master/src/main/java/CXFInterfaceComparator.java
TODO: This class could be directly generated by the Codegen.

You must register this class into your JAX-RS configuration file:
```xml
<jaxrs:resourceComparator>
<bean class="your.package.CXFInterfaceComparator"/>
</jaxrs:resourceComparator>
```

This is no longer necessary if you are using CXF >=v3.x


### Java Spring MVC

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public String toApiVarName(String name) {
}

/**
* Return the capitalized file name of the model test
* Return the capitalized file name of the model
*
* @param name the model name
* @return the file name of the model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
package io.swagger.codegen.languages;

import java.io.File;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.CodegenProperty;
import io.swagger.models.Operation;

public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
{
{
public JavaCXFServerCodegen()
{
super();

supportsInheritance = true;
sourceFolder = "src/gen/java";
invokerPackage = "io.swagger.api";
artifactId = "swagger-jaxrs-server";
Expand All @@ -28,6 +31,11 @@ public JavaCXFServerCodegen()

additionalProperties.put("title", title);

typeMapping.put("date", "LocalDate");
typeMapping.put("DateTime", "javax.xml.datatype.XMLGregorianCalendar"); // Map DateTime fields to Java standart class 'XMLGregorianCalendar'

importMapping.put("LocalDate", "org.joda.time.LocalDate");

super.embeddedTemplateDir = templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "cxf";

for ( int i = 0; i < cliOptions.size(); i++ ) {
Expand All @@ -36,36 +44,55 @@ public JavaCXFServerCodegen()
break;
}
}

cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC));

CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
library.setDefault(DEFAULT_LIBRARY);

Map<String, String> supportedLibraries = new LinkedHashMap<String,String>();

supportedLibraries.put(DEFAULT_LIBRARY, "CXF");
library.setEnum(supportedLibraries);

cliOptions.add(library);
cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC));
cliOptions.add(new CliOption("title", "a title describing the application"));
}

@Override
public void processOpts()
{
super.processOpts();
sourceFolder = "gen" + File.separator + "java";

modelTemplateFiles.clear();
modelTemplateFiles.put("entityModel.mustache", ".java");

supportingFiles.clear();
supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
//TODO
//final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");
//supportingFiles.add(new SupportingFile("CXF2InterfaceComparator.mustache", invokerFolder, "CXF2InterfaceComparator.java"));
}

@Override
public String getName()
{
return "jaxrs-cxf";
}


@Override
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
super.addOperationToGroup(tag, resourcePath, operation, co, operations);
co.subresourceOperation = !co.path.isEmpty();
}


@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
super.postProcessModelProperty(model, property);
model.imports.remove("ApiModelProperty");
model.imports.remove("ApiModel");
model.imports.remove("JsonSerialize");
model.imports.remove("ToStringSerializer");
model.imports.remove("JsonValue");
model.imports.remove("JsonProperty");
}

@Override
public String getHelp()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import java.util.*;

public class JavaInflectorServerCodegen extends JavaClientCodegen implements CodegenConfig {
public class JavaInflectorServerCodegen extends JavaClientCodegen {

private static final Logger LOGGER = LoggerFactory.getLogger(JavaInflectorServerCodegen.class);

Expand Down
Loading

0 comments on commit d89deba

Please sign in to comment.