github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/cmd/protoc-gen-openapi/converter/default_openapi_spec.go (about) 1 package converter 2 3 import ( 4 "github.com/getkin/kin-openapi/openapi3" 5 "github.com/golang/protobuf/proto" 6 ) 7 8 // defaultSpec creates a new OpenAPI3 document to fill in with schemas and paths: 9 func (c *Converter) defaultSpec() { 10 11 // Spec ready to take schemas: 12 c.openAPISpec = &openapi3.Swagger{ 13 Components: openapi3.Components{ 14 RequestBodies: make(map[string]*openapi3.RequestBodyRef), 15 Responses: make(map[string]*openapi3.ResponseRef), 16 SecuritySchemes: make(map[string]*openapi3.SecuritySchemeRef), 17 Schemas: make(map[string]*openapi3.SchemaRef), 18 }, 19 Info: &openapi3.Info{ 20 Title: "Micro API", 21 Description: "Generated by protoc-gen-openapi", 22 Version: "1", 23 ExtensionProps: openapi3.ExtensionProps{ 24 Extensions: map[string]interface{}{ 25 "x-logo": map[string]string{ 26 "url": "https://micro.dev/images/brand.png", 27 "backgroundColor": "#FFFFFF", 28 "altText": "Micro logo", 29 }, 30 }, 31 }, 32 }, 33 OpenAPI: "3.0.0", 34 Paths: make(openapi3.Paths), 35 } 36 37 // Add the local platform server: 38 c.openAPISpec.AddServer( 39 &openapi3.Server{ 40 URL: "http://localhost:8080", 41 Description: "Micro dev environment", 42 }, 43 ) 44 45 // Add the Micro auth mechanism: 46 c.openAPISpec.Components.SecuritySchemes["MicroAPIToken"] = &openapi3.SecuritySchemeRef{ 47 Value: &openapi3.SecurityScheme{ 48 BearerFormat: "JWT", 49 Description: "Micro API token", 50 Type: "http", 51 Scheme: "bearer", 52 }, 53 } 54 55 // Add a default Micro error schema: 56 c.openAPISpec.Components.Responses["MicroAPIError"] = &openapi3.ResponseRef{ 57 Value: &openapi3.Response{ 58 Content: openapi3.Content{ 59 "application/json": &openapi3.MediaType{ 60 Schema: &openapi3.SchemaRef{ 61 Value: &openapi3.Schema{ 62 Type: openAPITypeObject, 63 Title: "MicroAPIError", 64 Properties: map[string]*openapi3.SchemaRef{ 65 "Id": { 66 Value: &openapi3.Schema{ 67 Description: "Error ID", 68 Type: openAPITypeString, 69 }, 70 }, 71 "Code": { 72 Value: &openapi3.Schema{ 73 Description: "Error code", 74 Example: 500, 75 Type: openAPITypeNumber, 76 }, 77 }, 78 "Detail": { 79 Value: &openapi3.Schema{ 80 Description: "Error detail", 81 Example: "service not found", 82 Type: openAPITypeString, 83 }, 84 }, 85 "Status": { 86 Value: &openapi3.Schema{ 87 Description: "Error status message", 88 Example: "Internal Server Error", 89 Type: openAPITypeString, 90 }, 91 }, 92 }, 93 }, 94 }, 95 }, 96 }, 97 Description: proto.String("Error from the Micro API"), 98 }, 99 } 100 }