github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/internal/oapispec/routes.go (about) 1 // Copyright © 2021 Kaleido, Inc. 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 package oapispec 18 19 import ( 20 "github.com/kaleido-io/firefly/internal/config" 21 "github.com/kaleido-io/firefly/internal/i18n" 22 "github.com/kaleido-io/firefly/pkg/database" 23 ) 24 25 // Route defines each API operation on the REST API of Firefly 26 // Having a standard pluggable layer here on top of Gorilla allows us to autmoatically 27 // maintain the OpenAPI specification in-line with the code, while retaining the 28 // power of the Gorilla mux without a deep abstraction layer. 29 type Route struct { 30 // Name is the operation name that will go into the Swagger definition, and prefix input/output schema 31 Name string 32 // Path is a Gorilla mux path spec 33 Path string 34 // PathParams is a list of documented path parameters 35 PathParams []*PathParam 36 // QueryParams is a list of documented query parameters 37 QueryParams []*QueryParam 38 // FilterFactory is a reference to a filter object that defines the search param on resource collection interfaces 39 FilterFactory database.QueryFactory 40 // Method is the HTTP method 41 Method string 42 // Description is a message key to a translatable description of the operation 43 Description i18n.MessageKey 44 // JSONInputValue is a function that returns a pointer to a structure to take JSON input 45 JSONInputValue func() interface{} 46 // JSONInputMask are fields that aren't available for users to supply on input 47 JSONInputMask []string 48 // JSONInputSchema is a custom schema definition, for the case where the auto-gen + mask isn't good enough 49 JSONInputSchema string 50 // JSONOutputValue is a function that returns a pointer to a structure to take JSON output 51 JSONOutputValue func() interface{} 52 // JSONOutputCode is the success response code 53 JSONOutputCode int 54 // JSONHandler is a function for handling JSON content type input. Input/Ouptut objects are returned by JSONInputValue/JSONOutputValue funcs 55 JSONHandler func(r APIRequest) (output interface{}, err error) 56 // FormUploadHandler takes a single file upload, and returns a JSON object 57 FormUploadHandler func(r APIRequest) (output interface{}, err error) 58 } 59 60 // PathParam is a description of a path parameter 61 type PathParam struct { 62 // Name is the name of the parameter, from the Gorilla path mux 63 Name string 64 // Default is the value that will be used in the case no value is supplied 65 Default string 66 // Example is a field to fill in, in the helper UI 67 Example string 68 // ExampleFromConf is a field to fill in, in the helper UI, from the runtime configuration 69 ExampleFromConf config.RootKey 70 // Description is a message key to a translatable description of the parameter 71 Description i18n.MessageKey 72 } 73 74 // QueryParam is a description of a path parameter 75 type QueryParam struct { 76 // Name is the name of the parameter, from the Gorilla path mux 77 Name string 78 // IsBool if this is a boolean query 79 IsBool bool 80 // Default is the value that will be used in the case no value is supplied 81 Default string 82 // Example is a field to fill in, in the helper UI 83 Example string 84 // ExampleFromConf is a field to fill in, in the helper UI, from the runtime configuration 85 ExampleFromConf config.RootKey 86 // Description is a message key to a translatable description of the parameter 87 Description i18n.MessageKey 88 }