|
6 | 6 | "net/http"
|
7 | 7 | "time"
|
8 | 8 |
|
| 9 | + "github.com/swaggest/openapi-go" |
9 | 10 | "github.com/swaggest/openapi-go/openapi3"
|
10 | 11 | )
|
11 | 12 |
|
@@ -339,8 +340,8 @@ components:
|
339 | 340 | // bar
|
340 | 341 | }
|
341 | 342 |
|
342 |
| -func ExampleReflector_SetJSONResponse() { |
343 |
| - reflector := openapi3.Reflector{} |
| 343 | +func ExampleReflector_AddOperation() { |
| 344 | + reflector := openapi3.NewReflector() |
344 | 345 | reflector.Spec = &openapi3.Spec{Openapi: "3.0.3"}
|
345 | 346 | reflector.Spec.Info.
|
346 | 347 | WithTitle("Things API").
|
@@ -368,18 +369,17 @@ func ExampleReflector_SetJSONResponse() {
|
368 | 369 | UpdatedAt time.Time `json:"updated_at"`
|
369 | 370 | }
|
370 | 371 |
|
371 |
| - putOp := openapi3.Operation{} |
| 372 | + putOp, _ := reflector.NewOperationContext(http.MethodPut, "/things/{id}") |
372 | 373 |
|
373 |
| - handleError(reflector.SetRequest(&putOp, new(req), http.MethodPut)) |
374 |
| - handleError(reflector.SetJSONResponse(&putOp, new(resp), http.StatusOK)) |
375 |
| - handleError(reflector.SetJSONResponse(&putOp, new([]resp), http.StatusConflict)) |
376 |
| - handleError(reflector.Spec.AddOperation(http.MethodPut, "/things/{id}", putOp)) |
| 374 | + putOp.AddReqStructure(new(req)) |
| 375 | + putOp.AddRespStructure(new(resp)) |
| 376 | + putOp.AddRespStructure(new([]resp), openapi.WithHTTPStatus(http.StatusConflict)) |
| 377 | + handleError(reflector.AddOperation(putOp)) |
377 | 378 |
|
378 |
| - getOp := openapi3.Operation{} |
379 |
| - |
380 |
| - handleError(reflector.SetRequest(&getOp, new(req), http.MethodGet)) |
381 |
| - handleError(reflector.SetJSONResponse(&getOp, new(resp), http.StatusOK)) |
382 |
| - handleError(reflector.Spec.AddOperation(http.MethodGet, "/things/{id}", getOp)) |
| 379 | + getOp, _ := reflector.NewOperationContext(http.MethodGet, "/things/{id}") |
| 380 | + getOp.AddReqStructure(new(req)) |
| 381 | + getOp.AddRespStructure(new(resp)) |
| 382 | + handleError(reflector.AddOperation(getOp)) |
383 | 383 |
|
384 | 384 | schema, err := reflector.Spec.MarshalYAML()
|
385 | 385 | if err != nil {
|
@@ -493,9 +493,8 @@ func ExampleReflector_SetJSONResponse() {
|
493 | 493 | // type: object
|
494 | 494 | }
|
495 | 495 |
|
496 |
| -func ExampleReflector_SetRequest_queryObject() { |
497 |
| - reflector := openapi3.Reflector{} |
498 |
| - reflector.Spec = &openapi3.Spec{Openapi: "3.0.3"} |
| 496 | +func ExampleReflector_AddOperation_queryObject() { |
| 497 | + reflector := openapi3.NewReflector() |
499 | 498 | reflector.Spec.Info.
|
500 | 499 | WithTitle("Things API").
|
501 | 500 | WithVersion("1.2.3").
|
@@ -526,10 +525,10 @@ func ExampleReflector_SetRequest_queryObject() {
|
526 | 525 | DeepObjectFilter deepObjectFilter `query:"deep_object_filter"`
|
527 | 526 | }
|
528 | 527 |
|
529 |
| - getOp := openapi3.Operation{} |
| 528 | + getOp, _ := reflector.NewOperationContext(http.MethodGet, "/things/{id}") |
530 | 529 |
|
531 |
| - _ = reflector.SetRequest(&getOp, new(req), http.MethodGet) |
532 |
| - _ = reflector.Spec.AddOperation(http.MethodGet, "/things/{id}", getOp) |
| 530 | + getOp.AddReqStructure(new(req)) |
| 531 | + _ = reflector.AddOperation(getOp) |
533 | 532 |
|
534 | 533 | schema, err := reflector.Spec.MarshalYAML()
|
535 | 534 | if err != nil {
|
|
0 commit comments