CAICAIIs commented on code in PR #3280:
URL: https://github.com/apache/dubbo-go/pull/3280#discussion_r3052723481


##########
global/openapi_config.go:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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 global
+
+type OpenAPIConfig struct {
+       Enabled bool `yaml:"enabled" json:"enabled" default:"false"`
+
+       Path string `yaml:"path" json:"path,omitempty"`
+
+       InfoTitle       string `yaml:"info-title" json:"infoTitle,omitempty"`
+       InfoDescription string `yaml:"info-description" 
json:"infoDescription,omitempty"`
+       InfoVersion     string `yaml:"info-version" 
json:"infoVersion,omitempty"`
+
+       DefaultConsumesMediaTypes []string `yaml:"default-consumes-media-types" 
json:"defaultConsumesMediaTypes,omitempty"`
+       DefaultProducesMediaTypes []string `yaml:"default-produces-media-types" 
json:"defaultProducesMediaTypes,omitempty"`
+       DefaultHttpStatusCodes    []string `yaml:"default-http-status-codes" 
json:"defaultHttpStatusCodes,omitempty"`
+
+       Settings map[string]string `yaml:"settings" json:"settings,omitempty"`
+}
+
+func DefaultOpenAPIConfig() *OpenAPIConfig {

Review Comment:
   can read the latest published OpenAPI spec 
https://spec.openapis.org/oas/latest.html#info-object
   ```
   title | string | REQUIRED. The title of the API
   ```



##########
protocol/triple/triple_protocol/server.go:
##########
@@ -337,10 +340,38 @@ func (s *Server) GracefulStop(ctx context.Context) error {
 }
 
 func NewServer(addr string, tripleConf *global.TripleConfig) *Server {
-       return &Server{
+       s := &Server{
                mux:          newMethodRouteMux(),
                addr:         addr,
                handlers:     make(map[string]*Handler),
                tripleConfig: tripleConf,
        }
+
+       var openapiIntegration *openapi.OpenAPIIntegration
+       if tripleConf != nil && tripleConf.OpenAPI != nil && 
tripleConf.OpenAPI.Enabled {
+               openapiIntegration = 
openapi.NewOpenAPIIntegration(tripleConf.OpenAPI)
+       }
+       s.openapiIntegration = openapiIntegration
+
+       openapiHandler := openapi.NewHTTPHandler(openapiIntegration)
+       basePath := "/dubbo/openapi"

Review Comment:
   `OpenAPI.Path` is used as-is when all derived routes are registered here. If 
a user configures a trailing slash, for example `"/custom/openapi/"`, the 
effective routes become double-slash paths such as:
   
   - `/custom/openapi//openapi.json`
   - `/custom/openapi//swagger-ui/`
   
   I checked this on the current head:
   1. enable OpenAPI
   2. set `cfg.Path = "/custom/openapi/"`
   3. register one simple service
   4. request the normal URLs:
      - `/custom/openapi/openapi.json`
      - `/custom/openapi/swagger-ui/`
      - `/custom/openapi/redoc/`
   
   All of those returned `404`, while the double-slash variants returned `200`.
   
   So a very common custom path configuration makes the feature look broken. 
`openapi.path` should be normalized once (for example by trimming the trailing 
slash, except for the root case) before route registration and path matching.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to