From a289a60198aed3c12f473abb4957a71b999b1b5c Mon Sep 17 00:00:00 2001 From: Sean Yang Date: Sat, 30 Nov 2024 12:32:23 +0800 Subject: [PATCH] Refine --- .artifacts | 2 +- LICENSE | 8 + .../common/extension/ExtensionAccessor.java | 8 + .../dubbo/config/nested/RestConfig.java | 28 + .../dubbo-demo-spring-boot-servlet/pom.xml | 7 +- dubbo-distribution/dubbo-all-shaded/pom.xml | 7 +- dubbo-distribution/dubbo-all/pom.xml | 7 +- dubbo-distribution/dubbo-bom/pom.xml | 2 +- dubbo-distribution/dubbo-core-spi/pom.xml | 3 + dubbo-metadata/dubbo-metadata-api/pom.xml | 13 + .../DubboMetadataServiceV2Triple.java | 105 + .../apache/dubbo/metadata/MetadataInfoV2.java | 204 +- .../metadata/MetadataInfoV2OrBuilder.java | 43 + .../dubbo/metadata/MetadataRequest.java | 102 +- .../metadata/MetadataRequestOrBuilder.java | 9 + .../dubbo/metadata/MetadataServiceV2.java | 17 +- .../metadata/MetadataServiceV2OuterClass.java | 43 +- .../org/apache/dubbo/metadata/OpenAPI.java | 587 ++++++ .../apache/dubbo/metadata/OpenAPIFormat.java | 158 ++ .../dubbo/metadata/OpenAPIOrBuilder.java | 43 + .../apache/dubbo/metadata/OpenAPIRequest.java | 1748 +++++++++++++++++ .../metadata/OpenAPIRequestOrBuilder.java | 228 +++ .../apache/dubbo/metadata/ServiceInfoV2.java | 345 +++- .../metadata/ServiceInfoV2OrBuilder.java | 74 + .../src/main/proto/metadata_service_v2.proto | 59 + .../dubbo/qos/command/impl/GetOpenAPI.java | 95 + .../org.apache.dubbo.qos.api.BaseCommand | 1 + .../qos/command/util/CommandHelperTest.java | 2 + .../jaxrs/JaxrsRequestMappingResolver.java | 11 +- .../pom.xml | 2 +- .../tri/rest/openapi/AbstractContext.java | 0 .../tri/rest/openapi/ConfigFactory.java | 5 - .../protocol/tri/rest/openapi/Constants.java | 0 .../protocol/tri/rest/openapi/Context.java | 0 .../tri/rest/openapi/ContextImpl.java | 0 .../openapi/DefaultOpenAPINamingStrategy.java | 0 .../rest/openapi/DefaultOpenAPIService.java | 14 +- .../tri/rest/openapi/DefinitionEncoder.java | 0 .../tri/rest/openapi/DefinitionFilter.java | 0 .../tri/rest/openapi/DefinitionMerger.java | 9 +- .../tri/rest/openapi/DefinitionResolver.java | 0 .../tri/rest/openapi/ExtensionFactory.java | 0 .../rpc/protocol/tri/rest/openapi/Helper.java | 21 +- .../openapi/OpenAPIDefinitionResolver.java | 0 .../openapi/OpenAPIDocumentPublisher.java | 0 .../tri/rest/openapi/OpenAPIExtension.java | 0 .../tri/rest/openapi/OpenAPIFilter.java | 0 .../rest/openapi/OpenAPINamingStrategy.java | 0 .../rest/openapi/OpenAPIRequestHandler.java | 0 .../rest/openapi/OpenAPISchemaPredicate.java | 0 .../rest/openapi/OpenAPISchemaResolver.java | 0 .../tri/rest/openapi/PrimitiveSchema.java | 0 .../tri/rest/openapi/ProtoEncoder.java | 0 .../tri/rest/openapi/SchemaResolver.java | 0 .../tri/rest/openapi/model/ApiResponse.java | 0 .../tri/rest/openapi/model/Components.java | 0 .../tri/rest/openapi/model/Contact.java | 0 .../tri/rest/openapi/model/Discriminator.java | 0 .../tri/rest/openapi/model/Encoding.java | 0 .../tri/rest/openapi/model/Example.java | 0 .../tri/rest/openapi/model/ExternalDocs.java | 0 .../tri/rest/openapi/model/Header.java | 0 .../protocol/tri/rest/openapi/model/Info.java | 0 .../tri/rest/openapi/model/License.java | 0 .../tri/rest/openapi/model/MediaType.java | 0 .../protocol/tri/rest/openapi/model/Node.java | 0 .../tri/rest/openapi/model/OAuthFlow.java | 0 .../tri/rest/openapi/model/OAuthFlows.java | 0 .../tri/rest/openapi/model/OpenAPI.java | 0 .../tri/rest/openapi/model/Operation.java | 0 .../tri/rest/openapi/model/Parameter.java | 0 .../tri/rest/openapi/model/PathItem.java | 0 .../tri/rest/openapi/model/RequestBody.java | 0 .../tri/rest/openapi/model/Schema.java | 0 .../openapi/model/SecurityRequirement.java | 0 .../rest/openapi/model/SecurityScheme.java | 0 .../tri/rest/openapi/model/Server.java | 0 .../rest/openapi/model/ServerVariable.java | 0 .../protocol/tri/rest/openapi/model/Tag.java | 0 .../protocol/tri/rest/openapi/model/XML.java | 0 .../basic/BasicOpenAPIDefinitionResolver.java | 0 .../JavadocOpenAPIDefinitionResolver.java | 0 .../support/swagger/RedocRequestHandler.java | 1 + .../SwaggerOpenAPIDefinitionResolver.java | 0 .../swagger/SwaggerUIRequestHandler.java | 9 +- .../rest/support/swagger/WebjarHelper.java | 0 ....dubbo.remoting.http12.rest.OpenAPIService | 1 + ...protocol.tri.rest.openapi.OpenAPIExtension | 2 + .../META-INF/resources/redoc/index.html | 1 + .../META-INF/resources/swagger-ui/index.html | 1 + .../SpringMvcRequestMappingResolver.java | 11 +- .../tri/rest/support/swagger/Helper.java | 44 - .../metadata/MetadataServiceDelegation.java | 15 +- .../metadata/MetadataServiceDelegationV2.java | 41 +- dubbo-remoting/dubbo-remoting-http12/pom.xml | 10 +- .../remoting/http12/rest}/OpenAPIService.java | 10 +- .../java/org/apache/dubbo/rpc/Constants.java | 2 + dubbo-rpc/dubbo-rpc-triple/pom.xml | 46 +- .../rpc/protocol/tri/TripleProtocol.java | 19 +- .../rpc/protocol/tri/rest/cors/CorsUtils.java | 17 +- .../DefaultRequestMappingRegistry.java | 14 +- .../rest/mapping/RequestMappingResolver.java | 3 + .../basic/BasicRequestMappingResolver.java | 22 +- ...protocol.tri.rest.openapi.OpenAPIExtension | 2 - .../event/DubboOpenAPIExportListener.java | 8 +- dubbo-test/dubbo-dependencies-all/pom.xml | 2 +- pom.xml | 2 +- 107 files changed, 4106 insertions(+), 187 deletions(-) create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPI.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIFormat.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIOrBuilder.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIRequest.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIRequestOrBuilder.java create mode 100644 dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/GetOpenAPI.java rename dubbo-plugin/{dubbo-rest-swagger => dubbo-rest-openapi}/pom.xml (98%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/AbstractContext.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ConfigFactory.java (96%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Constants.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Context.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ContextImpl.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefaultOpenAPINamingStrategy.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefaultOpenAPIService.java (97%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionEncoder.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionFilter.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionMerger.java (98%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionResolver.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ExtensionFactory.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Helper.java (93%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIDefinitionResolver.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIDocumentPublisher.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIExtension.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIFilter.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPINamingStrategy.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIRequestHandler.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPISchemaPredicate.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPISchemaResolver.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/PrimitiveSchema.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ProtoEncoder.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/SchemaResolver.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ApiResponse.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Components.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Contact.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Discriminator.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Encoding.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Example.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ExternalDocs.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Header.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Info.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/License.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/MediaType.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Node.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OAuthFlow.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OAuthFlows.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OpenAPI.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Operation.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Parameter.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/PathItem.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/RequestBody.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Schema.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/SecurityRequirement.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/SecurityScheme.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Server.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ServerVariable.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Tag.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/XML.java (100%) rename {dubbo-rpc/dubbo-rpc-triple => dubbo-plugin/dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/BasicOpenAPIDefinitionResolver.java (100%) rename dubbo-plugin/{dubbo-rest-swagger => dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/JavadocOpenAPIDefinitionResolver.java (100%) rename dubbo-plugin/{dubbo-rest-swagger => dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/RedocRequestHandler.java (98%) rename dubbo-plugin/{dubbo-rest-swagger => dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/SwaggerOpenAPIDefinitionResolver.java (100%) rename dubbo-plugin/{dubbo-rest-swagger => dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/SwaggerUIRequestHandler.java (93%) rename dubbo-plugin/{dubbo-rest-swagger => dubbo-rest-openapi}/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/WebjarHelper.java (100%) create mode 100644 dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.rest.OpenAPIService rename dubbo-plugin/{dubbo-rest-swagger => dubbo-rest-openapi}/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension (66%) rename dubbo-plugin/{dubbo-rest-swagger => dubbo-rest-openapi}/src/main/resources/META-INF/resources/redoc/index.html (84%) rename dubbo-plugin/{dubbo-rest-swagger => dubbo-rest-openapi}/src/main/resources/META-INF/resources/swagger-ui/index.html (93%) delete mode 100644 dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/Helper.java rename {dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi => dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/rest}/OpenAPIService.java (77%) delete mode 100644 dubbo-rpc/dubbo-rpc-triple/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension diff --git a/.artifacts b/.artifacts index 2abca0fd4ef..27974610f1f 100644 --- a/.artifacts +++ b/.artifacts @@ -112,6 +112,6 @@ dubbo-xds dubbo-plugin-loom dubbo-rest-jaxrs dubbo-rest-spring -dubbo-rest-swagger +dubbo-rest-openapi dubbo-triple-servlet dubbo-triple-websocket diff --git a/LICENSE b/LICENSE index b2d3628b89d..3716d3930ed 100644 --- a/LICENSE +++ b/LICENSE @@ -287,3 +287,11 @@ This product contains a modified portion of 'Istio', an open platform to connect under a "Apache License 2.0" license, see https://github.com/istio/api/blob/master/LICENSE: * security/v1alpha1/ca.proto + +For the file dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/resources/swagger-ui/index.html: + +Under a "Apache License 2.0" license, see https://github.com/swagger-api/swagger-ui/blob/master/LICENSE + +For the file dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/resources/redoc/index.html: + +Under a "MIT License" license, see https://github.com/Redocly/redoc/blob/main/LICENSE diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionAccessor.java b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionAccessor.java index 5abade6f709..fcfc023b131 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionAccessor.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionAccessor.java @@ -46,6 +46,14 @@ default T getDefaultExtension(Class type) { return extensionLoader != null ? extensionLoader.getDefaultExtension() : null; } + default T getDefaultExtensionOrNull(Class type) { + ExtensionLoader extensionLoader = getExtensionLoader(type); + if (extensionLoader == null) { + return null; + } + return extensionLoader.getExtension(extensionLoader.getDefaultExtensionName(), true); + } + default List getActivateExtensions(Class type) { ExtensionLoader extensionLoader = getExtensionLoader(type); return extensionLoader != null ? extensionLoader.getActivateExtensions() : Collections.emptyList(); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/RestConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/RestConfig.java index 8f64a3d0157..7cc994413fc 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/RestConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/RestConfig.java @@ -34,6 +34,18 @@ public class RestConfig implements Serializable { public static final boolean DEFAULT_CASE_SENSITIVE_MATCH = true; public static final String DEFAULT_FORMAT_PARAMETER_NAME = "format"; + /** + * Whether to enable rest support + *

The default value is 'true'. + */ + private Boolean enabled; + + /** + * Whether to enable the default mapping '/{interfaceName}/{methodName}'. + *

The default value is 'true'. + */ + private Boolean enableDefaultMapping; + /** * Whether path matching should be match paths with a trailing slash. * If enabled, a method mapped to "/users" also matches to "/users/". @@ -90,6 +102,22 @@ public class RestConfig implements Serializable { */ private Map openapis; + public Boolean getEnabled() { + return enabled; + } + + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } + + public Boolean getEnableDefaultMapping() { + return enableDefaultMapping; + } + + public void setEnableDefaultMapping(Boolean enableDefaultMapping) { + this.enableDefaultMapping = enableDefaultMapping; + } + public Boolean getTrailingSlashMatch() { return trailingSlashMatch; } diff --git a/dubbo-demo/dubbo-demo-spring-boot/dubbo-demo-spring-boot-servlet/pom.xml b/dubbo-demo/dubbo-demo-spring-boot/dubbo-demo-spring-boot-servlet/pom.xml index c9728a77575..08eaf8e01a0 100644 --- a/dubbo-demo/dubbo-demo-spring-boot/dubbo-demo-spring-boot-servlet/pom.xml +++ b/dubbo-demo/dubbo-demo-spring-boot/dubbo-demo-spring-boot-servlet/pom.xml @@ -32,6 +32,11 @@ dubbo-registry-zookeeper ${project.version} + + org.apache.dubbo + dubbo-qos + ${project.version} + org.apache.dubbo dubbo-rpc-triple @@ -54,7 +59,7 @@ org.apache.dubbo - dubbo-rest-swagger + dubbo-rest-openapi ${project.version} diff --git a/dubbo-distribution/dubbo-all-shaded/pom.xml b/dubbo-distribution/dubbo-all-shaded/pom.xml index 4c74741dcf7..993f681c231 100644 --- a/dubbo-distribution/dubbo-all-shaded/pom.xml +++ b/dubbo-distribution/dubbo-all-shaded/pom.xml @@ -278,7 +278,7 @@ org.apache.dubbo - dubbo-rest-swagger + dubbo-rest-openapi ${project.version} compile true @@ -531,7 +531,7 @@ org.apache.dubbo:dubbo-rpc-triple org.apache.dubbo:dubbo-rest-jaxrs org.apache.dubbo:dubbo-rest-spring - org.apache.dubbo:dubbo-rest-swagger + org.apache.dubbo:dubbo-rest-openapi org.apache.dubbo:dubbo-triple-servlet org.apache.dubbo:dubbo-triple-websocket org.apache.dubbo:dubbo-serialization-api @@ -889,6 +889,9 @@ META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.mapping.RequestMappingResolver + + META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.rest.OpenAPIService + META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension diff --git a/dubbo-distribution/dubbo-all/pom.xml b/dubbo-distribution/dubbo-all/pom.xml index f518a387e44..b385f4a9af9 100644 --- a/dubbo-distribution/dubbo-all/pom.xml +++ b/dubbo-distribution/dubbo-all/pom.xml @@ -278,7 +278,7 @@ org.apache.dubbo - dubbo-rest-swagger + dubbo-rest-openapi ${project.version} compile true @@ -530,7 +530,7 @@ org.apache.dubbo:dubbo-rpc-triple org.apache.dubbo:dubbo-rest-jaxrs org.apache.dubbo:dubbo-rest-spring - org.apache.dubbo:dubbo-rest-swagger + org.apache.dubbo:dubbo-rest-openapi org.apache.dubbo:dubbo-triple-servlet org.apache.dubbo:dubbo-triple-websocket org.apache.dubbo:dubbo-serialization-api @@ -887,6 +887,9 @@ META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.mapping.RequestMappingResolver + + META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.rest.OpenAPIService + META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension diff --git a/dubbo-distribution/dubbo-bom/pom.xml b/dubbo-distribution/dubbo-bom/pom.xml index 5003a7c7d45..fd057752bb1 100644 --- a/dubbo-distribution/dubbo-bom/pom.xml +++ b/dubbo-distribution/dubbo-bom/pom.xml @@ -303,7 +303,7 @@ org.apache.dubbo - dubbo-rest-swagger + dubbo-rest-openapi ${project.version} diff --git a/dubbo-distribution/dubbo-core-spi/pom.xml b/dubbo-distribution/dubbo-core-spi/pom.xml index 0c6c789847f..691d35c0c1e 100644 --- a/dubbo-distribution/dubbo-core-spi/pom.xml +++ b/dubbo-distribution/dubbo-core-spi/pom.xml @@ -483,6 +483,9 @@ META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.mapping.RequestMappingResolver + + META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.rest.OpenAPIService + META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension diff --git a/dubbo-metadata/dubbo-metadata-api/pom.xml b/dubbo-metadata/dubbo-metadata-api/pom.xml index 44e01099bd0..abeee99db63 100644 --- a/dubbo-metadata/dubbo-metadata-api/pom.xml +++ b/dubbo-metadata/dubbo-metadata-api/pom.xml @@ -62,6 +62,10 @@ ${project.parent.version} compile + + com.google.protobuf + protobuf-java + org.apache.dubbo @@ -81,4 +85,13 @@ ${project.parent.version} + + + + + + diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DubboMetadataServiceV2Triple.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DubboMetadataServiceV2Triple.java index dd64d86a38e..928583d12dd 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DubboMetadataServiceV2Triple.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DubboMetadataServiceV2Triple.java @@ -62,6 +62,11 @@ public static MetadataServiceV2 newStub(Invoker invoker) { return new MetadataServiceV2Stub((Invoker) invoker); } + /** + *

+     *  Retrieves metadata information.
+     * 
+ */ private static final StubMethodDescriptor getMetadataInfoMethod = new StubMethodDescriptor( "GetMetadataInfo", MetadataRequest.class, @@ -91,10 +96,46 @@ public static MetadataServiceV2 newStub(Invoker invoker) { obj -> ((Message) obj).toByteArray(), MetadataRequest::parseFrom, MetadataInfoV2::parseFrom); + /** + *
+     *  Retrieves OpenAPI.
+     * 
+ */ + private static final StubMethodDescriptor getOpenAPIMethod = new StubMethodDescriptor( + "GetOpenAPI", + OpenAPIRequest.class, + OpenAPI.class, + MethodDescriptor.RpcType.UNARY, + obj -> ((Message) obj).toByteArray(), + obj -> ((Message) obj).toByteArray(), + OpenAPIRequest::parseFrom, + OpenAPI::parseFrom); + + private static final StubMethodDescriptor getOpenAPIAsyncMethod = new StubMethodDescriptor( + "GetOpenAPI", + OpenAPIRequest.class, + CompletableFuture.class, + MethodDescriptor.RpcType.UNARY, + obj -> ((Message) obj).toByteArray(), + obj -> ((Message) obj).toByteArray(), + OpenAPIRequest::parseFrom, + OpenAPI::parseFrom); + + private static final StubMethodDescriptor getOpenAPIProxyAsyncMethod = new StubMethodDescriptor( + "GetOpenAPIAsync", + OpenAPIRequest.class, + OpenAPI.class, + MethodDescriptor.RpcType.UNARY, + obj -> ((Message) obj).toByteArray(), + obj -> ((Message) obj).toByteArray(), + OpenAPIRequest::parseFrom, + OpenAPI::parseFrom); static { serviceDescriptor.addMethod(getMetadataInfoMethod); serviceDescriptor.addMethod(getMetadataInfoProxyAsyncMethod); + serviceDescriptor.addMethod(getOpenAPIMethod); + serviceDescriptor.addMethod(getOpenAPIProxyAsyncMethod); } public static class MetadataServiceV2Stub implements MetadataServiceV2, Destroyable { @@ -109,6 +150,11 @@ public MetadataServiceV2Stub(Invoker invoker) { invoker.destroy(); } + /** + *
+         *  Retrieves metadata information.
+         * 
+ */ @Override public MetadataInfoV2 getMetadataInfo(MetadataRequest request) { return StubInvocationUtil.unaryCall(invoker, getMetadataInfoMethod, request); @@ -118,9 +164,37 @@ public CompletableFuture getMetadataInfoAsync(MetadataRequest re return StubInvocationUtil.unaryCall(invoker, getMetadataInfoAsyncMethod, request); } + /** + *
+         *  Retrieves metadata information.
+         * 
+ */ public void getMetadataInfo(MetadataRequest request, StreamObserver responseObserver) { StubInvocationUtil.unaryCall(invoker, getMetadataInfoMethod, request, responseObserver); } + + /** + *
+         *  Retrieves OpenAPI.
+         * 
+ */ + @Override + public OpenAPI getOpenAPI(OpenAPIRequest request) { + return StubInvocationUtil.unaryCall(invoker, getOpenAPIMethod, request); + } + + public CompletableFuture getOpenAPIAsync(OpenAPIRequest request) { + return StubInvocationUtil.unaryCall(invoker, getOpenAPIAsyncMethod, request); + } + + /** + *
+         *  Retrieves OpenAPI.
+         * 
+ */ + public void getOpenAPI(OpenAPIRequest request, StreamObserver responseObserver) { + StubInvocationUtil.unaryCall(invoker, getOpenAPIMethod, request, responseObserver); + } } public abstract static class MetadataServiceV2ImplBase @@ -146,6 +220,11 @@ public CompletableFuture getMetadataInfoAsync(MetadataRequest re return CompletableFuture.completedFuture(getMetadataInfo(request)); } + @Override + public CompletableFuture getOpenAPIAsync(OpenAPIRequest request) { + return CompletableFuture.completedFuture(getOpenAPI(request)); + } + /** * This server stream type unary method is only used for generated stub to support async unary method. * It will not be called if you are NOT using Dubbo3 generated triple stub and DO NOT implement this method. @@ -161,6 +240,17 @@ public void getMetadataInfo(MetadataRequest request, StreamObserver responseObserver) { + getOpenAPIAsync(request).whenComplete((r, t) -> { + if (t != null) { + responseObserver.onError(t); + } else { + responseObserver.onNext(r); + responseObserver.onCompleted(); + } + }); + } + @Override public final Invoker getInvoker(URL url) { PathResolver pathResolver = url.getOrDefaultFrameworkModel() @@ -174,6 +264,12 @@ public final Invoker getInvoker(URL url) { pathResolver.addNativeStub("/" + JAVA_SERVICE_NAME + "/GetMetadataInfo"); pathResolver.addNativeStub("/" + JAVA_SERVICE_NAME + "/GetMetadataInfoAsync"); + pathResolver.addNativeStub("/" + SERVICE_NAME + "/GetOpenAPI"); + pathResolver.addNativeStub("/" + SERVICE_NAME + "/GetOpenAPIAsync"); + // for compatibility + pathResolver.addNativeStub("/" + JAVA_SERVICE_NAME + "/GetOpenAPI"); + pathResolver.addNativeStub("/" + JAVA_SERVICE_NAME + "/GetOpenAPIAsync"); + BiConsumer> getMetadataInfoFunc = this::getMetadataInfo; handlers.put(getMetadataInfoMethod.getMethodName(), new UnaryStubMethodHandler<>(getMetadataInfoFunc)); BiConsumer> getMetadataInfoAsyncFunc = @@ -181,6 +277,10 @@ public final Invoker getInvoker(URL url) { handlers.put( getMetadataInfoProxyAsyncMethod.getMethodName(), new UnaryStubMethodHandler<>(getMetadataInfoAsyncFunc)); + BiConsumer> getOpenAPIFunc = this::getOpenAPI; + handlers.put(getOpenAPIMethod.getMethodName(), new UnaryStubMethodHandler<>(getOpenAPIFunc)); + BiConsumer> getOpenAPIAsyncFunc = syncToAsync(this::getOpenAPI); + handlers.put(getOpenAPIProxyAsyncMethod.getMethodName(), new UnaryStubMethodHandler<>(getOpenAPIAsyncFunc)); return new StubInvoker<>(this, url, MetadataServiceV2.class, handlers); } @@ -190,6 +290,11 @@ public MetadataInfoV2 getMetadataInfo(MetadataRequest request) { throw unimplementedMethodException(getMetadataInfoMethod); } + @Override + public OpenAPI getOpenAPI(OpenAPIRequest request) { + throw unimplementedMethodException(getOpenAPIMethod); + } + @Override public final ServiceDescriptor getServiceDescriptor() { return serviceDescriptor; diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2.java index 520641396b3..82e375d7881 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2.java @@ -17,13 +17,19 @@ package org.apache.dubbo.metadata; /** + *
+ * Metadata information message.
+ * 
+ * * Protobuf type {@code org.apache.dubbo.metadata.MetadataInfoV2} */ public final class MetadataInfoV2 extends com.google.protobuf.GeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:org.apache.dubbo.metadata.MetadataInfoV2) MetadataInfoV2OrBuilder { + private static final long serialVersionUID = 0L; + // Use MetadataInfoV2.newBuilder() to construct. private MetadataInfoV2(com.google.protobuf.GeneratedMessageV3.Builder builder) { super(builder); @@ -65,7 +71,12 @@ protected FieldAccessorTable internalGetFieldAccessorTable() { @SuppressWarnings("serial") private volatile Object app_ = ""; + /** + *
+     * The application name.
+     * 
+ * * string app = 1; * @return The app. */ @@ -81,7 +92,12 @@ public String getApp() { return s; } } + /** + *
+     * The application name.
+     * 
+ * * string app = 1; * @return The bytes for app. */ @@ -101,7 +117,12 @@ public com.google.protobuf.ByteString getAppBytes() { @SuppressWarnings("serial") private volatile Object version_ = ""; + /** + *
+     * The application version.
+     * 
+ * * string version = 2; * @return The version. */ @@ -117,7 +138,12 @@ public String getVersion() { return s; } } + /** + *
+     * The application version.
+     * 
+ * * string version = 2; * @return The bytes for version. */ @@ -136,6 +162,7 @@ public com.google.protobuf.ByteString getVersionBytes() { public static final int SERVICES_FIELD_NUMBER = 3; private static final class ServicesDefaultEntryHolder { + static final com.google.protobuf.MapEntry defaultEntry = com.google.protobuf.MapEntry.newDefaultInstance( MetadataServiceV2OuterClass @@ -159,7 +186,12 @@ private com.google.protobuf.MapField internalGetServices( public int getServicesCount() { return internalGetServices().getMap().size(); } + /** + *
+     * A map of service information.
+     * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ @Override @@ -169,6 +201,7 @@ public boolean containsServices(String key) { } return internalGetServices().getMap().containsKey(key); } + /** * Use {@link #getServicesMap()} instead. */ @@ -177,14 +210,24 @@ public boolean containsServices(String key) { public java.util.Map getServices() { return getServicesMap(); } + /** + *
+     * A map of service information.
+     * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ @Override public java.util.Map getServicesMap() { return internalGetServices().getMap(); } + /** + *
+     * A map of service information.
+     * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ @Override @@ -198,7 +241,12 @@ public java.util.Map getServicesMap() { java.util.Map map = internalGetServices().getMap(); return map.containsKey(key) ? map.get(key) : defaultValue; } + /** + *
+     * A map of service information.
+     * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ @Override @@ -218,8 +266,12 @@ public ServiceInfoV2 getServicesOrThrow(String key) { @Override public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; + if (isInitialized == 1) { + return true; + } + if (isInitialized == 0) { + return false; + } memoizedIsInitialized = 1; return true; @@ -241,7 +293,9 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io @Override public int getSerializedSize() { int size = memoizedSize; - if (size != -1) return size; + if (size != -1) { + return size; + } size = 0; if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(app_)) { @@ -274,10 +328,18 @@ public boolean equals(final Object obj) { } MetadataInfoV2 other = (MetadataInfoV2) obj; - if (!getApp().equals(other.getApp())) return false; - if (!getVersion().equals(other.getVersion())) return false; - if (!internalGetServices().equals(other.internalGetServices())) return false; - if (!getUnknownFields().equals(other.getUnknownFields())) return false; + if (!getApp().equals(other.getApp())) { + return false; + } + if (!getVersion().equals(other.getVersion())) { + return false; + } + if (!internalGetServices().equals(other.internalGetServices())) { + return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) { + return false; + } return true; } @@ -385,13 +447,19 @@ protected Builder newBuilderForType(BuilderParent parent) { Builder builder = new Builder(parent); return builder; } + /** + *
+     * Metadata information message.
+     * 
+ * * Protobuf type {@code org.apache.dubbo.metadata.MetadataInfoV2} */ public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:org.apache.dubbo.metadata.MetadataInfoV2) MetadataInfoV2OrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_MetadataInfoV2_descriptor; } @@ -483,6 +551,37 @@ private void buildPartial0(MetadataInfoV2 result) { } } + @Override + public Builder clone() { + return super.clone(); + } + + @Override + public Builder setField(com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { + return super.setField(field, value); + } + + @Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, Object value) { + return super.setRepeatedField(field, index, value); + } + + @Override + public Builder addRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { + return super.addRepeatedField(field, value); + } + @Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof MetadataInfoV2) { @@ -494,7 +593,9 @@ public Builder mergeFrom(com.google.protobuf.Message other) { } public Builder mergeFrom(MetadataInfoV2 other) { - if (other == MetadataInfoV2.getDefaultInstance()) return this; + if (other == MetadataInfoV2.getDefaultInstance()) { + return this; + } if (!other.getApp().isEmpty()) { app_ = other.app_; bitField0_ |= 0x00000001; @@ -570,7 +671,12 @@ public Builder mergeFrom( private int bitField0_; private Object app_ = ""; + /** + *
+         * The application name.
+         * 
+ * * string app = 1; * @return The app. */ @@ -585,7 +691,12 @@ public String getApp() { return (String) ref; } } + /** + *
+         * The application name.
+         * 
+ * * string app = 1; * @return The bytes for app. */ @@ -599,7 +710,12 @@ public com.google.protobuf.ByteString getAppBytes() { return (com.google.protobuf.ByteString) ref; } } + /** + *
+         * The application name.
+         * 
+ * * string app = 1; * @param value The app to set. * @return This builder for chaining. @@ -613,7 +729,12 @@ public Builder setApp(String value) { onChanged(); return this; } + /** + *
+         * The application name.
+         * 
+ * * string app = 1; * @return This builder for chaining. */ @@ -623,7 +744,12 @@ public Builder clearApp() { onChanged(); return this; } + /** + *
+         * The application name.
+         * 
+ * * string app = 1; * @param value The bytes for app to set. * @return This builder for chaining. @@ -640,7 +766,12 @@ public Builder setAppBytes(com.google.protobuf.ByteString value) { } private Object version_ = ""; + /** + *
+         * The application version.
+         * 
+ * * string version = 2; * @return The version. */ @@ -655,7 +786,12 @@ public String getVersion() { return (String) ref; } } + /** + *
+         * The application version.
+         * 
+ * * string version = 2; * @return The bytes for version. */ @@ -669,7 +805,12 @@ public com.google.protobuf.ByteString getVersionBytes() { return (com.google.protobuf.ByteString) ref; } } + /** + *
+         * The application version.
+         * 
+ * * string version = 2; * @param value The version to set. * @return This builder for chaining. @@ -683,7 +824,12 @@ public Builder setVersion(String value) { onChanged(); return this; } + /** + *
+         * The application version.
+         * 
+ * * string version = 2; * @return This builder for chaining. */ @@ -693,7 +839,12 @@ public Builder clearVersion() { onChanged(); return this; } + /** + *
+         * The application version.
+         * 
+ * * string version = 2; * @param value The bytes for version to set. * @return This builder for chaining. @@ -733,7 +884,12 @@ private com.google.protobuf.MapField internalGetMutableSe public int getServicesCount() { return internalGetServices().getMap().size(); } + /** + *
+         * A map of service information.
+         * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ @Override @@ -743,6 +899,7 @@ public boolean containsServices(String key) { } return internalGetServices().getMap().containsKey(key); } + /** * Use {@link #getServicesMap()} instead. */ @@ -751,14 +908,24 @@ public boolean containsServices(String key) { public java.util.Map getServices() { return getServicesMap(); } + /** + *
+         * A map of service information.
+         * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ @Override public java.util.Map getServicesMap() { return internalGetServices().getMap(); } + /** + *
+         * A map of service information.
+         * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ @Override @@ -772,7 +939,12 @@ public java.util.Map getServicesMap() { java.util.Map map = internalGetServices().getMap(); return map.containsKey(key) ? map.get(key) : defaultValue; } + /** + *
+         * A map of service information.
+         * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ @Override @@ -792,7 +964,12 @@ public Builder clearServices() { internalGetMutableServices().getMutableMap().clear(); return this; } + /** + *
+         * A map of service information.
+         * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ public Builder removeServices(String key) { @@ -802,6 +979,7 @@ public Builder removeServices(String key) { internalGetMutableServices().getMutableMap().remove(key); return this; } + /** * Use alternate mutation accessors instead. */ @@ -810,7 +988,12 @@ public java.util.Map getMutableServices() { bitField0_ |= 0x00000004; return internalGetMutableServices().getMutableMap(); } + /** + *
+         * A map of service information.
+         * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ public Builder putServices(String key, ServiceInfoV2 value) { @@ -824,7 +1007,12 @@ public Builder putServices(String key, ServiceInfoV2 value) { bitField0_ |= 0x00000004; return this; } + /** + *
+         * A map of service information.
+         * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ public Builder putAllServices(java.util.Map values) { diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2OrBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2OrBuilder.java index cab7cdc934e..adf6b4376fc 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2OrBuilder.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataInfoV2OrBuilder.java @@ -22,45 +22,83 @@ public interface MetadataInfoV2OrBuilder com.google.protobuf.MessageOrBuilder { /** + *
+     * The application name.
+     * 
+ * * string app = 1; * @return The app. */ String getApp(); + /** + *
+     * The application name.
+     * 
+ * * string app = 1; * @return The bytes for app. */ com.google.protobuf.ByteString getAppBytes(); /** + *
+     * The application version.
+     * 
+ * * string version = 2; * @return The version. */ String getVersion(); + /** + *
+     * The application version.
+     * 
+ * * string version = 2; * @return The bytes for version. */ com.google.protobuf.ByteString getVersionBytes(); /** + *
+     * A map of service information.
+     * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ int getServicesCount(); + /** + *
+     * A map of service information.
+     * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ boolean containsServices(String key); + /** * Use {@link #getServicesMap()} instead. */ @Deprecated java.util.Map getServices(); + /** + *
+     * A map of service information.
+     * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ java.util.Map getServicesMap(); + /** + *
+     * A map of service information.
+     * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ /* nullable */ @@ -68,7 +106,12 @@ ServiceInfoV2 getServicesOrDefault( String key, /* nullable */ ServiceInfoV2 defaultValue); + /** + *
+     * A map of service information.
+     * 
+ * * map<string, .org.apache.dubbo.metadata.ServiceInfoV2> services = 3; */ ServiceInfoV2 getServicesOrThrow(String key); diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataRequest.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataRequest.java index c989693c43e..4e78f6f807e 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataRequest.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataRequest.java @@ -17,13 +17,19 @@ package org.apache.dubbo.metadata; /** + *
+ * Metadata request message.
+ * 
+ * * Protobuf type {@code org.apache.dubbo.metadata.MetadataRequest} */ public final class MetadataRequest extends com.google.protobuf.GeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:org.apache.dubbo.metadata.MetadataRequest) MetadataRequestOrBuilder { + private static final long serialVersionUID = 0L; + // Use MetadataRequest.newBuilder() to construct. private MetadataRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { super(builder); @@ -53,7 +59,12 @@ protected FieldAccessorTable internalGetFieldAccessorTable() { @SuppressWarnings("serial") private volatile Object revision_ = ""; + /** + *
+     * The revision of the metadata.
+     * 
+ * * string revision = 1; * @return The revision. */ @@ -69,7 +80,12 @@ public String getRevision() { return s; } } + /** + *
+     * The revision of the metadata.
+     * 
+ * * string revision = 1; * @return The bytes for revision. */ @@ -90,8 +106,12 @@ public com.google.protobuf.ByteString getRevisionBytes() { @Override public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; + if (isInitialized == 1) { + return true; + } + if (isInitialized == 0) { + return false; + } memoizedIsInitialized = 1; return true; @@ -108,7 +128,9 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io @Override public int getSerializedSize() { int size = memoizedSize; - if (size != -1) return size; + if (size != -1) { + return size; + } size = 0; if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(revision_)) { @@ -129,8 +151,12 @@ public boolean equals(final Object obj) { } MetadataRequest other = (MetadataRequest) obj; - if (!getRevision().equals(other.getRevision())) return false; - if (!getUnknownFields().equals(other.getUnknownFields())) return false; + if (!getRevision().equals(other.getRevision())) { + return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) { + return false; + } return true; } @@ -232,13 +258,19 @@ protected Builder newBuilderForType(BuilderParent parent) { Builder builder = new Builder(parent); return builder; } + /** + *
+     * Metadata request message.
+     * 
+ * * Protobuf type {@code org.apache.dubbo.metadata.MetadataRequest} */ public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:org.apache.dubbo.metadata.MetadataRequest) MetadataRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_MetadataRequest_descriptor; } @@ -301,6 +333,37 @@ private void buildPartial0(MetadataRequest result) { } } + @Override + public Builder clone() { + return super.clone(); + } + + @Override + public Builder setField(com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { + return super.setField(field, value); + } + + @Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, Object value) { + return super.setRepeatedField(field, index, value); + } + + @Override + public Builder addRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { + return super.addRepeatedField(field, value); + } + @Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof MetadataRequest) { @@ -312,7 +375,9 @@ public Builder mergeFrom(com.google.protobuf.Message other) { } public Builder mergeFrom(MetadataRequest other) { - if (other == MetadataRequest.getDefaultInstance()) return this; + if (other == MetadataRequest.getDefaultInstance()) { + return this; + } if (!other.getRevision().isEmpty()) { revision_ = other.revision_; bitField0_ |= 0x00000001; @@ -367,7 +432,12 @@ public Builder mergeFrom( private int bitField0_; private Object revision_ = ""; + /** + *
+         * The revision of the metadata.
+         * 
+ * * string revision = 1; * @return The revision. */ @@ -382,7 +452,12 @@ public String getRevision() { return (String) ref; } } + /** + *
+         * The revision of the metadata.
+         * 
+ * * string revision = 1; * @return The bytes for revision. */ @@ -396,7 +471,12 @@ public com.google.protobuf.ByteString getRevisionBytes() { return (com.google.protobuf.ByteString) ref; } } + /** + *
+         * The revision of the metadata.
+         * 
+ * * string revision = 1; * @param value The revision to set. * @return This builder for chaining. @@ -410,7 +490,12 @@ public Builder setRevision(String value) { onChanged(); return this; } + /** + *
+         * The revision of the metadata.
+         * 
+ * * string revision = 1; * @return This builder for chaining. */ @@ -420,7 +505,12 @@ public Builder clearRevision() { onChanged(); return this; } + /** + *
+         * The revision of the metadata.
+         * 
+ * * string revision = 1; * @param value The bytes for revision to set. * @return This builder for chaining. diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataRequestOrBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataRequestOrBuilder.java index 4099bb21cec..98c54262a1a 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataRequestOrBuilder.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataRequestOrBuilder.java @@ -22,11 +22,20 @@ public interface MetadataRequestOrBuilder com.google.protobuf.MessageOrBuilder { /** + *
+     * The revision of the metadata.
+     * 
+ * * string revision = 1; * @return The revision. */ String getRevision(); + /** + *
+     * The revision of the metadata.
+     * 
+ * * string revision = 1; * @return The bytes for revision. */ diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2.java index e938b3c2b15..a74d09f4d05 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2.java @@ -16,17 +16,28 @@ */ package org.apache.dubbo.metadata; -import org.apache.dubbo.remoting.http12.rest.Mapping; - import java.util.concurrent.CompletableFuture; -@Mapping(enabled = false) public interface MetadataServiceV2 extends org.apache.dubbo.rpc.model.DubboStub { String JAVA_SERVICE_NAME = "org.apache.dubbo.metadata.MetadataServiceV2"; String SERVICE_NAME = "org.apache.dubbo.metadata.MetadataServiceV2"; + /** + *
+     *  Retrieves metadata information.
+     * 
+ */ MetadataInfoV2 getMetadataInfo(MetadataRequest request); CompletableFuture getMetadataInfoAsync(MetadataRequest request); + + /** + *
+     *  Retrieves OpenAPI.
+     * 
+ */ + OpenAPI getOpenAPI(OpenAPIRequest request); + + CompletableFuture getOpenAPIAsync(OpenAPIRequest request); } diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2OuterClass.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2OuterClass.java index 01c1362d70e..7c91790497d 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2OuterClass.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataServiceV2OuterClass.java @@ -17,6 +17,7 @@ package org.apache.dubbo.metadata; public final class MetadataServiceV2OuterClass { + private MetadataServiceV2OuterClass() {} public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) {} @@ -45,6 +46,14 @@ public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry r internal_static_org_apache_dubbo_metadata_ServiceInfoV2_ParamsEntry_descriptor; static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_org_apache_dubbo_metadata_ServiceInfoV2_ParamsEntry_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_apache_dubbo_metadata_OpenAPIRequest_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_org_apache_dubbo_metadata_OpenAPIRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_apache_dubbo_metadata_OpenAPI_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_org_apache_dubbo_metadata_OpenAPI_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { return descriptor; @@ -67,12 +76,20 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "(\005\022\014\n\004path\030\006 \001(\t\022D\n\006params\030\007 \003(\01324.org.a" + "pache.dubbo.metadata.ServiceInfoV2.Param" + "sEntry\032-\n\013ParamsEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005va" - + "lue\030\002 \001(\t:\0028\0012}\n\021MetadataServiceV2\022h\n\017Ge" - + "tMetadataInfo\022*.org.apache.dubbo.metadat" - + "a.MetadataRequest\032).org.apache.dubbo.met" - + "adata.MetadataInfoV2BZ\n\031org.apache.dubbo" - + ".metadataP\001Z;dubbo.apache.org/dubbo-go/v" - + "3/metadata/triple_api;triple_apib\006proto3" + + "lue\030\002 \001(\t:\0028\001\"\372\001\n\016OpenAPIRequest\022\022\n\005grou" + + "p\030\001 \001(\tH\000\210\001\001\022\024\n\007version\030\002 \001(\tH\001\210\001\001\022\013\n\003ta" + + "g\030\003 \003(\t\022\017\n\007service\030\004 \003(\t\022\024\n\007openapi\030\005 \001(" + + "\tH\002\210\001\001\022=\n\006format\030\006 \001(\0162(.org.apache.dubb" + + "o.metadata.OpenAPIFormatH\003\210\001\001\022\023\n\006pretty\030" + + "\007 \001(\010H\004\210\001\001B\010\n\006_groupB\n\n\010_versionB\n\n\010_ope" + + "napiB\t\n\007_formatB\t\n\007_pretty\"\030\n\007OpenAPI\022\r\n" + + "\005value\030\001 \001(\t*.\n\rOpenAPIFormat\022\010\n\004JSON\020\000\022" + + "\010\n\004YAML\020\001\022\t\n\005PROTO\020\0022\332\001\n\021MetadataService" + + "V2\022h\n\017GetMetadataInfo\022*.org.apache.dubbo" + + ".metadata.MetadataRequest\032).org.apache.d" + + "ubbo.metadata.MetadataInfoV2\022[\n\nGetOpenA" + "PI\022).org.apache.dubbo.metadata.OpenAPIRe" + + "quest\032\".org.apache.dubbo.metadata.OpenAP" + "IBZ\n\031org.apache.dubbo.metadataP\001Z;dubbo." + + "apache.org/dubbo-go/v3/metadata/triple_a" + "pi;triple_apib\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] {}); @@ -116,6 +133,20 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { internal_static_org_apache_dubbo_metadata_ServiceInfoV2_ParamsEntry_descriptor, new String[] { "Key", "Value", }); + internal_static_org_apache_dubbo_metadata_OpenAPIRequest_descriptor = + getDescriptor().getMessageTypes().get(3); + internal_static_org_apache_dubbo_metadata_OpenAPIRequest_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_apache_dubbo_metadata_OpenAPIRequest_descriptor, new String[] { + "Group", "Version", "Tag", "Service", "Openapi", "Format", "Pretty", + }); + internal_static_org_apache_dubbo_metadata_OpenAPI_descriptor = + getDescriptor().getMessageTypes().get(4); + internal_static_org_apache_dubbo_metadata_OpenAPI_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_apache_dubbo_metadata_OpenAPI_descriptor, new String[] { + "Value", + }); } // @@protoc_insertion_point(outer_class_scope) diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPI.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPI.java new file mode 100644 index 00000000000..b8ef1efe7d2 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPI.java @@ -0,0 +1,587 @@ +/* + * 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.dubbo.metadata; + +/** + *
+ * OpenAPI message.
+ * 
+ * + * Protobuf type {@code org.apache.dubbo.metadata.OpenAPI} + */ +public final class OpenAPI extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:org.apache.dubbo.metadata.OpenAPI) + OpenAPIOrBuilder { + + private static final long serialVersionUID = 0L; + + // Use OpenAPI.newBuilder() to construct. + private OpenAPI(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private OpenAPI() { + value_ = ""; + } + + @Override + @SuppressWarnings({"unused"}) + protected Object newInstance(UnusedPrivateParameter unused) { + return new OpenAPI(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_OpenAPI_descriptor; + } + + @Override + protected FieldAccessorTable internalGetFieldAccessorTable() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_OpenAPI_fieldAccessorTable + .ensureFieldAccessorsInitialized(OpenAPI.class, Builder.class); + } + + public static final int VALUE_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile Object value_ = ""; + + /** + *
+     * The value of the OpenAPI.
+     * 
+ * + * string value = 1; + * @return The value. + */ + @Override + public String getValue() { + Object ref = value_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + value_ = s; + return s; + } + } + + /** + *
+     * The value of the OpenAPI.
+     * 
+ * + * string value = 1; + * @return The bytes for value. + */ + @Override + public com.google.protobuf.ByteString getValueBytes() { + Object ref = value_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + value_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + + @Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) { + return true; + } + if (isInitialized == 0) { + return false; + } + + memoizedIsInitialized = 1; + return true; + } + + @Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(value_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, value_); + } + getUnknownFields().writeTo(output); + } + + @Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) { + return size; + } + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(value_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, value_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @Override + public boolean equals(final Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof OpenAPI)) { + return super.equals(obj); + } + OpenAPI other = (OpenAPI) obj; + + if (!getValue().equals(other.getValue())) { + return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) { + return false; + } + return true; + } + + @Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + VALUE_FIELD_NUMBER; + hash = (53 * hash) + getValue().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static OpenAPI parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static OpenAPI parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static OpenAPI parseFrom(com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static OpenAPI parseFrom( + com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static OpenAPI parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static OpenAPI parseFrom(byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static OpenAPI parseFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static OpenAPI parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry); + } + + public static OpenAPI parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static OpenAPI parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + + public static OpenAPI parseFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static OpenAPI parseFrom( + com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry); + } + + @Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(OpenAPI prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @Override + protected Builder newBuilderForType(BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + + /** + *
+     * OpenAPI message.
+     * 
+ * + * Protobuf type {@code org.apache.dubbo.metadata.OpenAPI} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:org.apache.dubbo.metadata.OpenAPI) + OpenAPIOrBuilder { + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_OpenAPI_descriptor; + } + + @Override + protected FieldAccessorTable internalGetFieldAccessorTable() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_OpenAPI_fieldAccessorTable + .ensureFieldAccessorsInitialized(OpenAPI.class, Builder.class); + } + + // Construct using org.apache.dubbo.metadata.OpenAPI.newBuilder() + private Builder() {} + + private Builder(BuilderParent parent) { + super(parent); + } + + @Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + value_ = ""; + return this; + } + + @Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_OpenAPI_descriptor; + } + + @Override + public OpenAPI getDefaultInstanceForType() { + return OpenAPI.getDefaultInstance(); + } + + @Override + public OpenAPI build() { + OpenAPI result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @Override + public OpenAPI buildPartial() { + OpenAPI result = new OpenAPI(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(OpenAPI result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.value_ = value_; + } + } + + @Override + public Builder clone() { + return super.clone(); + } + + @Override + public Builder setField(com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { + return super.setField(field, value); + } + + @Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, Object value) { + return super.setRepeatedField(field, index, value); + } + + @Override + public Builder addRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { + return super.addRepeatedField(field, value); + } + + @Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof OpenAPI) { + return mergeFrom((OpenAPI) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(OpenAPI other) { + if (other == OpenAPI.getDefaultInstance()) { + return this; + } + if (!other.getValue().isEmpty()) { + value_ = other.value_; + bitField0_ |= 0x00000001; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @Override + public final boolean isInitialized() { + return true; + } + + @Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + value_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private Object value_ = ""; + + /** + *
+         * The value of the OpenAPI.
+         * 
+ * + * string value = 1; + * @return The value. + */ + public String getValue() { + Object ref = value_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + value_ = s; + return s; + } else { + return (String) ref; + } + } + + /** + *
+         * The value of the OpenAPI.
+         * 
+ * + * string value = 1; + * @return The bytes for value. + */ + public com.google.protobuf.ByteString getValueBytes() { + Object ref = value_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + value_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + *
+         * The value of the OpenAPI.
+         * 
+ * + * string value = 1; + * @param value The value to set. + * @return This builder for chaining. + */ + public Builder setValue(String value) { + if (value == null) { + throw new NullPointerException(); + } + value_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + /** + *
+         * The value of the OpenAPI.
+         * 
+ * + * string value = 1; + * @return This builder for chaining. + */ + public Builder clearValue() { + value_ = getDefaultInstance().getValue(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + + /** + *
+         * The value of the OpenAPI.
+         * 
+ * + * string value = 1; + * @param value The bytes for value to set. + * @return This builder for chaining. + */ + public Builder setValueBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + value_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + @Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @Override + public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:org.apache.dubbo.metadata.OpenAPI) + } + + // @@protoc_insertion_point(class_scope:org.apache.dubbo.metadata.OpenAPI) + private static final OpenAPI DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new OpenAPI(); + } + + public static OpenAPI getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @Override + public OpenAPI parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @Override + public OpenAPI getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIFormat.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIFormat.java new file mode 100644 index 00000000000..f679ee9b7ab --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIFormat.java @@ -0,0 +1,158 @@ +/* + * 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.dubbo.metadata; + +/** + *
+ * Response format enumeration.
+ * 
+ * + * Protobuf enum {@code org.apache.dubbo.metadata.OpenAPIFormat} + */ +public enum OpenAPIFormat implements com.google.protobuf.ProtocolMessageEnum { + /** + *
+     * JSON format.
+     * 
+ * + * JSON = 0; + */ + JSON(0), + /** + *
+     * YAML format.
+     * 
+ * + * YAML = 1; + */ + YAML(1), + /** + *
+     * PROTO format.
+     * 
+ * + * PROTO = 2; + */ + PROTO(2), + UNRECOGNIZED(-1), + ; + + /** + *
+     * JSON format.
+     * 
+ * + * JSON = 0; + */ + public static final int JSON_VALUE = 0; + /** + *
+     * YAML format.
+     * 
+ * + * YAML = 1; + */ + public static final int YAML_VALUE = 1; + /** + *
+     * PROTO format.
+     * 
+ * + * PROTO = 2; + */ + public static final int PROTO_VALUE = 2; + + public final int getNumber() { + if (this == UNRECOGNIZED) { + throw new IllegalArgumentException("Can't get the number of an unknown enum value."); + } + return value; + } + + /** + * @param value The numeric wire value of the corresponding enum entry. + * @return The enum associated with the given numeric wire value. + * @deprecated Use {@link #forNumber(int)} instead. + */ + @Deprecated + public static OpenAPIFormat valueOf(int value) { + return forNumber(value); + } + + /** + * @param value The numeric wire value of the corresponding enum entry. + * @return The enum associated with the given numeric wire value. + */ + public static OpenAPIFormat forNumber(int value) { + switch (value) { + case 0: + return JSON; + case 1: + return YAML; + case 2: + return PROTO; + default: + return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap internalGetValueMap() { + return internalValueMap; + } + + private static final com.google.protobuf.Internal.EnumLiteMap internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public OpenAPIFormat findValueByNumber(int number) { + return OpenAPIFormat.forNumber(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor getValueDescriptor() { + if (this == UNRECOGNIZED) { + throw new IllegalStateException("Can't get the descriptor of an unrecognized enum value."); + } + return getDescriptor().getValues().get(ordinal()); + } + + public final com.google.protobuf.Descriptors.EnumDescriptor getDescriptorForType() { + return getDescriptor(); + } + + public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { + return MetadataServiceV2OuterClass.getDescriptor().getEnumTypes().get(0); + } + + private static final OpenAPIFormat[] VALUES = values(); + + public static OpenAPIFormat valueOf(com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new IllegalArgumentException("EnumValueDescriptor is not for this type."); + } + if (desc.getIndex() == -1) { + return UNRECOGNIZED; + } + return VALUES[desc.getIndex()]; + } + + private final int value; + + private OpenAPIFormat(int value) { + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:org.apache.dubbo.metadata.OpenAPIFormat) +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIOrBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIOrBuilder.java new file mode 100644 index 00000000000..a9578f728f2 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIOrBuilder.java @@ -0,0 +1,43 @@ +/* + * 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.dubbo.metadata; + +public interface OpenAPIOrBuilder + extends + // @@protoc_insertion_point(interface_extends:org.apache.dubbo.metadata.OpenAPI) + com.google.protobuf.MessageOrBuilder { + + /** + *
+     * The value of the OpenAPI.
+     * 
+ * + * string value = 1; + * @return The value. + */ + String getValue(); + + /** + *
+     * The value of the OpenAPI.
+     * 
+ * + * string value = 1; + * @return The bytes for value. + */ + com.google.protobuf.ByteString getValueBytes(); +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIRequest.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIRequest.java new file mode 100644 index 00000000000..e8393680b43 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIRequest.java @@ -0,0 +1,1748 @@ +/* + * 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.dubbo.metadata; + +/** + *
+ * OpenAPI request message.
+ * 
+ * + * Protobuf type {@code org.apache.dubbo.metadata.OpenAPIRequest} + */ +public final class OpenAPIRequest extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:org.apache.dubbo.metadata.OpenAPIRequest) + OpenAPIRequestOrBuilder { + + private static final long serialVersionUID = 0L; + + // Use OpenAPIRequest.newBuilder() to construct. + private OpenAPIRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private OpenAPIRequest() { + group_ = ""; + version_ = ""; + tag_ = com.google.protobuf.LazyStringArrayList.emptyList(); + service_ = com.google.protobuf.LazyStringArrayList.emptyList(); + openapi_ = ""; + format_ = 0; + } + + @Override + @SuppressWarnings({"unused"}) + protected Object newInstance(UnusedPrivateParameter unused) { + return new OpenAPIRequest(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_OpenAPIRequest_descriptor; + } + + @Override + protected FieldAccessorTable internalGetFieldAccessorTable() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_OpenAPIRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized(OpenAPIRequest.class, Builder.class); + } + + private int bitField0_; + public static final int GROUP_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile Object group_ = ""; + + /** + *
+     * The openAPI group.
+     * 
+ * + * string group = 1; + * @return The group. + */ + @Override + public String getGroup() { + Object ref = group_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + group_ = s; + return s; + } + } + + /** + *
+     * The openAPI group.
+     * 
+ * + * string group = 1; + * @return The bytes for group. + */ + @Override + public com.google.protobuf.ByteString getGroupBytes() { + Object ref = group_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + group_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int VERSION_FIELD_NUMBER = 2; + + @SuppressWarnings("serial") + private volatile Object version_ = ""; + + /** + *
+     * The openAPI version, using a major.minor.patch versioning scheme
+     * e.g. 1.0.1
+     * 
+ * + * string version = 2; + * @return The version. + */ + @Override + public String getVersion() { + Object ref = version_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + version_ = s; + return s; + } + } + + /** + *
+     * The openAPI version, using a major.minor.patch versioning scheme
+     * e.g. 1.0.1
+     * 
+ * + * string version = 2; + * @return The bytes for version. + */ + @Override + public com.google.protobuf.ByteString getVersionBytes() { + Object ref = version_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + version_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int TAG_FIELD_NUMBER = 3; + + @SuppressWarnings("serial") + private com.google.protobuf.LazyStringArrayList tag_ = com.google.protobuf.LazyStringArrayList.emptyList(); + + /** + *
+     * The openAPI tags. Each tag is an or condition.
+     * 
+ * + * repeated string tag = 3; + * @return A list containing the tag. + */ + public com.google.protobuf.ProtocolStringList getTagList() { + return tag_; + } + + /** + *
+     * The openAPI tags. Each tag is an or condition.
+     * 
+ * + * repeated string tag = 3; + * @return The count of tag. + */ + public int getTagCount() { + return tag_.size(); + } + + /** + *
+     * The openAPI tags. Each tag is an or condition.
+     * 
+ * + * repeated string tag = 3; + * @param index The index of the element to return. + * @return The tag at the given index. + */ + public String getTag(int index) { + return tag_.get(index); + } + + /** + *
+     * The openAPI tags. Each tag is an or condition.
+     * 
+ * + * repeated string tag = 3; + * @param index The index of the value to return. + * @return The bytes of the tag at the given index. + */ + public com.google.protobuf.ByteString getTagBytes(int index) { + return tag_.getByteString(index); + } + + public static final int SERVICE_FIELD_NUMBER = 4; + + @SuppressWarnings("serial") + private com.google.protobuf.LazyStringArrayList service_ = com.google.protobuf.LazyStringArrayList.emptyList(); + + /** + *
+     * The openAPI services. Each service is an or condition.
+     * 
+ * + * repeated string service = 4; + * @return A list containing the service. + */ + public com.google.protobuf.ProtocolStringList getServiceList() { + return service_; + } + + /** + *
+     * The openAPI services. Each service is an or condition.
+     * 
+ * + * repeated string service = 4; + * @return The count of service. + */ + public int getServiceCount() { + return service_.size(); + } + + /** + *
+     * The openAPI services. Each service is an or condition.
+     * 
+ * + * repeated string service = 4; + * @param index The index of the element to return. + * @return The service at the given index. + */ + public String getService(int index) { + return service_.get(index); + } + + /** + *
+     * The openAPI services. Each service is an or condition.
+     * 
+ * + * repeated string service = 4; + * @param index The index of the value to return. + * @return The bytes of the service at the given index. + */ + public com.google.protobuf.ByteString getServiceBytes(int index) { + return service_.getByteString(index); + } + + public static final int OPENAPI_FIELD_NUMBER = 5; + + @SuppressWarnings("serial") + private volatile Object openapi_ = ""; + + /** + *
+     * The openAPI specification version, using a major.minor.patch versioning scheme
+     * e.g. 3.0.1, 3.1.0
+     * The default value is '3.0.1'.
+     * 
+ * + * string openapi = 5; + * @return The openapi. + */ + @Override + public String getOpenapi() { + Object ref = openapi_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + openapi_ = s; + return s; + } + } + + /** + *
+     * The openAPI specification version, using a major.minor.patch versioning scheme
+     * e.g. 3.0.1, 3.1.0
+     * The default value is '3.0.1'.
+     * 
+ * + * string openapi = 5; + * @return The bytes for openapi. + */ + @Override + public com.google.protobuf.ByteString getOpenapiBytes() { + Object ref = openapi_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + openapi_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int FORMAT_FIELD_NUMBER = 6; + private int format_ = 0; + + /** + *
+     * The format of the response.
+     * The default value is 'JSON'.
+     * 
+ * + * optional .org.apache.dubbo.metadata.OpenAPIFormat format = 6; + * @return Whether the format field is set. + */ + @Override + public boolean hasFormat() { + return ((bitField0_ & 0x00000001) != 0); + } + + /** + *
+     * The format of the response.
+     * The default value is 'JSON'.
+     * 
+ * + * optional .org.apache.dubbo.metadata.OpenAPIFormat format = 6; + * @return The enum numeric value on the wire for format. + */ + @Override + public int getFormatValue() { + return format_; + } + + /** + *
+     * The format of the response.
+     * The default value is 'JSON'.
+     * 
+ * + * optional .org.apache.dubbo.metadata.OpenAPIFormat format = 6; + * @return The format. + */ + @Override + public OpenAPIFormat getFormat() { + OpenAPIFormat result = OpenAPIFormat.forNumber(format_); + return result == null ? OpenAPIFormat.UNRECOGNIZED : result; + } + + public static final int PRETTY_FIELD_NUMBER = 7; + private boolean pretty_ = false; + + /** + *
+     * Whether to pretty print for json.
+     * The default value is 'false'.
+     * 
+ * + * optional bool pretty = 7; + * @return Whether the pretty field is set. + */ + @Override + public boolean hasPretty() { + return ((bitField0_ & 0x00000002) != 0); + } + + /** + *
+     * Whether to pretty print for json.
+     * The default value is 'false'.
+     * 
+ * + * optional bool pretty = 7; + * @return The pretty. + */ + @Override + public boolean getPretty() { + return pretty_; + } + + private byte memoizedIsInitialized = -1; + + @Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) { + return true; + } + if (isInitialized == 0) { + return false; + } + + memoizedIsInitialized = 1; + return true; + } + + @Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(group_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, group_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(version_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, version_); + } + for (int i = 0; i < tag_.size(); i++) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, tag_.getRaw(i)); + } + for (int i = 0; i < service_.size(); i++) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 4, service_.getRaw(i)); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(openapi_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 5, openapi_); + } + if (((bitField0_ & 0x00000001) != 0)) { + output.writeEnum(6, format_); + } + if (((bitField0_ & 0x00000002) != 0)) { + output.writeBool(7, pretty_); + } + getUnknownFields().writeTo(output); + } + + @Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) { + return size; + } + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(group_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, group_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(version_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, version_); + } + { + int dataSize = 0; + for (int i = 0; i < tag_.size(); i++) { + dataSize += computeStringSizeNoTag(tag_.getRaw(i)); + } + size += dataSize; + size += 1 * getTagList().size(); + } + { + int dataSize = 0; + for (int i = 0; i < service_.size(); i++) { + dataSize += computeStringSizeNoTag(service_.getRaw(i)); + } + size += dataSize; + size += 1 * getServiceList().size(); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(openapi_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, openapi_); + } + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeEnumSize(6, format_); + } + if (((bitField0_ & 0x00000002) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeBoolSize(7, pretty_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @Override + public boolean equals(final Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof OpenAPIRequest)) { + return super.equals(obj); + } + OpenAPIRequest other = (OpenAPIRequest) obj; + + if (!getGroup().equals(other.getGroup())) { + return false; + } + if (!getVersion().equals(other.getVersion())) { + return false; + } + if (!getTagList().equals(other.getTagList())) { + return false; + } + if (!getServiceList().equals(other.getServiceList())) { + return false; + } + if (!getOpenapi().equals(other.getOpenapi())) { + return false; + } + if (hasFormat() != other.hasFormat()) { + return false; + } + if (hasFormat()) { + if (format_ != other.format_) { + return false; + } + } + if (hasPretty() != other.hasPretty()) { + return false; + } + if (hasPretty()) { + if (getPretty() != other.getPretty()) { + return false; + } + } + if (!getUnknownFields().equals(other.getUnknownFields())) { + return false; + } + return true; + } + + @Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + GROUP_FIELD_NUMBER; + hash = (53 * hash) + getGroup().hashCode(); + hash = (37 * hash) + VERSION_FIELD_NUMBER; + hash = (53 * hash) + getVersion().hashCode(); + if (getTagCount() > 0) { + hash = (37 * hash) + TAG_FIELD_NUMBER; + hash = (53 * hash) + getTagList().hashCode(); + } + if (getServiceCount() > 0) { + hash = (37 * hash) + SERVICE_FIELD_NUMBER; + hash = (53 * hash) + getServiceList().hashCode(); + } + hash = (37 * hash) + OPENAPI_FIELD_NUMBER; + hash = (53 * hash) + getOpenapi().hashCode(); + if (hasFormat()) { + hash = (37 * hash) + FORMAT_FIELD_NUMBER; + hash = (53 * hash) + format_; + } + if (hasPretty()) { + hash = (37 * hash) + PRETTY_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean(getPretty()); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static OpenAPIRequest parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static OpenAPIRequest parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static OpenAPIRequest parseFrom(com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static OpenAPIRequest parseFrom( + com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static OpenAPIRequest parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static OpenAPIRequest parseFrom(byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static OpenAPIRequest parseFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static OpenAPIRequest parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry); + } + + public static OpenAPIRequest parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static OpenAPIRequest parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + + public static OpenAPIRequest parseFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static OpenAPIRequest parseFrom( + com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry); + } + + @Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(OpenAPIRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @Override + protected Builder newBuilderForType(BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + + /** + *
+     * OpenAPI request message.
+     * 
+ * + * Protobuf type {@code org.apache.dubbo.metadata.OpenAPIRequest} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:org.apache.dubbo.metadata.OpenAPIRequest) + OpenAPIRequestOrBuilder { + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_OpenAPIRequest_descriptor; + } + + @Override + protected FieldAccessorTable internalGetFieldAccessorTable() { + return MetadataServiceV2OuterClass + .internal_static_org_apache_dubbo_metadata_OpenAPIRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized(OpenAPIRequest.class, Builder.class); + } + + // Construct using org.apache.dubbo.metadata.OpenAPIRequest.newBuilder() + private Builder() {} + + private Builder(BuilderParent parent) { + super(parent); + } + + @Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + group_ = ""; + version_ = ""; + tag_ = com.google.protobuf.LazyStringArrayList.emptyList(); + service_ = com.google.protobuf.LazyStringArrayList.emptyList(); + openapi_ = ""; + format_ = 0; + pretty_ = false; + return this; + } + + @Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_OpenAPIRequest_descriptor; + } + + @Override + public OpenAPIRequest getDefaultInstanceForType() { + return OpenAPIRequest.getDefaultInstance(); + } + + @Override + public OpenAPIRequest build() { + OpenAPIRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @Override + public OpenAPIRequest buildPartial() { + OpenAPIRequest result = new OpenAPIRequest(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(OpenAPIRequest result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.group_ = group_; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.version_ = version_; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + tag_.makeImmutable(); + result.tag_ = tag_; + } + if (((from_bitField0_ & 0x00000008) != 0)) { + service_.makeImmutable(); + result.service_ = service_; + } + if (((from_bitField0_ & 0x00000010) != 0)) { + result.openapi_ = openapi_; + } + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000020) != 0)) { + result.format_ = format_; + to_bitField0_ |= 0x00000001; + } + if (((from_bitField0_ & 0x00000040) != 0)) { + result.pretty_ = pretty_; + to_bitField0_ |= 0x00000002; + } + result.bitField0_ |= to_bitField0_; + } + + @Override + public Builder clone() { + return super.clone(); + } + + @Override + public Builder setField(com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { + return super.setField(field, value); + } + + @Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, Object value) { + return super.setRepeatedField(field, index, value); + } + + @Override + public Builder addRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { + return super.addRepeatedField(field, value); + } + + @Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof OpenAPIRequest) { + return mergeFrom((OpenAPIRequest) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(OpenAPIRequest other) { + if (other == OpenAPIRequest.getDefaultInstance()) { + return this; + } + if (!other.getGroup().isEmpty()) { + group_ = other.group_; + bitField0_ |= 0x00000001; + onChanged(); + } + if (!other.getVersion().isEmpty()) { + version_ = other.version_; + bitField0_ |= 0x00000002; + onChanged(); + } + if (!other.tag_.isEmpty()) { + if (tag_.isEmpty()) { + tag_ = other.tag_; + bitField0_ |= 0x00000004; + } else { + ensureTagIsMutable(); + tag_.addAll(other.tag_); + } + onChanged(); + } + if (!other.service_.isEmpty()) { + if (service_.isEmpty()) { + service_ = other.service_; + bitField0_ |= 0x00000008; + } else { + ensureServiceIsMutable(); + service_.addAll(other.service_); + } + onChanged(); + } + if (!other.getOpenapi().isEmpty()) { + openapi_ = other.openapi_; + bitField0_ |= 0x00000010; + onChanged(); + } + if (other.hasFormat()) { + setFormat(other.getFormat()); + } + if (other.hasPretty()) { + setPretty(other.getPretty()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @Override + public final boolean isInitialized() { + return true; + } + + @Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + group_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: { + version_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000002; + break; + } // case 18 + case 26: { + String s = input.readStringRequireUtf8(); + ensureTagIsMutable(); + tag_.add(s); + break; + } // case 26 + case 34: { + String s = input.readStringRequireUtf8(); + ensureServiceIsMutable(); + service_.add(s); + break; + } // case 34 + case 42: { + openapi_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000010; + break; + } // case 42 + case 48: { + format_ = input.readEnum(); + bitField0_ |= 0x00000020; + break; + } // case 48 + case 56: { + pretty_ = input.readBool(); + bitField0_ |= 0x00000040; + break; + } // case 56 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private Object group_ = ""; + + /** + *
+         * The openAPI group.
+         * 
+ * + * string group = 1; + * @return The group. + */ + public String getGroup() { + Object ref = group_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + group_ = s; + return s; + } else { + return (String) ref; + } + } + + /** + *
+         * The openAPI group.
+         * 
+ * + * string group = 1; + * @return The bytes for group. + */ + public com.google.protobuf.ByteString getGroupBytes() { + Object ref = group_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + group_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + *
+         * The openAPI group.
+         * 
+ * + * string group = 1; + * @param value The group to set. + * @return This builder for chaining. + */ + public Builder setGroup(String value) { + if (value == null) { + throw new NullPointerException(); + } + group_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + /** + *
+         * The openAPI group.
+         * 
+ * + * string group = 1; + * @return This builder for chaining. + */ + public Builder clearGroup() { + group_ = getDefaultInstance().getGroup(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + + /** + *
+         * The openAPI group.
+         * 
+ * + * string group = 1; + * @param value The bytes for group to set. + * @return This builder for chaining. + */ + public Builder setGroupBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + group_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + private Object version_ = ""; + + /** + *
+         * The openAPI version, using a major.minor.patch versioning scheme
+         * e.g. 1.0.1
+         * 
+ * + * string version = 2; + * @return The version. + */ + public String getVersion() { + Object ref = version_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + version_ = s; + return s; + } else { + return (String) ref; + } + } + + /** + *
+         * The openAPI version, using a major.minor.patch versioning scheme
+         * e.g. 1.0.1
+         * 
+ * + * string version = 2; + * @return The bytes for version. + */ + public com.google.protobuf.ByteString getVersionBytes() { + Object ref = version_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + version_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + *
+         * The openAPI version, using a major.minor.patch versioning scheme
+         * e.g. 1.0.1
+         * 
+ * + * string version = 2; + * @param value The version to set. + * @return This builder for chaining. + */ + public Builder setVersion(String value) { + if (value == null) { + throw new NullPointerException(); + } + version_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + + /** + *
+         * The openAPI version, using a major.minor.patch versioning scheme
+         * e.g. 1.0.1
+         * 
+ * + * string version = 2; + * @return This builder for chaining. + */ + public Builder clearVersion() { + version_ = getDefaultInstance().getVersion(); + bitField0_ = (bitField0_ & ~0x00000002); + onChanged(); + return this; + } + + /** + *
+         * The openAPI version, using a major.minor.patch versioning scheme
+         * e.g. 1.0.1
+         * 
+ * + * string version = 2; + * @param value The bytes for version to set. + * @return This builder for chaining. + */ + public Builder setVersionBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + version_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + + private com.google.protobuf.LazyStringArrayList tag_ = com.google.protobuf.LazyStringArrayList.emptyList(); + + private void ensureTagIsMutable() { + if (!tag_.isModifiable()) { + tag_ = new com.google.protobuf.LazyStringArrayList(tag_); + } + bitField0_ |= 0x00000004; + } + + /** + *
+         * The openAPI tags. Each tag is an or condition.
+         * 
+ * + * repeated string tag = 3; + * @return A list containing the tag. + */ + public com.google.protobuf.ProtocolStringList getTagList() { + tag_.makeImmutable(); + return tag_; + } + + /** + *
+         * The openAPI tags. Each tag is an or condition.
+         * 
+ * + * repeated string tag = 3; + * @return The count of tag. + */ + public int getTagCount() { + return tag_.size(); + } + + /** + *
+         * The openAPI tags. Each tag is an or condition.
+         * 
+ * + * repeated string tag = 3; + * @param index The index of the element to return. + * @return The tag at the given index. + */ + public String getTag(int index) { + return tag_.get(index); + } + + /** + *
+         * The openAPI tags. Each tag is an or condition.
+         * 
+ * + * repeated string tag = 3; + * @param index The index of the value to return. + * @return The bytes of the tag at the given index. + */ + public com.google.protobuf.ByteString getTagBytes(int index) { + return tag_.getByteString(index); + } + + /** + *
+         * The openAPI tags. Each tag is an or condition.
+         * 
+ * + * repeated string tag = 3; + * @param index The index to set the value at. + * @param value The tag to set. + * @return This builder for chaining. + */ + public Builder setTag(int index, String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureTagIsMutable(); + tag_.set(index, value); + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + + /** + *
+         * The openAPI tags. Each tag is an or condition.
+         * 
+ * + * repeated string tag = 3; + * @param value The tag to add. + * @return This builder for chaining. + */ + public Builder addTag(String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureTagIsMutable(); + tag_.add(value); + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + + /** + *
+         * The openAPI tags. Each tag is an or condition.
+         * 
+ * + * repeated string tag = 3; + * @param values The tag to add. + * @return This builder for chaining. + */ + public Builder addAllTag(Iterable values) { + ensureTagIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, tag_); + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + + /** + *
+         * The openAPI tags. Each tag is an or condition.
+         * 
+ * + * repeated string tag = 3; + * @return This builder for chaining. + */ + public Builder clearTag() { + tag_ = com.google.protobuf.LazyStringArrayList.emptyList(); + bitField0_ = (bitField0_ & ~0x00000004); + ; + onChanged(); + return this; + } + + /** + *
+         * The openAPI tags. Each tag is an or condition.
+         * 
+ * + * repeated string tag = 3; + * @param value The bytes of the tag to add. + * @return This builder for chaining. + */ + public Builder addTagBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + ensureTagIsMutable(); + tag_.add(value); + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + + private com.google.protobuf.LazyStringArrayList service_ = com.google.protobuf.LazyStringArrayList.emptyList(); + + private void ensureServiceIsMutable() { + if (!service_.isModifiable()) { + service_ = new com.google.protobuf.LazyStringArrayList(service_); + } + bitField0_ |= 0x00000008; + } + + /** + *
+         * The openAPI services. Each service is an or condition.
+         * 
+ * + * repeated string service = 4; + * @return A list containing the service. + */ + public com.google.protobuf.ProtocolStringList getServiceList() { + service_.makeImmutable(); + return service_; + } + + /** + *
+         * The openAPI services. Each service is an or condition.
+         * 
+ * + * repeated string service = 4; + * @return The count of service. + */ + public int getServiceCount() { + return service_.size(); + } + + /** + *
+         * The openAPI services. Each service is an or condition.
+         * 
+ * + * repeated string service = 4; + * @param index The index of the element to return. + * @return The service at the given index. + */ + public String getService(int index) { + return service_.get(index); + } + + /** + *
+         * The openAPI services. Each service is an or condition.
+         * 
+ * + * repeated string service = 4; + * @param index The index of the value to return. + * @return The bytes of the service at the given index. + */ + public com.google.protobuf.ByteString getServiceBytes(int index) { + return service_.getByteString(index); + } + + /** + *
+         * The openAPI services. Each service is an or condition.
+         * 
+ * + * repeated string service = 4; + * @param index The index to set the value at. + * @param value The service to set. + * @return This builder for chaining. + */ + public Builder setService(int index, String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureServiceIsMutable(); + service_.set(index, value); + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + + /** + *
+         * The openAPI services. Each service is an or condition.
+         * 
+ * + * repeated string service = 4; + * @param value The service to add. + * @return This builder for chaining. + */ + public Builder addService(String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureServiceIsMutable(); + service_.add(value); + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + + /** + *
+         * The openAPI services. Each service is an or condition.
+         * 
+ * + * repeated string service = 4; + * @param values The service to add. + * @return This builder for chaining. + */ + public Builder addAllService(Iterable values) { + ensureServiceIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, service_); + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + + /** + *
+         * The openAPI services. Each service is an or condition.
+         * 
+ * + * repeated string service = 4; + * @return This builder for chaining. + */ + public Builder clearService() { + service_ = com.google.protobuf.LazyStringArrayList.emptyList(); + bitField0_ = (bitField0_ & ~0x00000008); + ; + onChanged(); + return this; + } + + /** + *
+         * The openAPI services. Each service is an or condition.
+         * 
+ * + * repeated string service = 4; + * @param value The bytes of the service to add. + * @return This builder for chaining. + */ + public Builder addServiceBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + ensureServiceIsMutable(); + service_.add(value); + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + + private Object openapi_ = ""; + + /** + *
+         * The openAPI specification version, using a major.minor.patch versioning scheme
+         * e.g. 3.0.1, 3.1.0
+         * The default value is '3.0.1'.
+         * 
+ * + * string openapi = 5; + * @return The openapi. + */ + public String getOpenapi() { + Object ref = openapi_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + openapi_ = s; + return s; + } else { + return (String) ref; + } + } + + /** + *
+         * The openAPI specification version, using a major.minor.patch versioning scheme
+         * e.g. 3.0.1, 3.1.0
+         * The default value is '3.0.1'.
+         * 
+ * + * string openapi = 5; + * @return The bytes for openapi. + */ + public com.google.protobuf.ByteString getOpenapiBytes() { + Object ref = openapi_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((String) ref); + openapi_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + *
+         * The openAPI specification version, using a major.minor.patch versioning scheme
+         * e.g. 3.0.1, 3.1.0
+         * The default value is '3.0.1'.
+         * 
+ * + * string openapi = 5; + * @param value The openapi to set. + * @return This builder for chaining. + */ + public Builder setOpenapi(String value) { + if (value == null) { + throw new NullPointerException(); + } + openapi_ = value; + bitField0_ |= 0x00000010; + onChanged(); + return this; + } + + /** + *
+         * The openAPI specification version, using a major.minor.patch versioning scheme
+         * e.g. 3.0.1, 3.1.0
+         * The default value is '3.0.1'.
+         * 
+ * + * string openapi = 5; + * @return This builder for chaining. + */ + public Builder clearOpenapi() { + openapi_ = getDefaultInstance().getOpenapi(); + bitField0_ = (bitField0_ & ~0x00000010); + onChanged(); + return this; + } + + /** + *
+         * The openAPI specification version, using a major.minor.patch versioning scheme
+         * e.g. 3.0.1, 3.1.0
+         * The default value is '3.0.1'.
+         * 
+ * + * string openapi = 5; + * @param value The bytes for openapi to set. + * @return This builder for chaining. + */ + public Builder setOpenapiBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + openapi_ = value; + bitField0_ |= 0x00000010; + onChanged(); + return this; + } + + private int format_ = 0; + + /** + *
+         * The format of the response.
+         * The default value is 'JSON'.
+         * 
+ * + * optional .org.apache.dubbo.metadata.OpenAPIFormat format = 6; + * @return Whether the format field is set. + */ + @Override + public boolean hasFormat() { + return ((bitField0_ & 0x00000020) != 0); + } + + /** + *
+         * The format of the response.
+         * The default value is 'JSON'.
+         * 
+ * + * optional .org.apache.dubbo.metadata.OpenAPIFormat format = 6; + * @return The enum numeric value on the wire for format. + */ + @Override + public int getFormatValue() { + return format_; + } + + /** + *
+         * The format of the response.
+         * The default value is 'JSON'.
+         * 
+ * + * optional .org.apache.dubbo.metadata.OpenAPIFormat format = 6; + * @param value The enum numeric value on the wire for format to set. + * @return This builder for chaining. + */ + public Builder setFormatValue(int value) { + format_ = value; + bitField0_ |= 0x00000020; + onChanged(); + return this; + } + + /** + *
+         * The format of the response.
+         * The default value is 'JSON'.
+         * 
+ * + * optional .org.apache.dubbo.metadata.OpenAPIFormat format = 6; + * @return The format. + */ + @Override + public OpenAPIFormat getFormat() { + OpenAPIFormat result = OpenAPIFormat.forNumber(format_); + return result == null ? OpenAPIFormat.UNRECOGNIZED : result; + } + + /** + *
+         * The format of the response.
+         * The default value is 'JSON'.
+         * 
+ * + * optional .org.apache.dubbo.metadata.OpenAPIFormat format = 6; + * @param value The format to set. + * @return This builder for chaining. + */ + public Builder setFormat(OpenAPIFormat value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000020; + format_ = value.getNumber(); + onChanged(); + return this; + } + + /** + *
+         * The format of the response.
+         * The default value is 'JSON'.
+         * 
+ * + * optional .org.apache.dubbo.metadata.OpenAPIFormat format = 6; + * @return This builder for chaining. + */ + public Builder clearFormat() { + bitField0_ = (bitField0_ & ~0x00000020); + format_ = 0; + onChanged(); + return this; + } + + private boolean pretty_; + + /** + *
+         * Whether to pretty print for json.
+         * The default value is 'false'.
+         * 
+ * + * optional bool pretty = 7; + * @return Whether the pretty field is set. + */ + @Override + public boolean hasPretty() { + return ((bitField0_ & 0x00000040) != 0); + } + + /** + *
+         * Whether to pretty print for json.
+         * The default value is 'false'.
+         * 
+ * + * optional bool pretty = 7; + * @return The pretty. + */ + @Override + public boolean getPretty() { + return pretty_; + } + + /** + *
+         * Whether to pretty print for json.
+         * The default value is 'false'.
+         * 
+ * + * optional bool pretty = 7; + * @param value The pretty to set. + * @return This builder for chaining. + */ + public Builder setPretty(boolean value) { + + pretty_ = value; + bitField0_ |= 0x00000040; + onChanged(); + return this; + } + + /** + *
+         * Whether to pretty print for json.
+         * The default value is 'false'.
+         * 
+ * + * optional bool pretty = 7; + * @return This builder for chaining. + */ + public Builder clearPretty() { + bitField0_ = (bitField0_ & ~0x00000040); + pretty_ = false; + onChanged(); + return this; + } + + @Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @Override + public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:org.apache.dubbo.metadata.OpenAPIRequest) + } + + // @@protoc_insertion_point(class_scope:org.apache.dubbo.metadata.OpenAPIRequest) + private static final OpenAPIRequest DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new OpenAPIRequest(); + } + + public static OpenAPIRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @Override + public OpenAPIRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @Override + public OpenAPIRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIRequestOrBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIRequestOrBuilder.java new file mode 100644 index 00000000000..00e03f260cd --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/OpenAPIRequestOrBuilder.java @@ -0,0 +1,228 @@ +/* + * 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.dubbo.metadata; + +public interface OpenAPIRequestOrBuilder + extends + // @@protoc_insertion_point(interface_extends:org.apache.dubbo.metadata.OpenAPIRequest) + com.google.protobuf.MessageOrBuilder { + + /** + *
+     * The openAPI group.
+     * 
+ * + * string group = 1; + * @return The group. + */ + String getGroup(); + + /** + *
+     * The openAPI group.
+     * 
+ * + * string group = 1; + * @return The bytes for group. + */ + com.google.protobuf.ByteString getGroupBytes(); + + /** + *
+     * The openAPI version, using a major.minor.patch versioning scheme
+     * e.g. 1.0.1
+     * 
+ * + * string version = 2; + * @return The version. + */ + String getVersion(); + + /** + *
+     * The openAPI version, using a major.minor.patch versioning scheme
+     * e.g. 1.0.1
+     * 
+ * + * string version = 2; + * @return The bytes for version. + */ + com.google.protobuf.ByteString getVersionBytes(); + + /** + *
+     * The openAPI tags. Each tag is an or condition.
+     * 
+ * + * repeated string tag = 3; + * @return A list containing the tag. + */ + java.util.List getTagList(); + + /** + *
+     * The openAPI tags. Each tag is an or condition.
+     * 
+ * + * repeated string tag = 3; + * @return The count of tag. + */ + int getTagCount(); + + /** + *
+     * The openAPI tags. Each tag is an or condition.
+     * 
+ * + * repeated string tag = 3; + * @param index The index of the element to return. + * @return The tag at the given index. + */ + String getTag(int index); + + /** + *
+     * The openAPI tags. Each tag is an or condition.
+     * 
+ * + * repeated string tag = 3; + * @param index The index of the value to return. + * @return The bytes of the tag at the given index. + */ + com.google.protobuf.ByteString getTagBytes(int index); + + /** + *
+     * The openAPI services. Each service is an or condition.
+     * 
+ * + * repeated string service = 4; + * @return A list containing the service. + */ + java.util.List getServiceList(); + + /** + *
+     * The openAPI services. Each service is an or condition.
+     * 
+ * + * repeated string service = 4; + * @return The count of service. + */ + int getServiceCount(); + + /** + *
+     * The openAPI services. Each service is an or condition.
+     * 
+ * + * repeated string service = 4; + * @param index The index of the element to return. + * @return The service at the given index. + */ + String getService(int index); + + /** + *
+     * The openAPI services. Each service is an or condition.
+     * 
+ * + * repeated string service = 4; + * @param index The index of the value to return. + * @return The bytes of the service at the given index. + */ + com.google.protobuf.ByteString getServiceBytes(int index); + + /** + *
+     * The openAPI specification version, using a major.minor.patch versioning scheme
+     * e.g. 3.0.1, 3.1.0
+     * The default value is '3.0.1'.
+     * 
+ * + * string openapi = 5; + * @return The openapi. + */ + String getOpenapi(); + + /** + *
+     * The openAPI specification version, using a major.minor.patch versioning scheme
+     * e.g. 3.0.1, 3.1.0
+     * The default value is '3.0.1'.
+     * 
+ * + * string openapi = 5; + * @return The bytes for openapi. + */ + com.google.protobuf.ByteString getOpenapiBytes(); + + /** + *
+     * The format of the response.
+     * The default value is 'JSON'.
+     * 
+ * + * optional .org.apache.dubbo.metadata.OpenAPIFormat format = 6; + * @return Whether the format field is set. + */ + boolean hasFormat(); + + /** + *
+     * The format of the response.
+     * The default value is 'JSON'.
+     * 
+ * + * optional .org.apache.dubbo.metadata.OpenAPIFormat format = 6; + * @return The enum numeric value on the wire for format. + */ + int getFormatValue(); + + /** + *
+     * The format of the response.
+     * The default value is 'JSON'.
+     * 
+ * + * optional .org.apache.dubbo.metadata.OpenAPIFormat format = 6; + * @return The format. + */ + OpenAPIFormat getFormat(); + + /** + *
+     * Whether to pretty print for json.
+     * The default value is 'false'.
+     * 
+ * + * optional bool pretty = 7; + * @return Whether the pretty field is set. + */ + boolean hasPretty(); + + /** + *
+     * Whether to pretty print for json.
+     * The default value is 'false'.
+     * 
+ * + * optional bool pretty = 7; + * @return The pretty. + */ + boolean getPretty(); +} diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2.java index 8da76533c0c..7292671d56c 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2.java @@ -17,13 +17,19 @@ package org.apache.dubbo.metadata; /** + *
+ * Service information message.
+ * 
+ * * Protobuf type {@code org.apache.dubbo.metadata.ServiceInfoV2} */ public final class ServiceInfoV2 extends com.google.protobuf.GeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:org.apache.dubbo.metadata.ServiceInfoV2) ServiceInfoV2OrBuilder { + private static final long serialVersionUID = 0L; + // Use ServiceInfoV2.newBuilder() to construct. private ServiceInfoV2(com.google.protobuf.GeneratedMessageV3.Builder builder) { super(builder); @@ -68,7 +74,12 @@ protected FieldAccessorTable internalGetFieldAccessorTable() { @SuppressWarnings("serial") private volatile Object name_ = ""; + /** + *
+     * The service name.
+     * 
+ * * string name = 1; * @return The name. */ @@ -84,7 +95,12 @@ public String getName() { return s; } } + /** + *
+     * The service name.
+     * 
+ * * string name = 1; * @return The bytes for name. */ @@ -104,7 +120,12 @@ public com.google.protobuf.ByteString getNameBytes() { @SuppressWarnings("serial") private volatile Object group_ = ""; + /** + *
+     * The service group.
+     * 
+ * * string group = 2; * @return The group. */ @@ -120,7 +141,12 @@ public String getGroup() { return s; } } + /** + *
+     * The service group.
+     * 
+ * * string group = 2; * @return The bytes for group. */ @@ -140,7 +166,12 @@ public com.google.protobuf.ByteString getGroupBytes() { @SuppressWarnings("serial") private volatile Object version_ = ""; + /** + *
+     * The service version.
+     * 
+ * * string version = 3; * @return The version. */ @@ -156,7 +187,12 @@ public String getVersion() { return s; } } + /** + *
+     * The service version.
+     * 
+ * * string version = 3; * @return The bytes for version. */ @@ -176,7 +212,12 @@ public com.google.protobuf.ByteString getVersionBytes() { @SuppressWarnings("serial") private volatile Object protocol_ = ""; + /** + *
+     * The service protocol.
+     * 
+ * * string protocol = 4; * @return The protocol. */ @@ -192,7 +233,12 @@ public String getProtocol() { return s; } } + /** + *
+     * The service protocol.
+     * 
+ * * string protocol = 4; * @return The bytes for protocol. */ @@ -210,7 +256,12 @@ public com.google.protobuf.ByteString getProtocolBytes() { public static final int PORT_FIELD_NUMBER = 5; private int port_ = 0; + /** + *
+     * The service port.
+     * 
+ * * int32 port = 5; * @return The port. */ @@ -223,7 +274,12 @@ public int getPort() { @SuppressWarnings("serial") private volatile Object path_ = ""; + /** + *
+     * The service path.
+     * 
+ * * string path = 6; * @return The path. */ @@ -239,7 +295,12 @@ public String getPath() { return s; } } + /** + *
+     * The service path.
+     * 
+ * * string path = 6; * @return The bytes for path. */ @@ -258,6 +319,7 @@ public com.google.protobuf.ByteString getPathBytes() { public static final int PARAMS_FIELD_NUMBER = 7; private static final class ParamsDefaultEntryHolder { + static final com.google.protobuf.MapEntry defaultEntry = com.google.protobuf.MapEntry.newDefaultInstance( MetadataServiceV2OuterClass @@ -281,7 +343,12 @@ private com.google.protobuf.MapField internalGetParams() { public int getParamsCount() { return internalGetParams().getMap().size(); } + /** + *
+     * A map of service parameters.
+     * 
+ * * map<string, string> params = 7; */ @Override @@ -291,6 +358,7 @@ public boolean containsParams(String key) { } return internalGetParams().getMap().containsKey(key); } + /** * Use {@link #getParamsMap()} instead. */ @@ -299,14 +367,24 @@ public boolean containsParams(String key) { public java.util.Map getParams() { return getParamsMap(); } + /** + *
+     * A map of service parameters.
+     * 
+ * * map<string, string> params = 7; */ @Override public java.util.Map getParamsMap() { return internalGetParams().getMap(); } + /** + *
+     * A map of service parameters.
+     * 
+ * * map<string, string> params = 7; */ @Override @@ -320,7 +398,12 @@ public java.util.Map getParamsMap() { java.util.Map map = internalGetParams().getMap(); return map.containsKey(key) ? map.get(key) : defaultValue; } + /** + *
+     * A map of service parameters.
+     * 
+ * * map<string, string> params = 7; */ @Override @@ -340,8 +423,12 @@ public String getParamsOrThrow(String key) { @Override public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; + if (isInitialized == 1) { + return true; + } + if (isInitialized == 0) { + return false; + } memoizedIsInitialized = 1; return true; @@ -375,7 +462,9 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io @Override public int getSerializedSize() { int size = memoizedSize; - if (size != -1) return size; + if (size != -1) { + return size; + } size = 0; if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { @@ -420,14 +509,30 @@ public boolean equals(final Object obj) { } ServiceInfoV2 other = (ServiceInfoV2) obj; - if (!getName().equals(other.getName())) return false; - if (!getGroup().equals(other.getGroup())) return false; - if (!getVersion().equals(other.getVersion())) return false; - if (!getProtocol().equals(other.getProtocol())) return false; - if (getPort() != other.getPort()) return false; - if (!getPath().equals(other.getPath())) return false; - if (!internalGetParams().equals(other.internalGetParams())) return false; - if (!getUnknownFields().equals(other.getUnknownFields())) return false; + if (!getName().equals(other.getName())) { + return false; + } + if (!getGroup().equals(other.getGroup())) { + return false; + } + if (!getVersion().equals(other.getVersion())) { + return false; + } + if (!getProtocol().equals(other.getProtocol())) { + return false; + } + if (getPort() != other.getPort()) { + return false; + } + if (!getPath().equals(other.getPath())) { + return false; + } + if (!internalGetParams().equals(other.internalGetParams())) { + return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) { + return false; + } return true; } @@ -543,13 +648,19 @@ protected Builder newBuilderForType(BuilderParent parent) { Builder builder = new Builder(parent); return builder; } + /** + *
+     * Service information message.
+     * 
+ * * Protobuf type {@code org.apache.dubbo.metadata.ServiceInfoV2} */ public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:org.apache.dubbo.metadata.ServiceInfoV2) ServiceInfoV2OrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return MetadataServiceV2OuterClass.internal_static_org_apache_dubbo_metadata_ServiceInfoV2_descriptor; } @@ -657,6 +768,37 @@ private void buildPartial0(ServiceInfoV2 result) { } } + @Override + public Builder clone() { + return super.clone(); + } + + @Override + public Builder setField(com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { + return super.setField(field, value); + } + + @Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, Object value) { + return super.setRepeatedField(field, index, value); + } + + @Override + public Builder addRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { + return super.addRepeatedField(field, value); + } + @Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof ServiceInfoV2) { @@ -668,7 +810,9 @@ public Builder mergeFrom(com.google.protobuf.Message other) { } public Builder mergeFrom(ServiceInfoV2 other) { - if (other == ServiceInfoV2.getDefaultInstance()) return this; + if (other == ServiceInfoV2.getDefaultInstance()) { + return this; + } if (!other.getName().isEmpty()) { name_ = other.name_; bitField0_ |= 0x00000001; @@ -780,7 +924,12 @@ public Builder mergeFrom( private int bitField0_; private Object name_ = ""; + /** + *
+         * The service name.
+         * 
+ * * string name = 1; * @return The name. */ @@ -795,7 +944,12 @@ public String getName() { return (String) ref; } } + /** + *
+         * The service name.
+         * 
+ * * string name = 1; * @return The bytes for name. */ @@ -809,7 +963,12 @@ public com.google.protobuf.ByteString getNameBytes() { return (com.google.protobuf.ByteString) ref; } } + /** + *
+         * The service name.
+         * 
+ * * string name = 1; * @param value The name to set. * @return This builder for chaining. @@ -823,7 +982,12 @@ public Builder setName(String value) { onChanged(); return this; } + /** + *
+         * The service name.
+         * 
+ * * string name = 1; * @return This builder for chaining. */ @@ -833,7 +997,12 @@ public Builder clearName() { onChanged(); return this; } + /** + *
+         * The service name.
+         * 
+ * * string name = 1; * @param value The bytes for name to set. * @return This builder for chaining. @@ -850,7 +1019,12 @@ public Builder setNameBytes(com.google.protobuf.ByteString value) { } private Object group_ = ""; + /** + *
+         * The service group.
+         * 
+ * * string group = 2; * @return The group. */ @@ -865,7 +1039,12 @@ public String getGroup() { return (String) ref; } } + /** + *
+         * The service group.
+         * 
+ * * string group = 2; * @return The bytes for group. */ @@ -879,7 +1058,12 @@ public com.google.protobuf.ByteString getGroupBytes() { return (com.google.protobuf.ByteString) ref; } } + /** + *
+         * The service group.
+         * 
+ * * string group = 2; * @param value The group to set. * @return This builder for chaining. @@ -893,7 +1077,12 @@ public Builder setGroup(String value) { onChanged(); return this; } + /** + *
+         * The service group.
+         * 
+ * * string group = 2; * @return This builder for chaining. */ @@ -903,7 +1092,12 @@ public Builder clearGroup() { onChanged(); return this; } + /** + *
+         * The service group.
+         * 
+ * * string group = 2; * @param value The bytes for group to set. * @return This builder for chaining. @@ -920,7 +1114,12 @@ public Builder setGroupBytes(com.google.protobuf.ByteString value) { } private Object version_ = ""; + /** + *
+         * The service version.
+         * 
+ * * string version = 3; * @return The version. */ @@ -935,7 +1134,12 @@ public String getVersion() { return (String) ref; } } + /** + *
+         * The service version.
+         * 
+ * * string version = 3; * @return The bytes for version. */ @@ -949,7 +1153,12 @@ public com.google.protobuf.ByteString getVersionBytes() { return (com.google.protobuf.ByteString) ref; } } + /** + *
+         * The service version.
+         * 
+ * * string version = 3; * @param value The version to set. * @return This builder for chaining. @@ -963,7 +1172,12 @@ public Builder setVersion(String value) { onChanged(); return this; } + /** + *
+         * The service version.
+         * 
+ * * string version = 3; * @return This builder for chaining. */ @@ -973,7 +1187,12 @@ public Builder clearVersion() { onChanged(); return this; } + /** + *
+         * The service version.
+         * 
+ * * string version = 3; * @param value The bytes for version to set. * @return This builder for chaining. @@ -990,7 +1209,12 @@ public Builder setVersionBytes(com.google.protobuf.ByteString value) { } private Object protocol_ = ""; + /** + *
+         * The service protocol.
+         * 
+ * * string protocol = 4; * @return The protocol. */ @@ -1005,7 +1229,12 @@ public String getProtocol() { return (String) ref; } } + /** + *
+         * The service protocol.
+         * 
+ * * string protocol = 4; * @return The bytes for protocol. */ @@ -1019,7 +1248,12 @@ public com.google.protobuf.ByteString getProtocolBytes() { return (com.google.protobuf.ByteString) ref; } } + /** + *
+         * The service protocol.
+         * 
+ * * string protocol = 4; * @param value The protocol to set. * @return This builder for chaining. @@ -1033,7 +1267,12 @@ public Builder setProtocol(String value) { onChanged(); return this; } + /** + *
+         * The service protocol.
+         * 
+ * * string protocol = 4; * @return This builder for chaining. */ @@ -1043,7 +1282,12 @@ public Builder clearProtocol() { onChanged(); return this; } + /** + *
+         * The service protocol.
+         * 
+ * * string protocol = 4; * @param value The bytes for protocol to set. * @return This builder for chaining. @@ -1060,7 +1304,12 @@ public Builder setProtocolBytes(com.google.protobuf.ByteString value) { } private int port_; + /** + *
+         * The service port.
+         * 
+ * * int32 port = 5; * @return The port. */ @@ -1068,7 +1317,12 @@ public Builder setProtocolBytes(com.google.protobuf.ByteString value) { public int getPort() { return port_; } + /** + *
+         * The service port.
+         * 
+ * * int32 port = 5; * @param value The port to set. * @return This builder for chaining. @@ -1080,7 +1334,12 @@ public Builder setPort(int value) { onChanged(); return this; } + /** + *
+         * The service port.
+         * 
+ * * int32 port = 5; * @return This builder for chaining. */ @@ -1092,7 +1351,12 @@ public Builder clearPort() { } private Object path_ = ""; + /** + *
+         * The service path.
+         * 
+ * * string path = 6; * @return The path. */ @@ -1107,7 +1371,12 @@ public String getPath() { return (String) ref; } } + /** + *
+         * The service path.
+         * 
+ * * string path = 6; * @return The bytes for path. */ @@ -1121,7 +1390,12 @@ public com.google.protobuf.ByteString getPathBytes() { return (com.google.protobuf.ByteString) ref; } } + /** + *
+         * The service path.
+         * 
+ * * string path = 6; * @param value The path to set. * @return This builder for chaining. @@ -1135,7 +1409,12 @@ public Builder setPath(String value) { onChanged(); return this; } + /** + *
+         * The service path.
+         * 
+ * * string path = 6; * @return This builder for chaining. */ @@ -1145,7 +1424,12 @@ public Builder clearPath() { onChanged(); return this; } + /** + *
+         * The service path.
+         * 
+ * * string path = 6; * @param value The bytes for path to set. * @return This builder for chaining. @@ -1185,7 +1469,12 @@ private com.google.protobuf.MapField internalGetMutableParams() public int getParamsCount() { return internalGetParams().getMap().size(); } + /** + *
+         * A map of service parameters.
+         * 
+ * * map<string, string> params = 7; */ @Override @@ -1195,6 +1484,7 @@ public boolean containsParams(String key) { } return internalGetParams().getMap().containsKey(key); } + /** * Use {@link #getParamsMap()} instead. */ @@ -1203,14 +1493,24 @@ public boolean containsParams(String key) { public java.util.Map getParams() { return getParamsMap(); } + /** + *
+         * A map of service parameters.
+         * 
+ * * map<string, string> params = 7; */ @Override public java.util.Map getParamsMap() { return internalGetParams().getMap(); } + /** + *
+         * A map of service parameters.
+         * 
+ * * map<string, string> params = 7; */ @Override @@ -1224,7 +1524,12 @@ public java.util.Map getParamsMap() { java.util.Map map = internalGetParams().getMap(); return map.containsKey(key) ? map.get(key) : defaultValue; } + /** + *
+         * A map of service parameters.
+         * 
+ * * map<string, string> params = 7; */ @Override @@ -1244,7 +1549,12 @@ public Builder clearParams() { internalGetMutableParams().getMutableMap().clear(); return this; } + /** + *
+         * A map of service parameters.
+         * 
+ * * map<string, string> params = 7; */ public Builder removeParams(String key) { @@ -1254,6 +1564,7 @@ public Builder removeParams(String key) { internalGetMutableParams().getMutableMap().remove(key); return this; } + /** * Use alternate mutation accessors instead. */ @@ -1262,7 +1573,12 @@ public java.util.Map getMutableParams() { bitField0_ |= 0x00000040; return internalGetMutableParams().getMutableMap(); } + /** + *
+         * A map of service parameters.
+         * 
+ * * map<string, string> params = 7; */ public Builder putParams(String key, String value) { @@ -1276,7 +1592,12 @@ public Builder putParams(String key, String value) { bitField0_ |= 0x00000040; return this; } + /** + *
+         * A map of service parameters.
+         * 
+ * * map<string, string> params = 7; */ public Builder putAllParams(java.util.Map values) { diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2OrBuilder.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2OrBuilder.java index 6c39dd594fc..3daacf0d100 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2OrBuilder.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/ServiceInfoV2OrBuilder.java @@ -22,84 +22,153 @@ public interface ServiceInfoV2OrBuilder com.google.protobuf.MessageOrBuilder { /** + *
+     * The service name.
+     * 
+ * * string name = 1; * @return The name. */ String getName(); + /** + *
+     * The service name.
+     * 
+ * * string name = 1; * @return The bytes for name. */ com.google.protobuf.ByteString getNameBytes(); /** + *
+     * The service group.
+     * 
+ * * string group = 2; * @return The group. */ String getGroup(); + /** + *
+     * The service group.
+     * 
+ * * string group = 2; * @return The bytes for group. */ com.google.protobuf.ByteString getGroupBytes(); /** + *
+     * The service version.
+     * 
+ * * string version = 3; * @return The version. */ String getVersion(); + /** + *
+     * The service version.
+     * 
+ * * string version = 3; * @return The bytes for version. */ com.google.protobuf.ByteString getVersionBytes(); /** + *
+     * The service protocol.
+     * 
+ * * string protocol = 4; * @return The protocol. */ String getProtocol(); + /** + *
+     * The service protocol.
+     * 
+ * * string protocol = 4; * @return The bytes for protocol. */ com.google.protobuf.ByteString getProtocolBytes(); /** + *
+     * The service port.
+     * 
+ * * int32 port = 5; * @return The port. */ int getPort(); /** + *
+     * The service path.
+     * 
+ * * string path = 6; * @return The path. */ String getPath(); + /** + *
+     * The service path.
+     * 
+ * * string path = 6; * @return The bytes for path. */ com.google.protobuf.ByteString getPathBytes(); /** + *
+     * A map of service parameters.
+     * 
+ * * map<string, string> params = 7; */ int getParamsCount(); + /** + *
+     * A map of service parameters.
+     * 
+ * * map<string, string> params = 7; */ boolean containsParams(String key); + /** * Use {@link #getParamsMap()} instead. */ @Deprecated java.util.Map getParams(); + /** + *
+     * A map of service parameters.
+     * 
+ * * map<string, string> params = 7; */ java.util.Map getParamsMap(); + /** + *
+     * A map of service parameters.
+     * 
+ * * map<string, string> params = 7; */ /* nullable */ @@ -107,7 +176,12 @@ String getParamsOrDefault( String key, /* nullable */ String defaultValue); + /** + *
+     * A map of service parameters.
+     * 
+ * * map<string, string> params = 7; */ String getParamsOrThrow(String key); diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/proto/metadata_service_v2.proto b/dubbo-metadata/dubbo-metadata-api/src/main/proto/metadata_service_v2.proto index 77c49d1021e..b47678d21d5 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/proto/metadata_service_v2.proto +++ b/dubbo-metadata/dubbo-metadata-api/src/main/proto/metadata_service_v2.proto @@ -22,26 +22,85 @@ option go_package = "dubbo.apache.org/dubbo-go/v3/metadata/triple_api;triple_api option java_package = "org.apache.dubbo.metadata"; option java_multiple_files = true; +// Metadata service V2. service MetadataServiceV2{ + + // Retrieves metadata information. rpc GetMetadataInfo(MetadataRequest) returns (MetadataInfoV2); + + // Retrieves OpenAPI. + rpc GetOpenAPI(OpenAPIRequest) returns (OpenAPI); } +// Metadata request message. message MetadataRequest{ + // The revision of the metadata. string revision = 1; } +// Metadata information message. message MetadataInfoV2{ + // The application name. string app = 1; + // The application version. string version = 2; + // A map of service information. map services = 3; } +// Service information message. message ServiceInfoV2{ + // The service name. string name = 1; + // The service group. string group = 2; + // The service version. string version = 3; + // The service protocol. string protocol = 4; + // The service port. int32 port = 5; + // The service path. string path = 6; + // A map of service parameters. map params = 7; } + +// OpenAPI request message. +message OpenAPIRequest { + // The openAPI group. + string group = 1; + // The openAPI version, using a major.minor.patch versioning scheme + // e.g. 1.0.1 + string version = 2; + // The openAPI tags. Each tag is an or condition. + repeated string tag = 3; + // The openAPI services. Each service is an or condition. + repeated string service = 4; + // The openAPI specification version, using a major.minor.patch versioning scheme + // e.g. 3.0.1, 3.1.0 + // The default value is '3.0.1'. + string openapi = 5; + // The format of the response. + // The default value is 'JSON'. + optional OpenAPIFormat format = 6; + // Whether to pretty print for json. + // The default value is 'false'. + optional bool pretty = 7; +} + +// Response format enumeration. +enum OpenAPIFormat { + // JSON format. + JSON = 0; + // YAML format. + YAML = 1; + // PROTO format. + PROTO = 2; +} + +// OpenAPI message. +message OpenAPI { + // The value of the OpenAPI. + string value = 1; +} diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/GetOpenAPI.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/GetOpenAPI.java new file mode 100644 index 00000000000..e8938d0d839 --- /dev/null +++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/GetOpenAPI.java @@ -0,0 +1,95 @@ +/* + * 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.dubbo.qos.command.impl; + +import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.qos.api.BaseCommand; +import org.apache.dubbo.qos.api.Cmd; +import org.apache.dubbo.qos.api.CommandContext; +import org.apache.dubbo.qos.api.PermissionLevel; +import org.apache.dubbo.remoting.http12.rest.OpenAPIRequest; +import org.apache.dubbo.remoting.http12.rest.OpenAPIService; +import org.apache.dubbo.rpc.model.FrameworkModel; + +@Cmd( + name = "getOpenAPI", + summary = "Get the openapi descriptor for specified services.", + example = { + "getOpenAPI", + "getOpenAPI groupA", + "getOpenAPI com.example.DemoService", + "getOpenAPI --group groupA --version 1.1.0 --tag tagA --service com.example. --openapi 3.0.0 --format yaml", + }, + requiredPermissionLevel = PermissionLevel.PRIVATE) +public class GetOpenAPI implements BaseCommand { + + private final FrameworkModel frameworkModel; + + public GetOpenAPI(FrameworkModel frameworkModel) { + this.frameworkModel = frameworkModel; + } + + @Override + public String execute(CommandContext commandContext, String[] args) { + OpenAPIService openAPIService = frameworkModel.getDefaultExtensionOrNull(OpenAPIService.class); + if (openAPIService == null) { + return "OpenAPI is not available"; + } + + OpenAPIRequest request = new OpenAPIRequest(); + + int len = args.length; + if (len > 0) { + if (len == 1) { + String arg0 = args[0]; + if (arg0.indexOf('.') > 0) { + request.setService(new String[] {arg0}); + } else { + request.setGroup(arg0); + } + } else { + for (int i = 0; i < len; i += 2) { + String value = args[i + 1]; + switch (StringUtils.substringAfterLast(args[i], '-')) { + case "group": + request.setGroup(value); + break; + case "version": + request.setVersion(value); + break; + case "tag": + request.setTag(StringUtils.tokenize(value)); + break; + case "service": + request.setService(StringUtils.tokenize(value)); + break; + case "openapi": + request.setOpenapi(value); + break; + case "format": + request.setFormat(value); + break; + default: + break; + } + } + } + } + + return openAPIService.getDocument(request); + } +} diff --git a/dubbo-plugin/dubbo-qos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.qos.api.BaseCommand b/dubbo-plugin/dubbo-qos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.qos.api.BaseCommand index a837d2b7024..9a336915e1b 100644 --- a/dubbo-plugin/dubbo-qos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.qos.api.BaseCommand +++ b/dubbo-plugin/dubbo-qos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.qos.api.BaseCommand @@ -38,3 +38,4 @@ getConfig=org.apache.dubbo.qos.command.impl.GetConfig getAddress=org.apache.dubbo.qos.command.impl.GetAddress gracefulShutdown=org.apache.dubbo.qos.command.impl.GracefulShutdown metrics_default=org.apache.dubbo.qos.command.impl.DefaultMetricsReporterCmd +getOpenAPI=org.apache.dubbo.qos.command.impl.GetOpenAPI diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java index b2443ec9bfb..238b1421dd0 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java @@ -29,6 +29,7 @@ import org.apache.dubbo.qos.command.impl.GetAddress; import org.apache.dubbo.qos.command.impl.GetConfig; import org.apache.dubbo.qos.command.impl.GetEnabledRouterSnapshot; +import org.apache.dubbo.qos.command.impl.GetOpenAPI; import org.apache.dubbo.qos.command.impl.GetRecentRouterSnapshot; import org.apache.dubbo.qos.command.impl.GetRouterSnapshot; import org.apache.dubbo.qos.command.impl.GracefulShutdown; @@ -127,6 +128,7 @@ void testGetAllCommandClass() { expectedClasses.add(GetAddress.class); expectedClasses.add(GracefulShutdown.class); expectedClasses.add(DefaultMetricsReporterCmd.class); + expectedClasses.add(GetOpenAPI.class); assertThat(classes, containsInAnyOrder(expectedClasses.toArray(new Class[0]))); } diff --git a/dubbo-plugin/dubbo-rest-jaxrs/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/jaxrs/JaxrsRequestMappingResolver.java b/dubbo-plugin/dubbo-rest-jaxrs/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/jaxrs/JaxrsRequestMappingResolver.java index acf619d7b2a..e2ee07c12e9 100644 --- a/dubbo-plugin/dubbo-rest-jaxrs/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/jaxrs/JaxrsRequestMappingResolver.java +++ b/dubbo-plugin/dubbo-rest-jaxrs/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/jaxrs/JaxrsRequestMappingResolver.java @@ -17,6 +17,7 @@ package org.apache.dubbo.rpc.protocol.tri.rest.support.jaxrs; import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.config.nested.RestConfig; import org.apache.dubbo.rpc.model.FrameworkModel; import org.apache.dubbo.rpc.protocol.tri.rest.cors.CorsUtils; import org.apache.dubbo.rpc.protocol.tri.rest.mapping.RequestMapping; @@ -32,12 +33,11 @@ @Activate(onClass = {"javax.ws.rs.Path", "javax.ws.rs.container.ContainerRequestContext"}) public class JaxrsRequestMappingResolver implements RequestMappingResolver { - private final FrameworkModel frameworkModel; private final RestToolKit toolKit; + private RestConfig restConfig; private CorsMeta globalCorsMeta; public JaxrsRequestMappingResolver(FrameworkModel frameworkModel) { - this.frameworkModel = frameworkModel; toolKit = new JaxrsRestToolKit(frameworkModel); } @@ -46,6 +46,11 @@ public RestToolKit getRestToolKit() { return toolKit; } + @Override + public void setRestConfig(RestConfig restConfig) { + this.restConfig = restConfig; + } + @Override public RequestMapping resolve(ServiceMeta serviceMeta) { AnnotationMeta path = serviceMeta.findAnnotation(Annotations.Path); @@ -70,7 +75,7 @@ public RequestMapping resolve(MethodMeta methodMeta) { } ServiceMeta serviceMeta = methodMeta.getServiceMeta(); if (globalCorsMeta == null) { - globalCorsMeta = CorsUtils.getGlobalCorsMeta(frameworkModel); + globalCorsMeta = CorsUtils.getGlobalCorsMeta(restConfig); } return builder(methodMeta, path, httpMethod) .name(methodMeta.getMethod().getName()) diff --git a/dubbo-plugin/dubbo-rest-swagger/pom.xml b/dubbo-plugin/dubbo-rest-openapi/pom.xml similarity index 98% rename from dubbo-plugin/dubbo-rest-swagger/pom.xml rename to dubbo-plugin/dubbo-rest-openapi/pom.xml index 472b75feda6..f3199369f92 100644 --- a/dubbo-plugin/dubbo-rest-swagger/pom.xml +++ b/dubbo-plugin/dubbo-rest-openapi/pom.xml @@ -24,7 +24,7 @@ ../../pom.xml - dubbo-rest-swagger + dubbo-rest-openapi 2.2.25 diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/AbstractContext.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/AbstractContext.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/AbstractContext.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/AbstractContext.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ConfigFactory.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ConfigFactory.java similarity index 96% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ConfigFactory.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ConfigFactory.java index 9d8a54687f1..8786e334fb8 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ConfigFactory.java +++ b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ConfigFactory.java @@ -44,11 +44,6 @@ public ConfigFactory(FrameworkModel frameworkModel) { this.frameworkModel = frameworkModel; } - public static boolean isOpenAPIEnabled(FrameworkModel frameworkModel) { - Environment environment = getEnvironment(frameworkModel); - return environment.getConfiguration().getBoolean(H2_SETTINGS_OPENAPI_PREFIX + ".enabled", false); - } - private static Environment getEnvironment(FrameworkModel frameworkModel) { return frameworkModel.defaultApplication().modelEnvironment(); } diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Constants.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Constants.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Constants.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Constants.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Context.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Context.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Context.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Context.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ContextImpl.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ContextImpl.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ContextImpl.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ContextImpl.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefaultOpenAPINamingStrategy.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefaultOpenAPINamingStrategy.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefaultOpenAPINamingStrategy.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefaultOpenAPINamingStrategy.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefaultOpenAPIService.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefaultOpenAPIService.java similarity index 97% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefaultOpenAPIService.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefaultOpenAPIService.java index a7c4538fc5d..a991562a957 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefaultOpenAPIService.java +++ b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefaultOpenAPIService.java @@ -28,6 +28,7 @@ import org.apache.dubbo.remoting.http12.exception.HttpResultPayloadException; import org.apache.dubbo.remoting.http12.message.MediaType; import org.apache.dubbo.remoting.http12.rest.OpenAPIRequest; +import org.apache.dubbo.remoting.http12.rest.OpenAPIService; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.model.FrameworkModel; import org.apache.dubbo.rpc.protocol.tri.ExceptionUtils; @@ -72,7 +73,6 @@ public class DefaultOpenAPIService implements OpenAPIRequestHandler, OpenAPIServ private final DefinitionFilter definitionFilter; private final DefinitionEncoder definitionEncoder; private final RadixTree tree; - private RequestMappingRegistry requestMappingRegistry; private volatile List openAPIs; private boolean exported; @@ -89,10 +89,6 @@ public DefaultOpenAPIService(FrameworkModel frameworkModel) { tree = initRequestHandlers(); } - public void setRequestMappingRegistry(RequestMappingRegistry requestMappingRegistry) { - this.requestMappingRegistry = requestMappingRegistry; - } - private RadixTree initRequestHandlers() { RadixTree tree = new RadixTree<>(false); for (OpenAPIRequestHandler handler : extensionFactory.getExtensions(OpenAPIRequestHandler.class)) { @@ -133,7 +129,6 @@ public Collection getOpenAPIGroups() { return groups; } - @Override public OpenAPI getOpenAPI(OpenAPIRequest request) { return definitionFilter.filter(definitionMerger.merge(getOpenAPIs(), request), request); } @@ -150,8 +145,13 @@ private List getOpenAPIs() { } private List resolveOpenAPIs() { + RequestMappingRegistry registry = frameworkModel.getBean(RequestMappingRegistry.class); + if (registry == null) { + return Collections.emptyList(); + } + Map>> byClassMap = new HashMap<>(); - for (Registration registration : requestMappingRegistry.getRegistrations()) { + for (Registration registration : registry.getRegistrations()) { HandlerMeta meta = registration.getMeta(); byClassMap .computeIfAbsent(new Key(meta.getService()), k -> new IdentityHashMap<>()) diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionEncoder.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionEncoder.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionEncoder.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionEncoder.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionFilter.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionFilter.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionFilter.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionFilter.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionMerger.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionMerger.java similarity index 98% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionMerger.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionMerger.java index f8be87a0165..e2814aed4fb 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionMerger.java +++ b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionMerger.java @@ -415,8 +415,12 @@ private void mergeTags(OpenAPI target, OpenAPI source) { } private void addSchemas(OpenAPI target, String version, String group) { + Map paths = target.getPaths(); + if (paths == null) { + return; + } Map schemas = new IdentityHashMap<>(); - for (PathItem pathItem : target.getPaths().values()) { + for (PathItem pathItem : paths.values()) { Map operations = pathItem.getOperations(); if (operations == null) { continue; @@ -624,6 +628,9 @@ private void completeModel(OpenAPI target) { if (info.getVersion() == null) { info.setVersion("v1"); } + if (CollectionUtils.isEmptyMap(target.getPaths())) { + return; + } ExternalDocs docs = target.getExternalDocs(); if (docs.getUrl() == null && docs.getDescription() == null) { docs.setUrl("../redoc/index.html?group=" + target.getGroup()).setDescription("ReDoc"); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionResolver.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionResolver.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionResolver.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/DefinitionResolver.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ExtensionFactory.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ExtensionFactory.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ExtensionFactory.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ExtensionFactory.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Helper.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Helper.java similarity index 93% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Helper.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Helper.java index 729b3205d07..1a17514acad 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Helper.java +++ b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/Helper.java @@ -33,7 +33,10 @@ import java.util.List; import java.util.Map; import java.util.function.Consumer; +import java.util.function.Function; import java.util.function.Supplier; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import static org.apache.dubbo.remoting.http12.HttpMethods.DELETE; import static org.apache.dubbo.remoting.http12.HttpMethods.GET; @@ -75,6 +78,8 @@ public final class Helper { {DELETE.name(), "delete", "remove", "erase", "destroy", "drop"} }; + private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("\\{\\{([\\w.-]+)}}"); + private Helper() {} public static Collection guessHttpMethod(MethodMeta method) { @@ -170,7 +175,7 @@ public static OpenAPIRequest formatRequest(OpenAPIRequest request) { } request.setService(service); - request.setVersion(trim(request.getVersion())); + request.setOpenapi(trim(request.getOpenapi())); request.setFormat(trim(request.getFormat())); return request; } @@ -326,4 +331,18 @@ public static boolean isVersionGreaterOrEqual(String version1, String version2) } return true; } + + public static String render(String text, Function fn) { + if (text == null) { + return null; + } + Matcher matcher = PLACEHOLDER_PATTERN.matcher(text); + StringBuffer result = new StringBuffer(text.length()); + while (matcher.find()) { + String value = fn.apply(matcher.group(1)); + matcher.appendReplacement(result, value == null ? StringUtils.EMPTY_STRING : value); + } + matcher.appendTail(result); + return result.toString(); + } } diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIDefinitionResolver.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIDefinitionResolver.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIDefinitionResolver.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIDefinitionResolver.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIDocumentPublisher.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIDocumentPublisher.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIDocumentPublisher.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIDocumentPublisher.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIExtension.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIExtension.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIExtension.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIExtension.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIFilter.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIFilter.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIFilter.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIFilter.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPINamingStrategy.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPINamingStrategy.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPINamingStrategy.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPINamingStrategy.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIRequestHandler.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIRequestHandler.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIRequestHandler.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIRequestHandler.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPISchemaPredicate.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPISchemaPredicate.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPISchemaPredicate.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPISchemaPredicate.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPISchemaResolver.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPISchemaResolver.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPISchemaResolver.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPISchemaResolver.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/PrimitiveSchema.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/PrimitiveSchema.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/PrimitiveSchema.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/PrimitiveSchema.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ProtoEncoder.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ProtoEncoder.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ProtoEncoder.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/ProtoEncoder.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/SchemaResolver.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/SchemaResolver.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/SchemaResolver.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/SchemaResolver.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ApiResponse.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ApiResponse.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ApiResponse.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ApiResponse.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Components.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Components.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Components.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Components.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Contact.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Contact.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Contact.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Contact.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Discriminator.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Discriminator.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Discriminator.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Discriminator.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Encoding.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Encoding.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Encoding.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Encoding.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Example.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Example.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Example.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Example.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ExternalDocs.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ExternalDocs.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ExternalDocs.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ExternalDocs.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Header.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Header.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Header.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Header.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Info.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Info.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Info.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Info.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/License.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/License.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/License.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/License.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/MediaType.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/MediaType.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/MediaType.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/MediaType.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Node.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Node.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Node.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Node.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OAuthFlow.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OAuthFlow.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OAuthFlow.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OAuthFlow.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OAuthFlows.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OAuthFlows.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OAuthFlows.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OAuthFlows.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OpenAPI.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OpenAPI.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OpenAPI.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/OpenAPI.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Operation.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Operation.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Operation.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Operation.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Parameter.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Parameter.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Parameter.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Parameter.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/PathItem.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/PathItem.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/PathItem.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/PathItem.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/RequestBody.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/RequestBody.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/RequestBody.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/RequestBody.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Schema.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Schema.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Schema.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Schema.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/SecurityRequirement.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/SecurityRequirement.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/SecurityRequirement.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/SecurityRequirement.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/SecurityScheme.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/SecurityScheme.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/SecurityScheme.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/SecurityScheme.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Server.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Server.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Server.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Server.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ServerVariable.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ServerVariable.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ServerVariable.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/ServerVariable.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Tag.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Tag.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Tag.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/Tag.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/XML.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/XML.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/XML.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/model/XML.java diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/BasicOpenAPIDefinitionResolver.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/BasicOpenAPIDefinitionResolver.java similarity index 100% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/BasicOpenAPIDefinitionResolver.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/BasicOpenAPIDefinitionResolver.java diff --git a/dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/JavadocOpenAPIDefinitionResolver.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/JavadocOpenAPIDefinitionResolver.java similarity index 100% rename from dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/JavadocOpenAPIDefinitionResolver.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/JavadocOpenAPIDefinitionResolver.java diff --git a/dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/RedocRequestHandler.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/RedocRequestHandler.java similarity index 98% rename from dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/RedocRequestHandler.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/RedocRequestHandler.java index 0469ab8e202..3407a94bab4 100644 --- a/dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/RedocRequestHandler.java +++ b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/RedocRequestHandler.java @@ -28,6 +28,7 @@ import org.apache.dubbo.rpc.model.FrameworkModel; import org.apache.dubbo.rpc.protocol.tri.rest.openapi.ConfigFactory; import org.apache.dubbo.rpc.protocol.tri.rest.openapi.Constants; +import org.apache.dubbo.rpc.protocol.tri.rest.openapi.Helper; import org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIRequestHandler; import org.apache.dubbo.rpc.protocol.tri.rest.util.PathUtils; import org.apache.dubbo.rpc.protocol.tri.rest.util.RequestUtils; diff --git a/dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/SwaggerOpenAPIDefinitionResolver.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/SwaggerOpenAPIDefinitionResolver.java similarity index 100% rename from dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/SwaggerOpenAPIDefinitionResolver.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/SwaggerOpenAPIDefinitionResolver.java diff --git a/dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/SwaggerUIRequestHandler.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/SwaggerUIRequestHandler.java similarity index 93% rename from dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/SwaggerUIRequestHandler.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/SwaggerUIRequestHandler.java index 67cd6f25652..37010f92fe6 100644 --- a/dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/SwaggerUIRequestHandler.java +++ b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/SwaggerUIRequestHandler.java @@ -26,10 +26,11 @@ import org.apache.dubbo.remoting.http12.HttpResult; import org.apache.dubbo.remoting.http12.HttpStatus; import org.apache.dubbo.remoting.http12.exception.HttpStatusException; +import org.apache.dubbo.remoting.http12.rest.OpenAPIService; import org.apache.dubbo.rpc.model.FrameworkModel; import org.apache.dubbo.rpc.protocol.tri.rest.openapi.ConfigFactory; +import org.apache.dubbo.rpc.protocol.tri.rest.openapi.Helper; import org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIRequestHandler; -import org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIService; import org.apache.dubbo.rpc.protocol.tri.rest.util.PathUtils; import org.apache.dubbo.rpc.protocol.tri.rest.util.RequestUtils; @@ -131,7 +132,11 @@ private HttpResult handleIndex() { } private HttpResult handleSwaggerConfig() { - Collection groups = frameworkModel.getBean(OpenAPIService.class).getOpenAPIGroups(); + OpenAPIService openAPIService = frameworkModel.getDefaultExtensionOrNull(OpenAPIService.class); + if (openAPIService == null) { + return HttpResult.notFound(); + } + Collection groups = openAPIService.getOpenAPIGroups(); List> urls = new ArrayList<>(); for (String group : groups) { Map url = new LinkedHashMap<>(4); diff --git a/dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/WebjarHelper.java b/dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/WebjarHelper.java similarity index 100% rename from dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/WebjarHelper.java rename to dubbo-plugin/dubbo-rest-openapi/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/WebjarHelper.java diff --git a/dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.rest.OpenAPIService b/dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.rest.OpenAPIService new file mode 100644 index 00000000000..b98343397d1 --- /dev/null +++ b/dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.rest.OpenAPIService @@ -0,0 +1 @@ +default=org.apache.dubbo.rpc.protocol.tri.rest.openapi.DefaultOpenAPIService diff --git a/dubbo-plugin/dubbo-rest-swagger/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension b/dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension similarity index 66% rename from dubbo-plugin/dubbo-rest-swagger/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension rename to dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension index 68c769ce618..74eb520bcad 100644 --- a/dubbo-plugin/dubbo-rest-swagger/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension +++ b/dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension @@ -1,4 +1,6 @@ +resolver-basic=org.apache.dubbo.rpc.protocol.tri.rest.support.basic.BasicOpenAPIDefinitionResolver resolver-swagger=org.apache.dubbo.rpc.protocol.tri.rest.support.swagger.SwaggerOpenAPIDefinitionResolver resolver-javadoc=org.apache.dubbo.rpc.protocol.tri.rest.support.swagger.JavadocOpenAPIDefinitionResolver +naming-strategy-default=org.apache.dubbo.rpc.protocol.tri.rest.openapi.DefaultOpenAPINamingStrategy handler-swagger-ui=org.apache.dubbo.rpc.protocol.tri.rest.support.swagger.SwaggerUIRequestHandler handler-redoc=org.apache.dubbo.rpc.protocol.tri.rest.support.swagger.RedocRequestHandler diff --git a/dubbo-plugin/dubbo-rest-swagger/src/main/resources/META-INF/resources/redoc/index.html b/dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/resources/redoc/index.html similarity index 84% rename from dubbo-plugin/dubbo-rest-swagger/src/main/resources/META-INF/resources/redoc/index.html rename to dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/resources/redoc/index.html index 7fa9aab01d5..68fd09cef73 100644 --- a/dubbo-plugin/dubbo-rest-swagger/src/main/resources/META-INF/resources/redoc/index.html +++ b/dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/resources/redoc/index.html @@ -1,3 +1,4 @@ + diff --git a/dubbo-plugin/dubbo-rest-swagger/src/main/resources/META-INF/resources/swagger-ui/index.html b/dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/resources/swagger-ui/index.html similarity index 93% rename from dubbo-plugin/dubbo-rest-swagger/src/main/resources/META-INF/resources/swagger-ui/index.html rename to dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/resources/swagger-ui/index.html index e0675341b44..bf226824c91 100644 --- a/dubbo-plugin/dubbo-rest-swagger/src/main/resources/META-INF/resources/swagger-ui/index.html +++ b/dubbo-plugin/dubbo-rest-openapi/src/main/resources/META-INF/resources/swagger-ui/index.html @@ -1,3 +1,4 @@ + diff --git a/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/SpringMvcRequestMappingResolver.java b/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/SpringMvcRequestMappingResolver.java index 428f4f9d18f..b80de0d00a2 100644 --- a/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/SpringMvcRequestMappingResolver.java +++ b/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/SpringMvcRequestMappingResolver.java @@ -19,6 +19,7 @@ import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.config.nested.RestConfig; import org.apache.dubbo.rpc.model.FrameworkModel; import org.apache.dubbo.rpc.protocol.tri.rest.cors.CorsUtils; import org.apache.dubbo.rpc.protocol.tri.rest.mapping.RequestMapping; @@ -35,15 +36,19 @@ @Activate(onClass = "org.springframework.web.bind.annotation.RequestMapping") public class SpringMvcRequestMappingResolver implements RequestMappingResolver { - private final FrameworkModel frameworkModel; private final RestToolKit toolKit; + private RestConfig restConfig; private CorsMeta globalCorsMeta; public SpringMvcRequestMappingResolver(FrameworkModel frameworkModel) { - this.frameworkModel = frameworkModel; toolKit = new SpringRestToolKit(frameworkModel); } + @Override + public void setRestConfig(RestConfig restConfig) { + this.restConfig = restConfig; + } + @Override public RestToolKit getRestToolKit() { return toolKit; @@ -125,7 +130,7 @@ private Builder builder( private CorsMeta buildCorsMeta(AnnotationMeta crossOrigin, String[] methods) { if (globalCorsMeta == null) { - globalCorsMeta = CorsUtils.getGlobalCorsMeta(frameworkModel); + globalCorsMeta = CorsUtils.getGlobalCorsMeta(restConfig); } if (crossOrigin == null) { return globalCorsMeta; diff --git a/dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/Helper.java b/dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/Helper.java deleted file mode 100644 index 766029b71c6..00000000000 --- a/dubbo-plugin/dubbo-rest-swagger/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/swagger/Helper.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.dubbo.rpc.protocol.tri.rest.support.swagger; - -import org.apache.dubbo.common.utils.StringUtils; - -import java.util.function.Function; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -final class Helper { - - private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("\\{\\{([\\w.-]+)}}"); - - private Helper() {} - - public static String render(String text, Function fn) { - if (text == null) { - return null; - } - Matcher matcher = PLACEHOLDER_PATTERN.matcher(text); - StringBuffer result = new StringBuffer(text.length()); - while (matcher.find()) { - String value = fn.apply(matcher.group(1)); - matcher.appendReplacement(result, value == null ? StringUtils.EMPTY_STRING : value); - } - matcher.appendTail(result); - return result.toString(); - } -} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegation.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegation.java index ab3ba7cec0a..c69fdeb9ef3 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegation.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegation.java @@ -29,8 +29,9 @@ import org.apache.dubbo.remoting.http12.HttpStatus; import org.apache.dubbo.remoting.http12.exception.HttpStatusException; import org.apache.dubbo.remoting.http12.rest.OpenAPIRequest; +import org.apache.dubbo.remoting.http12.rest.OpenAPIService; import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIService; +import org.apache.dubbo.rpc.protocol.tri.TripleProtocol; import java.util.ArrayList; import java.util.Comparator; @@ -220,11 +221,15 @@ public String getAndListenInstanceMetadata(String consumerId, InstanceMetadataCh @Override public String getOpenAPI(OpenAPIRequest request) { - OpenAPIService openAPIService = applicationModel.getBean(OpenAPIService.class); - if (openAPIService == null) { - throw new HttpStatusException(HttpStatus.NOT_FOUND.getCode(), "OpenAPI is not available"); + if (TripleProtocol.OPENAPI_ENABLED) { + OpenAPIService openAPIService = + applicationModel.getFrameworkModel().getDefaultExtensionOrNull(OpenAPIService.class); + if (openAPIService != null) { + return openAPIService.getDocument(request); + } } - return openAPIService.getDocument(request); + + throw new HttpStatusException(HttpStatus.NOT_FOUND.getCode(), "OpenAPI is not available"); } private SortedSet getServiceURLs( diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegationV2.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegationV2.java index 10878cce00d..1f8d3f2056c 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegationV2.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceDelegationV2.java @@ -23,9 +23,17 @@ import org.apache.dubbo.metadata.DubboMetadataServiceV2Triple.MetadataServiceV2ImplBase; import org.apache.dubbo.metadata.MetadataInfo; import org.apache.dubbo.metadata.MetadataRequest; +import org.apache.dubbo.metadata.OpenAPI; +import org.apache.dubbo.metadata.OpenAPIFormat; import org.apache.dubbo.registry.client.ServiceDiscovery; import org.apache.dubbo.registry.support.RegistryManager; +import org.apache.dubbo.remoting.http12.HttpStatus; +import org.apache.dubbo.remoting.http12.exception.HttpStatusException; +import org.apache.dubbo.remoting.http12.rest.OpenAPIRequest; +import org.apache.dubbo.remoting.http12.rest.OpenAPIService; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.model.FrameworkModel; +import org.apache.dubbo.rpc.protocol.tri.TripleProtocol; import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_LOAD_METADATA; import static org.apache.dubbo.metadata.util.MetadataServiceVersionUtils.toV2; @@ -34,8 +42,7 @@ public class MetadataServiceDelegationV2 extends MetadataServiceV2ImplBase { ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass()); - private final ApplicationModel applicationModel; - + private final FrameworkModel frameworkModel; private final RegistryManager registryManager; private URL metadataUrl; @@ -43,8 +50,8 @@ public class MetadataServiceDelegationV2 extends MetadataServiceV2ImplBase { public static final String VERSION = "2.0.0"; public MetadataServiceDelegationV2(ApplicationModel applicationModel) { - this.applicationModel = applicationModel; - this.registryManager = RegistryManager.getInstance(applicationModel); + frameworkModel = applicationModel.getFrameworkModel(); + registryManager = RegistryManager.getInstance(applicationModel); } @Override @@ -70,6 +77,32 @@ public org.apache.dubbo.metadata.MetadataInfoV2 getMetadataInfo(MetadataRequest return null; } + @Override + public OpenAPI getOpenAPI(org.apache.dubbo.metadata.OpenAPIRequest request) { + if (TripleProtocol.OPENAPI_ENABLED) { + OpenAPIService openAPIService = frameworkModel.getDefaultExtensionOrNull(OpenAPIService.class); + if (openAPIService != null) { + OpenAPIRequest oRequest = new OpenAPIRequest(); + oRequest.setGroup(request.getGroup()); + oRequest.setVersion(request.getVersion()); + oRequest.setTag(request.getTagList().toArray(StringUtils.EMPTY_STRING_ARRAY)); + oRequest.setService(request.getServiceList().toArray(StringUtils.EMPTY_STRING_ARRAY)); + oRequest.setOpenapi(request.getOpenapi()); + OpenAPIFormat format = request.getFormat(); + if (request.hasFormat()) { + oRequest.setFormat(format.name()); + } + if (request.hasPretty()) { + oRequest.setPretty(request.getPretty()); + } + String document = openAPIService.getDocument(oRequest); + return OpenAPI.newBuilder().setValue(document).build(); + } + } + + throw new HttpStatusException(HttpStatus.NOT_FOUND.getCode(), "OpenAPI is not available"); + } + public URL getMetadataUrl() { return metadataUrl; } diff --git a/dubbo-remoting/dubbo-remoting-http12/pom.xml b/dubbo-remoting/dubbo-remoting-http12/pom.xml index c81f5ae601a..4d16603471c 100644 --- a/dubbo-remoting/dubbo-remoting-http12/pom.xml +++ b/dubbo-remoting/dubbo-remoting-http12/pom.xml @@ -46,10 +46,6 @@ dubbo-remoting-api ${project.parent.version} - - com.google.protobuf - protobuf-java-util - io.netty @@ -60,6 +56,12 @@ netty-codec-http2 + + com.google.protobuf + protobuf-java-util + provided + + javax.xml.bind jaxb-api diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIService.java b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/rest/OpenAPIService.java similarity index 77% rename from dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIService.java rename to dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/rest/OpenAPIService.java index 01d9d97d612..18b4ac45d7b 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/openapi/OpenAPIService.java +++ b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/rest/OpenAPIService.java @@ -14,19 +14,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.rpc.protocol.tri.rest.openapi; +package org.apache.dubbo.remoting.http12.rest; -import org.apache.dubbo.remoting.http12.rest.OpenAPIRequest; -import org.apache.dubbo.rpc.protocol.tri.rest.openapi.model.OpenAPI; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.extension.ExtensionScope; +import org.apache.dubbo.common.extension.SPI; import java.util.Collection; +@SPI(value = CommonConstants.DEFAULT_KEY, scope = ExtensionScope.FRAMEWORK) public interface OpenAPIService { Collection getOpenAPIGroups(); - OpenAPI getOpenAPI(OpenAPIRequest request); - String getDocument(OpenAPIRequest request); void refresh(); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java index 7abc0aa40a6..bf64a3578f4 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java @@ -113,6 +113,8 @@ public interface Constants { String H2_SETTINGS_OPENAPI_PREFIX = "dubbo.protocol.triple.rest.openapi"; String H2_SETTINGS_VERBOSE_ENABLED = "dubbo.protocol.triple.verbose"; + String H2_SETTINGS_REST_ENABLED = "dubbo.protocol.triple.rest.enabled"; + String H2_SETTINGS_OPENAPI_ENABLED = "dubbo.protocol.triple.rest.openapi.enabled"; String H2_SETTINGS_SERVLET_ENABLED = "dubbo.protocol.triple.servlet.enabled"; String H3_SETTINGS_HTTP3_ENABLED = "dubbo.protocol.triple.http3.enabled"; String H3_SETTINGS_HTTP3_NEGOTIATION = "dubbo.protocol.triple.http3.negotiation"; diff --git a/dubbo-rpc/dubbo-rpc-triple/pom.xml b/dubbo-rpc/dubbo-rpc-triple/pom.xml index a516e70137f..1b4bebf035c 100644 --- a/dubbo-rpc/dubbo-rpc-triple/pom.xml +++ b/dubbo-rpc/dubbo-rpc-triple/pom.xml @@ -51,6 +51,7 @@ org.apache.dubbo dubbo-remoting-websocket ${project.parent.version} + true org.apache.dubbo @@ -60,23 +61,36 @@ org.apache.dubbo - dubbo-cluster + dubbo-native ${project.parent.version} - test - io.netty - netty-codec-http2 + com.google.protobuf + protobuf-java-util + true - com.google.protobuf - protobuf-java + org.apache.commons + commons-compress + true + + org.xerial.snappy + snappy-java + true + + org.springframework spring-test test + + org.apache.dubbo + dubbo-cluster + ${project.parent.version} + test + org.apache.dubbo dubbo-serialization-hessian2 @@ -94,19 +108,11 @@ log4j-slf4j-impl test - - org.apache.commons - commons-compress - io.reactivex.rxjava2 rxjava test - - org.xerial.snappy - snappy-java - io.projectreactor reactor-core @@ -117,18 +123,6 @@ spock-core test - - org.apache.dubbo - dubbo-native - ${project.parent.version} - - - - org.apache.dubbo - dubbo-compiler - ${project.parent.version} - provided - diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java index f3e53b25980..19412dd0109 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java @@ -50,7 +50,9 @@ import static org.apache.dubbo.config.Constants.CLIENT_THREAD_POOL_NAME; import static org.apache.dubbo.config.Constants.SERVER_THREAD_POOL_NAME; import static org.apache.dubbo.rpc.Constants.H2_SETTINGS_IGNORE_1_0_0_KEY; +import static org.apache.dubbo.rpc.Constants.H2_SETTINGS_OPENAPI_ENABLED; import static org.apache.dubbo.rpc.Constants.H2_SETTINGS_RESOLVE_FALLBACK_TO_DEFAULT_KEY; +import static org.apache.dubbo.rpc.Constants.H2_SETTINGS_REST_ENABLED; import static org.apache.dubbo.rpc.Constants.H2_SETTINGS_SUPPORT_NO_LOWER_HEADER_KEY; import static org.apache.dubbo.rpc.Constants.H2_SETTINGS_VERBOSE_ENABLED; @@ -65,6 +67,8 @@ public class TripleProtocol extends AbstractProtocol { public static boolean IGNORE_1_0_0_VERSION = false; public static boolean RESOLVE_FALLBACK_TO_DEFAULT = true; public static boolean VERBOSE_ENABLED = false; + public static boolean REST_ENABLED = true; + public static boolean OPENAPI_ENABLED = false; public TripleProtocol(FrameworkModel frameworkModel) { this.frameworkModel = frameworkModel; @@ -82,6 +86,9 @@ public TripleProtocol(FrameworkModel frameworkModel) { // init global settings Configuration globalConf = ConfigurationUtils.getGlobalConfiguration(frameworkModel.defaultApplication()); VERBOSE_ENABLED = globalConf.getBoolean(H2_SETTINGS_VERBOSE_ENABLED, false); + REST_ENABLED = globalConf.getBoolean(H2_SETTINGS_REST_ENABLED, true); + OPENAPI_ENABLED = globalConf.getBoolean(H2_SETTINGS_OPENAPI_ENABLED, false); + ServletExchanger.init(globalConf); Http3Exchanger.init(globalConf); } @@ -104,7 +111,9 @@ public void afterUnExport() { pathResolver.unregister(invoker); // unregister rest request mapping - mappingRegistry.unregister(invoker); + if (REST_ENABLED) { + mappingRegistry.unregister(invoker); + } // set service status to NOT_SERVING setServiceStatus(url, false); @@ -121,7 +130,9 @@ public void afterUnExport() { pathResolver.register(invoker); // register rest request mapping - mappingRegistry.register(invoker); + if (REST_ENABLED) { + mappingRegistry.register(invoker); + } // set service status to SERVING setServiceStatus(url, true); @@ -205,7 +216,9 @@ public void destroy() { PortUnificationExchanger.close(); Http3Exchanger.close(); pathResolver.destroy(); - mappingRegistry.destroy(); + if (REST_ENABLED) { + mappingRegistry.destroy(); + } super.destroy(); } } diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/cors/CorsUtils.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/cors/CorsUtils.java index a71cf9ec00e..b6f31cc0984 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/cors/CorsUtils.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/cors/CorsUtils.java @@ -16,23 +16,16 @@ */ package org.apache.dubbo.rpc.protocol.tri.rest.cors; -import org.apache.dubbo.common.config.Configuration; -import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.nested.CorsConfig; -import org.apache.dubbo.rpc.model.FrameworkModel; +import org.apache.dubbo.config.nested.RestConfig; import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.CorsMeta; public class CorsUtils { private CorsUtils() {} - public static CorsMeta getGlobalCorsMeta(FrameworkModel frameworkModel) { - CorsConfig config = ConfigManager.getProtocolOrDefault(CommonConstants.TRIPLE) - .getTripleOrDefault() - .getRestOrDefault() - .getCorsOrDefault(); + public static CorsMeta getGlobalCorsMeta(RestConfig restConfig) { + CorsConfig config = restConfig.getCorsOrDefault(); return CorsMeta.builder() .allowedOrigins(config.getAllowedOrigins()) .allowedMethods(config.getAllowedMethods()) @@ -43,10 +36,6 @@ public static CorsMeta getGlobalCorsMeta(FrameworkModel frameworkModel) { .build(); } - private static String[] getValues(Configuration config, String key) { - return StringUtils.tokenize(config.getString(key), ','); - } - public static String formatOrigin(String value) { value = value.trim(); int last = value.length() - 1; diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java index 30b3ca199e1..6535f827399 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java @@ -24,6 +24,7 @@ import org.apache.dubbo.remoting.http12.HttpRequest; import org.apache.dubbo.remoting.http12.exception.HttpStatusException; import org.apache.dubbo.remoting.http12.message.MethodMetadata; +import org.apache.dubbo.remoting.http12.rest.OpenAPIService; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.model.FrameworkModel; import org.apache.dubbo.rpc.model.MethodDescriptor; @@ -31,6 +32,7 @@ import org.apache.dubbo.rpc.model.ReflectionServiceDescriptor; import org.apache.dubbo.rpc.model.ServiceDescriptor; import org.apache.dubbo.rpc.protocol.tri.DescriptorUtils; +import org.apache.dubbo.rpc.protocol.tri.TripleProtocol; import org.apache.dubbo.rpc.protocol.tri.rest.Messages; import org.apache.dubbo.rpc.protocol.tri.rest.RestConstants; import org.apache.dubbo.rpc.protocol.tri.rest.RestMappingException; @@ -40,8 +42,6 @@ import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.HandlerMeta; import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.MethodMeta; import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.ServiceMeta; -import org.apache.dubbo.rpc.protocol.tri.rest.openapi.ConfigFactory; -import org.apache.dubbo.rpc.protocol.tri.rest.openapi.DefaultOpenAPIService; import org.apache.dubbo.rpc.protocol.tri.rest.util.KeyString; import org.apache.dubbo.rpc.protocol.tri.rest.util.MethodWalker; import org.apache.dubbo.rpc.protocol.tri.rest.util.PathUtils; @@ -67,7 +67,7 @@ public final class DefaultRequestMappingRegistry implements RequestMappingRegist private final AtomicBoolean initialized = new AtomicBoolean(); private ContentNegotiator contentNegotiator; - private DefaultOpenAPIService openAPIService; + private OpenAPIService openAPIService; private List resolvers; private RestConfig restConfig; private RadixTree tree; @@ -78,14 +78,16 @@ public DefaultRequestMappingRegistry(FrameworkModel frameworkModel) { private void init(Invoker invoker) { contentNegotiator = frameworkModel.getOrRegisterBean(ContentNegotiator.class); - if (ConfigFactory.isOpenAPIEnabled(frameworkModel)) { - openAPIService = frameworkModel.getOrRegisterBean(DefaultOpenAPIService.class); - openAPIService.setRequestMappingRegistry(this); + if (TripleProtocol.OPENAPI_ENABLED) { + openAPIService = frameworkModel.getDefaultExtensionOrNull(OpenAPIService.class); } resolvers = frameworkModel.getActivateExtensions(RequestMappingResolver.class); restConfig = ConfigManager.getProtocolOrDefault(invoker.getUrl()) .getTripleOrDefault() .getRestOrDefault(); + for (RequestMappingResolver resolver : resolvers) { + resolver.setRestConfig(restConfig); + } tree = new RadixTree<>(restConfig.getCaseSensitiveMatchOrDefault()); } diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RequestMappingResolver.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RequestMappingResolver.java index 803792f1a4d..25e34620b0b 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RequestMappingResolver.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RequestMappingResolver.java @@ -18,6 +18,7 @@ import org.apache.dubbo.common.extension.ExtensionScope; import org.apache.dubbo.common.extension.SPI; +import org.apache.dubbo.config.nested.RestConfig; import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.MethodMeta; import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.ServiceMeta; import org.apache.dubbo.rpc.protocol.tri.rest.util.RestToolKit; @@ -27,6 +28,8 @@ public interface RequestMappingResolver { RestToolKit getRestToolKit(); + default void setRestConfig(RestConfig restConfig) {} + default boolean accept(ServiceMeta serviceMeta) { return true; } diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/BasicRequestMappingResolver.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/BasicRequestMappingResolver.java index bddaadefc9a..533d2b155d4 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/BasicRequestMappingResolver.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/BasicRequestMappingResolver.java @@ -18,6 +18,7 @@ import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.config.nested.RestConfig; import org.apache.dubbo.remoting.http12.rest.Mapping; import org.apache.dubbo.rpc.model.FrameworkModel; import org.apache.dubbo.rpc.protocol.tri.rest.cors.CorsUtils; @@ -36,12 +37,11 @@ @Activate public class BasicRequestMappingResolver implements RequestMappingResolver { - private final FrameworkModel frameworkModel; private final RestToolKit toolKit; + private RestConfig restConfig; private CorsMeta globalCorsMeta; public BasicRequestMappingResolver(FrameworkModel frameworkModel) { - this.frameworkModel = frameworkModel; toolKit = new BasicRestToolKit(frameworkModel); } @@ -50,6 +50,11 @@ public RestToolKit getRestToolKit() { return toolKit; } + @Override + public void setRestConfig(RestConfig restConfig) { + this.restConfig = restConfig; + } + @Override public boolean accept(MethodMeta methodMeta) { AnnotationMeta mapping = methodMeta.findAnnotation(Mapping.class); @@ -77,8 +82,15 @@ public RequestMapping resolve(ServiceMeta serviceMeta) { public RequestMapping resolve(MethodMeta methodMeta) { Method method = methodMeta.getMethod(); AnnotationMeta mapping = methodMeta.findAnnotation(Mapping.class); - if (mapping != null && !mapping.getAnnotation().enabled()) { - return null; + if (mapping != null) { + if (!mapping.getAnnotation().enabled()) { + return null; + } + } else { + Boolean enabled = restConfig.getEnableDefaultMapping(); + if (enabled != null && !enabled) { + return null; + } } Builder builder = builder(mapping); @@ -92,7 +104,7 @@ public RequestMapping resolve(MethodMeta methodMeta) { ServiceMeta serviceMeta = methodMeta.getServiceMeta(); if (globalCorsMeta == null) { - globalCorsMeta = CorsUtils.getGlobalCorsMeta(frameworkModel); + globalCorsMeta = CorsUtils.getGlobalCorsMeta(restConfig); } return builder.name(method.getName()) .service(serviceMeta.getServiceGroup(), serviceMeta.getServiceVersion()) diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension b/dubbo-rpc/dubbo-rpc-triple/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension deleted file mode 100644 index c2f29afc12b..00000000000 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIExtension +++ /dev/null @@ -1,2 +0,0 @@ -resolver-basic=org.apache.dubbo.rpc.protocol.tri.rest.support.basic.BasicOpenAPIDefinitionResolver -naming-strategy-default=org.apache.dubbo.rpc.protocol.tri.rest.openapi.DefaultOpenAPINamingStrategy diff --git a/dubbo-spring-boot-project/dubbo-spring-boot/src/main/java/org/apache/dubbo/spring/boot/context/event/DubboOpenAPIExportListener.java b/dubbo-spring-boot-project/dubbo-spring-boot/src/main/java/org/apache/dubbo/spring/boot/context/event/DubboOpenAPIExportListener.java index 73a0f347a6e..511aeadcfd2 100644 --- a/dubbo-spring-boot-project/dubbo-spring-boot/src/main/java/org/apache/dubbo/spring/boot/context/event/DubboOpenAPIExportListener.java +++ b/dubbo-spring-boot-project/dubbo-spring-boot/src/main/java/org/apache/dubbo/spring/boot/context/event/DubboOpenAPIExportListener.java @@ -17,8 +17,8 @@ package org.apache.dubbo.spring.boot.context.event; import org.apache.dubbo.config.spring.util.DubboBeanUtils; +import org.apache.dubbo.remoting.http12.rest.OpenAPIService; import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.rpc.protocol.tri.rest.openapi.OpenAPIService; import java.util.concurrent.atomic.AtomicBoolean; @@ -41,7 +41,11 @@ public void onApplicationEvent(ApplicationReadyEvent event) { return; } ApplicationModel applicationModel = DubboBeanUtils.getApplicationModel(event.getApplicationContext()); - OpenAPIService openAPIService = applicationModel.getBean(OpenAPIService.class); + if (applicationModel == null) { + return; + } + OpenAPIService openAPIService = + applicationModel.getFrameworkModel().getDefaultExtensionOrNull(OpenAPIService.class); if (openAPIService != null) { openAPIService.export(); } diff --git a/dubbo-test/dubbo-dependencies-all/pom.xml b/dubbo-test/dubbo-dependencies-all/pom.xml index 554c6cb50a1..69889f8f9aa 100644 --- a/dubbo-test/dubbo-dependencies-all/pom.xml +++ b/dubbo-test/dubbo-dependencies-all/pom.xml @@ -253,7 +253,7 @@ org.apache.dubbo - dubbo-rest-swagger + dubbo-rest-openapi ${project.version} diff --git a/pom.xml b/pom.xml index 6fc69afbfd0..c0bebb4e4a2 100644 --- a/pom.xml +++ b/pom.xml @@ -106,7 +106,7 @@ dubbo-plugin/dubbo-filter-validation dubbo-plugin/dubbo-rest-jaxrs dubbo-plugin/dubbo-rest-spring - dubbo-plugin/dubbo-rest-swagger + dubbo-plugin/dubbo-rest-openapi dubbo-plugin/dubbo-triple-servlet dubbo-plugin/dubbo-triple-websocket dubbo-demo/dubbo-demo-api