trpc.group/trpc-go/trpc-cmdline@v1.0.9/util/apidocs/pathx.go (about)

     1  // Tencent is pleased to support the open source community by making tRPC available.
     2  //
     3  // Copyright (C) 2023 THL A29 Limited, a Tencent company.
     4  // All rights reserved.
     5  //
     6  // If you have downloaded a copy of the tRPC source code from Tencent,
     7  // please note that tRPC source code is licensed under the  Apache 2.0 License,
     8  // A copy of the Apache 2.0 License is included in this file.
     9  
    10  package apidocs
    11  
    12  // MethodStructX defines the detailed information of a method in OpenAPI JSON.
    13  type MethodStructX struct {
    14  	Summary     string                       `json:"summary,omitempty"`     // Comment of method.
    15  	OperationID string                       `json:"operationId,omitempty"` // Name of method.
    16  	Responses   map[string]BodyContentStruct `json:"responses,omitempty"`   // Response definition of method.
    17  
    18  	// Structure  of method's input parameters except body.
    19  	Parameters  []*ParameterStructX `json:"parameters,omitempty"`
    20  	RequestBody *BodyContentStruct  `json:"requestBody,omitempty"` // Struct definition of method input parameters.
    21  
    22  	Tags        []string `json:"tags,omitempty"`        // The service to which the method belongs.
    23  	Description string   `json:"description,omitempty"` // Description of the method.
    24  }
    25  
    26  // MethodsX for v3
    27  type MethodsX struct {
    28  	Elements map[string]*MethodStructX
    29  	Rank     map[string]int
    30  }
    31  
    32  // UnmarshalJSON deserializes JSON data.
    33  func (method *MethodsX) UnmarshalJSON(b []byte) error {
    34  	return OrderedUnmarshalJSON(b, &method.Elements, &method.Rank)
    35  }
    36  
    37  // MarshalJSON serializes to JSON.
    38  func (method MethodsX) MarshalJSON() ([]byte, error) {
    39  	return OrderedMarshalJSON(method.Elements, method.Rank)
    40  }
    41  
    42  // PathsX for v3
    43  type PathsX struct {
    44  	Elements map[string]MethodsX
    45  	Rank     map[string]int
    46  }
    47  
    48  // UnmarshalJSON deserializes JSON data.
    49  func (paths *PathsX) UnmarshalJSON(b []byte) error {
    50  	return OrderedUnmarshalJSON(b, &paths.Elements, &paths.Rank)
    51  }
    52  
    53  // MarshalJSON serializes to JSON.
    54  func (paths PathsX) MarshalJSON() ([]byte, error) {
    55  	return OrderedMarshalJSON(paths.Elements, paths.Rank)
    56  }