Hi Sergey, Thanks for the clarification, make perfect sense.
Cheers ------------- Freeman(Yue) Fang Red Hat, Inc. FuseSource is now part of Red Hat Web: http://fusesource.com | http://www.redhat.com/ Twitter: freemanfang Blog: http://freemanfang.blogspot.com http://blog.sina.com.cn/u/1473905042 weibo: @Freeman小屋 On 2013-11-11, at 下午6:01, Sergey Beryozkin wrote: > Hi Freeman > > Thanks for taking care of it. > Let me clarify why I moved the WADL related code to rt/rs/descriptions. > > First, I wanted to make the jaxrs module smaller, and also 'react' to the > fact that a WADL auto-generation is not an essential part of the clients > consuming the endpoints, so a minor performance gain can be achieved without > it (i.e, the WADL filter won't be checked by default now). > WADL would be IMHO the closest to the 'core' doc option for JAX-RS endpoints > because it was created by one of JAX-RS 1.0 authors. So we could not replace > with Swagger in the core frontend :-). > > However we can now continue enhancing rt/rs/descriptions with more code > supporting different doc styles/approaches, in this case we now have a > Swagger feature, and going forward we can think of doing RAML (Dan point to > it), JSON home, and RestDocs, etc. so the users will be spoiled for choice :-) > > Though I'd only expect the WADL code be a non-optional/implicit dep of > rt/rs/descriptions. > > Cheers, Sergey > > > On 11/11/13 05:31, Freeman Fang wrote: >> Hi Sergey, >> >> Done. >> >> Move SwaggerFeature into rt/rs/description module on trunk and remove >> SwaggerFeature from 2.6.x branch. >> >> Cheers >> ------------- >> Freeman(Yue) Fang >> >> Red Hat, Inc. >> FuseSource is now part of Red Hat >> Web: http://fusesource.com | http://www.redhat.com/ >> Twitter: freemanfang >> Blog: http://freemanfang.blogspot.com >> http://blog.sina.com.cn/u/1473905042 >> weibo: @Freeman小屋 >> >> >> >> On 2013-11-8, at 下午7:49, Sergey Beryozkin wrote: >> >>> Well, it is a rather light weight contribution, so I guess if you keep the >>> dependency optional as Dan also suggested then yes, may be it can go >>> to 2.7.x, but I'd think twice before putting it into what is likely going >>> be to be the last CXF 2.6.x release, it is a new feature, not a bug fix. >>> For the trunk - please move it to the other module >>> >>> Thanks, Sergey >>> >>> >>> >>> On 08/11/13 11:39, Sergey Beryozkin wrote: >>>> I'm sorry, really not sure how I got my message truncated >>>> >>>> Yes, please move it rt/rs/description - this is now where WADL related >>>> code lives, I'm fine with Swagger code being there too >>>> >>>> Sergey >>>> >>>> On 08/11/13 11:32, Sergey Beryozkin wrote: >>>>> Hi Freeman >>>>> >>>>> While I appreciate yout effort I'm -1 on this commit. >>>>> Here is why: >>>>> >>>>> - we've worked hard on minimizing cxf rt frontend jaxrs and in one ho >>>>> you add a Swagger related code without even discussing it. >>>>> >>>>> Please revert your commits. >>>>> >>>>> IMHO, it may go as an *optional* dependency to rt/rs/description module >>>>> which is where it should stay, on the trunk only. I honestly do not want >>>>> >>>>> >>>>> >>>>> >>>>> On 08/11/13 03:30, [email protected] wrote: >>>>>> Author: ffang >>>>>> Date: Fri Nov 8 03:30:41 2013 >>>>>> New Revision: 1539911 >>>>>> >>>>>> URL: http://svn.apache.org/r1539911 >>>>>> Log: >>>>>> [CXF-5379]introduce cxf swagger feature >>>>>> >>>>>> Added: >>>>>> >>>>>> cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/swagger/ >>>>>> >>>>>> cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerFeature.java >>>>>> >>>>>> >>>>>> Modified: >>>>>> cxf/trunk/parent/pom.xml >>>>>> cxf/trunk/rt/frontend/jaxrs/pom.xml >>>>>> >>>>>> cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java >>>>>> >>>>>> >>>>>> >>>>>> Modified: cxf/trunk/parent/pom.xml >>>>>> URL: >>>>>> http://svn.apache.org/viewvc/cxf/trunk/parent/pom.xml?rev=1539911&r1=1539910&r2=1539911&view=diff >>>>>> >>>>>> >>>>>> ============================================================================== >>>>>> >>>>>> >>>>>> --- cxf/trunk/parent/pom.xml (original) >>>>>> +++ cxf/trunk/parent/pom.xml Fri Nov 8 03:30:41 2013 >>>>>> @@ -149,6 +149,7 @@ >>>>>> <cxf.spring.osgi.version>1.2.1</cxf.spring.osgi.version> >>>>>> >>>>>> <cxf.spring.ldap.version>1.3.1.RELEASE</cxf.spring.ldap.version> >>>>>> <cxf.spring.mock>spring-test</cxf.spring.mock> >>>>>> + <cxf.swagger.version>1.3.0</cxf.swagger.version> >>>>>> <cxf.velocity.version>1.7</cxf.velocity.version> >>>>>> <cxf.woodstox.core.version>4.2.0</cxf.woodstox.core.version> >>>>>> >>>>>> <cxf.woodstox.stax2-api.version>3.1.1</cxf.woodstox.stax2-api.version> >>>>>> @@ -1615,6 +1616,12 @@ >>>>>> <artifactId>msv-core</artifactId> >>>>>> <version>${cxf.msv.version}</version> >>>>>> </dependency> >>>>>> + <dependency> >>>>>> + <groupId>com.wordnik</groupId> >>>>>> + <artifactId>swagger-jaxrs_2.10</artifactId> >>>>>> + <version>${cxf.swagger.version}</version> >>>>>> + </dependency> >>>>>> + >>>>>> </dependencies> >>>>>> </dependencyManagement> >>>>>> >>>>>> >>>>>> Modified: cxf/trunk/rt/frontend/jaxrs/pom.xml >>>>>> URL: >>>>>> http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/pom.xml?rev=1539911&r1=1539910&r2=1539911&view=diff >>>>>> >>>>>> >>>>>> ============================================================================== >>>>>> >>>>>> >>>>>> --- cxf/trunk/rt/frontend/jaxrs/pom.xml (original) >>>>>> +++ cxf/trunk/rt/frontend/jaxrs/pom.xml Fri Nov 8 03:30:41 2013 >>>>>> @@ -36,6 +36,7 @@ >>>>>> >>>>>> javax.servlet*;version="${cxf.osgi.javax.servlet.version}", >>>>>> org.apache.aries*;version="${cxf.aries.version.range}", >>>>>> >>>>>> org.springframework*;resolution:="optional";version="${cxf.osgi.spring.version}", >>>>>> >>>>>> >>>>>> + >>>>>> com.wordnik.swagger.jaxrs*;resolution:="optional";version="[1.3.0, >>>>>> 1.4.0)", >>>>>> javax.ws.rs.client;version="[2.0,3)", >>>>>> javax.ws.rs*;version="[1.0,3)", >>>>>> </cxf.osgi.import> >>>>>> @@ -158,6 +159,10 @@ >>>>>> </exclusion> >>>>>> </exclusions> >>>>>> </dependency> >>>>>> + <dependency> >>>>>> + <groupId>com.wordnik</groupId> >>>>>> + <artifactId>swagger-jaxrs_2.10</artifactId> >>>>>> + </dependency> >>>>>> </dependencies> >>>>>> >>>>>> >>>>>> >>>>>> Modified: >>>>>> cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java >>>>>> >>>>>> >>>>>> URL: >>>>>> http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java?rev=1539911&r1=1539910&r2=1539911&view=diff >>>>>> >>>>>> >>>>>> ============================================================================== >>>>>> >>>>>> >>>>>> --- >>>>>> cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java >>>>>> >>>>>> (original) >>>>>> +++ >>>>>> cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java >>>>>> >>>>>> Fri Nov 8 03:30:41 2013 >>>>>> @@ -110,6 +110,7 @@ public class AbstractJAXRSFactoryBean ex >>>>>> super.setBus(bus); >>>>>> checkBindingFactory(bus); >>>>>> serviceFactory.setBus(bus); >>>>>> + bus.setProperty(JAXRSServiceFactoryBean.class.getName(), >>>>>> serviceFactory); >>>>>> } >>>>>> >>>>>> /* >>>>>> @@ -204,6 +205,7 @@ public class AbstractJAXRSFactoryBean ex >>>>>> */ >>>>>> public void setServiceFactory(JAXRSServiceFactoryBean >>>>>> serviceFactory) { >>>>>> this.serviceFactory = serviceFactory; >>>>>> + getBus().setProperty(JAXRSServiceFactoryBean.class.getName(), >>>>>> serviceFactory); >>>>>> } >>>>>> >>>>>> protected Endpoint createEndpoint() throws BusException, >>>>>> EndpointException { >>>>>> >>>>>> Added: >>>>>> cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerFeature.java >>>>>> >>>>>> >>>>>> URL: >>>>>> http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerFeature.java?rev=1539911&view=auto >>>>>> >>>>>> >>>>>> ============================================================================== >>>>>> >>>>>> >>>>>> --- >>>>>> cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerFeature.java >>>>>> >>>>>> (added) >>>>>> +++ >>>>>> cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerFeature.java >>>>>> >>>>>> Fri Nov 8 03:30:41 2013 >>>>>> @@ -0,0 +1,142 @@ >>>>>> +/** >>>>>> + * Licensed to the Apache Software Foundation (ASF) under one >>>>>> + * or more contributor license agreements. See the NOTICE file >>>>>> + * distributed with this work for additional information >>>>>> + * regarding copyright ownership. The ASF licenses this file >>>>>> + * to you under the Apache License, Version 2.0 (the >>>>>> + * "License"); you may not use this file except in compliance >>>>>> + * with the License. You may obtain a copy of the License at >>>>>> + * >>>>>> + * http://www.apache.org/licenses/LICENSE-2.0 >>>>>> + * >>>>>> + * Unless required by applicable law or agreed to in writing, >>>>>> + * software distributed under the License is distributed on an >>>>>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY >>>>>> + * KIND, either express or implied. See the License for the >>>>>> + * specific language governing permissions and limitations >>>>>> + * under the License. >>>>>> + */ >>>>>> +package org.apache.cxf.jaxrs.swagger; >>>>>> + >>>>>> +import java.util.ArrayList; >>>>>> +import java.util.List; >>>>>> + >>>>>> +import org.apache.cxf.Bus; >>>>>> +import org.apache.cxf.endpoint.Server; >>>>>> +import org.apache.cxf.feature.AbstractFeature; >>>>>> +import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean; >>>>>> +import org.apache.cxf.jaxrs.model.AbstractResourceInfo; >>>>>> +import org.apache.cxf.jaxrs.provider.ProviderFactory; >>>>>> + >>>>>> +public class SwaggerFeature extends AbstractFeature { >>>>>> + >>>>>> + private String resourcePackage; >>>>>> + private String version = "1.0.0"; >>>>>> + private String basePath; >>>>>> + private String title = "Rest sample app"; >>>>>> + private String description = "This is a app."; >>>>>> + private String contact = "[email protected]"; >>>>>> + private String license = "Apache 2.0 License"; >>>>>> + private String licenseUrl = >>>>>> "http://www.apache.org/licenses/LICENSE-2.0.html"; >>>>>> + private boolean scan = true; >>>>>> + @Override >>>>>> + public void initialize(Server server, Bus bus) { >>>>>> + List<Object> serviceBeans = new ArrayList<Object>(); >>>>>> + serviceBeans.add(new >>>>>> com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON()); >>>>>> + calulateDefaultResourcePackage(bus); >>>>>> + calulateDefaultBasePath(server); >>>>>> + >>>>>> ((JAXRSServiceFactoryBean)bus.getProperty(JAXRSServiceFactoryBean.class.getName())). >>>>>> >>>>>> >>>>>> + setResourceClassesFromBeans(serviceBeans); >>>>>> + List<Object> providers = new ArrayList<Object>(); >>>>>> + providers.add(new >>>>>> com.wordnik.swagger.jaxrs.listing.ResourceListingProvider()); >>>>>> + providers.add(new >>>>>> com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider()); >>>>>> + >>>>>> ((ProviderFactory)bus.getProperty(ProviderFactory.class.getName())).setUserProviders(providers); >>>>>> >>>>>> >>>>>> + com.wordnik.swagger.jaxrs.config.BeanConfig beanConfig = new >>>>>> com.wordnik.swagger.jaxrs.config.BeanConfig(); >>>>>> + beanConfig.setResourcePackage(getResourcePackage()); >>>>>> + beanConfig.setVersion(getVersion()); >>>>>> + beanConfig.setBasePath(getBasePath()); >>>>>> + beanConfig.setTitle(getTitle()); >>>>>> + beanConfig.setDescription(getDescription()); >>>>>> + beanConfig.setContact(getContact()); >>>>>> + beanConfig.setLicense(getLicense()); >>>>>> + beanConfig.setLicenseUrl(getLicenseUrl()); >>>>>> + beanConfig.setScan(isScan()); >>>>>> + initializeProvider(server.getEndpoint(), bus); >>>>>> + } >>>>>> + private void calulateDefaultResourcePackage(Bus bus) { >>>>>> + JAXRSServiceFactoryBean serviceFactoryBean = >>>>>> + >>>>>> (JAXRSServiceFactoryBean)bus.getProperty(JAXRSServiceFactoryBean.class.getName()); >>>>>> >>>>>> >>>>>> + AbstractResourceInfo resourceInfo = >>>>>> serviceFactoryBean.getClassResourceInfo().get(0); >>>>>> + >>>>>> + if ((resourceInfo != null) >>>>>> + && (getResourcePackage() == null || >>>>>> getResourcePackage().length() == 0)) { >>>>>> + >>>>>> setResourcePackage(resourceInfo.getResourceClass().getPackage().getName()); >>>>>> >>>>>> >>>>>> + } >>>>>> + } >>>>>> + >>>>>> + private void calulateDefaultBasePath(Server server) { >>>>>> + String address = >>>>>> server.getEndpoint().getEndpointInfo().getAddress(); >>>>>> + if (getBasePath() == null || getBasePath().length() == 0) { >>>>>> + if (address.startsWith("http")) { >>>>>> + setBasePath(address + "/api-docs"); >>>>>> + } else { >>>>>> + setBasePath("http://localhost:8181/cxf" + address + >>>>>> "/api-docs"); >>>>>> + } >>>>>> + } >>>>>> + } >>>>>> + public String getResourcePackage() { >>>>>> + return resourcePackage; >>>>>> + } >>>>>> + public void setResourcePackage(String resourcePackage) { >>>>>> + this.resourcePackage = resourcePackage; >>>>>> + } >>>>>> + public String getVersion() { >>>>>> + return version; >>>>>> + } >>>>>> + public void setVersion(String version) { >>>>>> + this.version = version; >>>>>> + } >>>>>> + public String getBasePath() { >>>>>> + return basePath; >>>>>> + } >>>>>> + public void setBasePath(String basePath) { >>>>>> + this.basePath = basePath; >>>>>> + } >>>>>> + public String getTitle() { >>>>>> + return title; >>>>>> + } >>>>>> + public void setTitle(String title) { >>>>>> + this.title = title; >>>>>> + } >>>>>> + public String getDescription() { >>>>>> + return description; >>>>>> + } >>>>>> + public void setDescription(String description) { >>>>>> + this.description = description; >>>>>> + } >>>>>> + public String getContact() { >>>>>> + return contact; >>>>>> + } >>>>>> + public void setContact(String contact) { >>>>>> + this.contact = contact; >>>>>> + } >>>>>> + public String getLicense() { >>>>>> + return license; >>>>>> + } >>>>>> + public void setLicense(String license) { >>>>>> + this.license = license; >>>>>> + } >>>>>> + public String getLicenseUrl() { >>>>>> + return licenseUrl; >>>>>> + } >>>>>> + public void setLicenseUrl(String licenseUrl) { >>>>>> + this.licenseUrl = licenseUrl; >>>>>> + } >>>>>> + public boolean isScan() { >>>>>> + return scan; >>>>>> + } >>>>>> + public void setScan(boolean scan) { >>>>>> + this.scan = scan; >>>>>> + } >>>>>> + >>>>>> +} >>>>>> >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >>> -- >>> Sergey Beryozkin >>> >>> Talend Community Coders >>> http://coders.talend.com/ >>> >>> Blog: http://sberyozkin.blogspot.com >> >> > > > -- > Sergey Beryozkin > > Talend Community Coders > http://coders.talend.com/ > > Blog: http://sberyozkin.blogspot.com
