@@ -2,6 +2,7 @@ package radix_tree_address_space
2
2
3
3
import (
4
4
"fmt"
5
+ "net/http"
5
6
"strings"
6
7
7
8
"github.com/getkin/kin-openapi/openapi3"
@@ -80,15 +81,58 @@ type AddressSpace interface {
80
81
GetSimpleSelectKey () string
81
82
GetSimpleSelectSchema () anysdk.Schema
82
83
GetUnionSelectSchemas () map [string ]anysdk.Schema
84
+ DereferenceAddress (address string ) (any , bool )
83
85
}
84
86
85
87
type standardNamespace struct {
86
- serverVars map [string ]string
87
- requestBodyParams map [string ]anysdk.Addressable
88
- server * openapi3.Server
89
- simpleSelectKey string
90
- simpleSelectSchema anysdk.Schema
91
- unionSelectSchemas map [string ]anysdk.Schema
88
+ serverVars map [string ]string
89
+ requestBodyParams map [string ]anysdk.Addressable
90
+ server * openapi3.Server
91
+ simpleSelectKey string
92
+ simpleSelectSchema anysdk.Schema
93
+ responseBodySchema anysdk.Schema
94
+ requestBodySchema anysdk.Schema
95
+ responseBodyMediaType string
96
+ requestBodyMediaType string
97
+ pathString string
98
+ serverUrlString string
99
+ request * http.Request
100
+ response * http.Response
101
+ unionSelectSchemas map [string ]anysdk.Schema
102
+ }
103
+
104
+ func (ns * standardNamespace ) DereferenceAddress (address string ) (any , bool ) {
105
+ parts := strings .Split (address , "." )
106
+ if len (parts ) == 0 {
107
+ return nil , false
108
+ }
109
+ if parts [0 ] == standardRequestName {
110
+ if len (parts ) < 2 {
111
+ return nil , false
112
+ }
113
+ switch parts [1 ] {
114
+ case standardBodyName :
115
+ return ns .requestBodySchema , true
116
+ case standardHeadersName :
117
+ return ns .request .Header , true
118
+ default :
119
+ return nil , false
120
+ }
121
+ }
122
+ if parts [0 ] == standardResponseName {
123
+ if len (parts ) < 2 {
124
+ return nil , false
125
+ }
126
+ switch parts [1 ] {
127
+ case standardHeadersName :
128
+ return ns .server .Variables , true
129
+ case standardBodyName :
130
+ return ns .responseBodySchema , true
131
+ default :
132
+ return nil , false
133
+ }
134
+ }
135
+ return nil , false
92
136
}
93
137
94
138
func (ns * standardNamespace ) GetServer () * openapi3.Server {
@@ -144,10 +188,11 @@ func (asa *standardAddressSpaceAnalyzer) Analyze() error {
144
188
for k , v := range firstServer .Variables {
145
189
serverVars [k ] = v .Default
146
190
}
147
- reequestBodySchema , requestBodySchemaErr := asa .method .GetRequestBodySchema ()
191
+ requestBodySchema , requestBodySchemaErr := asa .method .GetRequestBodySchema ()
192
+ requestBodyMediaType := asa .method .GetRequestBodyMediaType ()
148
193
requestBodyParams := map [string ]anysdk.Addressable {}
149
194
var err error
150
- if reequestBodySchema != nil && requestBodySchemaErr == nil {
195
+ if requestBodySchema != nil && requestBodySchemaErr == nil {
151
196
requestBodyParams , err = asa .method .GetRequestBodyAttributesNoRename ()
152
197
if err != nil {
153
198
return err
@@ -176,13 +221,18 @@ func (asa *standardAddressSpaceAnalyzer) Analyze() error {
176
221
}
177
222
unionSelectSchemas [k ] = schema
178
223
}
224
+ responseSchema , responseMediaType , _ := asa .method .GetResponseBodySchemaAndMediaType ()
179
225
addressSpace := & standardNamespace {
180
- server : firstServer ,
181
- serverVars : serverVars ,
182
- requestBodyParams : requestBodyParams ,
183
- simpleSelectKey : simpleSelectKey ,
184
- simpleSelectSchema : simpleSelectSchema ,
185
- unionSelectSchemas : unionSelectSchemas ,
226
+ server : firstServer ,
227
+ serverVars : serverVars ,
228
+ requestBodyParams : requestBodyParams ,
229
+ simpleSelectKey : simpleSelectKey ,
230
+ simpleSelectSchema : simpleSelectSchema ,
231
+ unionSelectSchemas : unionSelectSchemas ,
232
+ responseBodySchema : responseSchema ,
233
+ requestBodySchema : requestBodySchema ,
234
+ responseBodyMediaType : responseMediaType ,
235
+ requestBodyMediaType : requestBodyMediaType ,
186
236
}
187
237
if addressSpace == nil {
188
238
return fmt .Errorf ("failed to create address space for operation %s" , asa .method .GetName ())
0 commit comments