buildSecurityScheme builds the OpenAPI SecurityScheme object from the top-level security scheme definition.
(se *expr.SchemeExpr)
| 563 | // buildSecurityScheme builds the OpenAPI SecurityScheme object from the |
| 564 | // top-level security scheme definition. |
| 565 | func buildSecurityScheme(se *expr.SchemeExpr) *SecurityScheme { |
| 566 | var scheme *SecurityScheme |
| 567 | switch se.Kind { |
| 568 | case expr.BasicAuthKind: |
| 569 | scheme = &SecurityScheme{ |
| 570 | Type: "http", |
| 571 | Scheme: "basic", |
| 572 | Description: se.Description, |
| 573 | Extensions: openapi.ExtensionsFromExpr(se.Meta), |
| 574 | } |
| 575 | case expr.APIKeyKind: |
| 576 | scheme = &SecurityScheme{ |
| 577 | Type: "apiKey", |
| 578 | Description: se.Description, |
| 579 | In: se.In, |
| 580 | Name: se.Name, |
| 581 | Extensions: openapi.ExtensionsFromExpr(se.Meta), |
| 582 | } |
| 583 | case expr.BearerKind, expr.JWTKind: |
| 584 | bearerFormat := se.BearerFormat |
| 585 | if bearerFormat == "" && se.Kind == expr.JWTKind { |
| 586 | bearerFormat = "JWT" |
| 587 | } |
| 588 | scheme = &SecurityScheme{ |
| 589 | Type: "http", |
| 590 | Scheme: "bearer", |
| 591 | BearerFormat: bearerFormat, |
| 592 | Description: se.Description, |
| 593 | Extensions: openapi.ExtensionsFromExpr(se.Meta), |
| 594 | } |
| 595 | case expr.OAuth2Kind: |
| 596 | scopes := make(map[string]string, len(se.Scopes)) |
| 597 | for _, scope := range se.Scopes { |
| 598 | scopes[scope.Name] = scope.Description |
| 599 | } |
| 600 | var flows OAuthFlows |
| 601 | for _, f := range se.Flows { |
| 602 | switch f.Kind { |
| 603 | case expr.AuthorizationCodeFlowKind: |
| 604 | flows.AuthorizationCode = &OAuthFlow{ |
| 605 | AuthorizationURL: f.AuthorizationURL, |
| 606 | TokenURL: f.TokenURL, |
| 607 | RefreshURL: f.RefreshURL, |
| 608 | Scopes: scopes, |
| 609 | } |
| 610 | case expr.ClientCredentialsFlowKind: |
| 611 | flows.ClientCredentials = &OAuthFlow{ |
| 612 | TokenURL: f.TokenURL, |
| 613 | RefreshURL: f.RefreshURL, |
| 614 | Scopes: scopes, |
| 615 | } |
| 616 | case expr.ImplicitFlowKind: |
| 617 | flows.Implicit = &OAuthFlow{ |
| 618 | AuthorizationURL: f.AuthorizationURL, |
| 619 | RefreshURL: f.RefreshURL, |
| 620 | Scopes: scopes, |
| 621 | } |
| 622 | case expr.PasswordFlowKind: |
no test coverage detected