1// Copyright 2015 go-swagger maintainers 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package spec 16 17import ( 18 "encoding/json" 19 20 "github.com/go-openapi/swag" 21) 22 23// SecuritySchemeProps describes a swagger security scheme in the securityDefinitions section 24type SecuritySchemeProps struct { 25 Description string `json:"description,omitempty"` 26 Type string `json:"type"` 27 Name string `json:"name,omitempty"` // api key 28 In string `json:"in,omitempty"` // api key 29 Flow string `json:"flow,omitempty"` // oauth2 30 AuthorizationURL string `json:"authorizationUrl,omitempty"` // oauth2 31 TokenURL string `json:"tokenUrl,omitempty"` // oauth2 32 Scopes map[string]string `json:"scopes,omitempty"` // oauth2 33} 34 35// SecurityScheme allows the definition of a security scheme that can be used by the operations. 36// Supported schemes are basic authentication, an API key (either as a header or as a query parameter) 37// and OAuth2's common flows (implicit, password, application and access code). 38// 39// For more information: http://goo.gl/8us55a#securitySchemeObject 40type SecurityScheme struct { 41 VendorExtensible 42 SecuritySchemeProps 43} 44 45// MarshalJSON marshal this to JSON 46func (s SecurityScheme) MarshalJSON() ([]byte, error) { 47 b1, err := json.Marshal(s.SecuritySchemeProps) 48 if err != nil { 49 return nil, err 50 } 51 b2, err := json.Marshal(s.VendorExtensible) 52 if err != nil { 53 return nil, err 54 } 55 return swag.ConcatJSON(b1, b2), nil 56} 57 58// UnmarshalJSON marshal this from JSON 59func (s *SecurityScheme) UnmarshalJSON(data []byte) error { 60 if err := json.Unmarshal(data, &s.SecuritySchemeProps); err != nil { 61 return err 62 } 63 return json.Unmarshal(data, &s.VendorExtensible) 64} 65