-
-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up generation of Go types from objects found under the Component schemas, and add some tests for each kind that we support.
- Loading branch information
Marcin Romaszewicz
committed
Apr 19, 2019
1 parent
71c3f1f
commit 52364d1
Showing
9 changed files
with
155 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// This is an autogenerated file, any edits which you make here will be lost! | ||
package components | ||
|
||
import ( | ||
"bytes" | ||
"compress/gzip" | ||
"encoding/base64" | ||
"fmt" | ||
"github.com/deepmap/oapi-codegen/pkg/runtime" | ||
"github.com/getkin/kin-openapi/openapi3" | ||
"strings" | ||
) | ||
|
||
// Type definition for component schema "SchemaObject" | ||
type SchemaObject struct { | ||
FirstName string `json:"firstName"` | ||
Role string `json:"role"` | ||
} | ||
|
||
// Type definition for component parameter "ParameterObject" | ||
type ParameterObject string | ||
|
||
// Type definition for component response "ResponseObject" | ||
type ResponseObject struct { | ||
Field SchemaObject `json:"Field"` | ||
} | ||
|
||
// Type definition for component requestBodies "RequestBody" | ||
type RequestBody struct { | ||
Field SchemaObject `json:"Field"` | ||
} | ||
|
||
type ServerInterface interface { | ||
} | ||
|
||
type ServerInterfaceWrapper struct { | ||
Handler ServerInterface | ||
} | ||
|
||
func RegisterHandlers(router runtime.EchoRouter, si ServerInterface) { | ||
|
||
} | ||
|
||
// Base64 encoded, gzipped, json marshaled Swagger object | ||
var swaggerSpec = []string{ | ||
|
||
"H4sIAAAAAAAC/9ySzU7rQAyFXyXyvcsoacUuO1ggseBHtDvUxTBxwdVkZmq7FVWVd0czSVsofQFYxXbs", | ||
"75yjZA82dDF49CrQ7CEaNh0qcu6eDt3j6wqtppENXtHn0sToyBql4OuVBJ9mYt+xM5nEISIrYSbdEro2", | ||
"Ff8Zl9DAv/qkWw9HUs/yc9Tq+xIY1xtibKF5GQmLNFb80Do6Q2eSuosIDYgy+Tfo02qLYpli8ggNmOKY", | ||
"D0pI57DeIO+OYih6E9rR8/NxsPt1yQeGxODlEGZo/siXvC6EuuiwOIQswklsdJFA34z8yLIkFn0wHV7Q", | ||
"LIGDu/TiLE3eKr+gFtku+WVIx44seskcn4Xg/m6e6Eqa8DBH0WKGvM3/5BZZhoTTalJN0mKI6E0kaOCq", | ||
"mlRT6D8DAAD//9SMdbW0AwAA", | ||
} | ||
|
||
// Returns the Swagger specification corresponding to the generated code | ||
// in this file. | ||
func GetSwagger() (*openapi3.Swagger, error) { | ||
zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, "")) | ||
if err != nil { | ||
return nil, fmt.Errorf("error base64 decoding spec: %s", err) | ||
} | ||
zr, err := gzip.NewReader(bytes.NewReader(zipped)) | ||
if err != nil { | ||
return nil, fmt.Errorf("error decompressing spec: %s", err) | ||
} | ||
var buf bytes.Buffer | ||
_, err = buf.ReadFrom(zr) | ||
if err != nil { | ||
return nil, fmt.Errorf("error decompressing spec: %s", err) | ||
} | ||
|
||
swagger, err := openapi3.NewSwaggerLoader().LoadSwaggerFromData(buf.Bytes()) | ||
if err != nil { | ||
return nil, fmt.Errorf("error loading Swagger: %s", err) | ||
} | ||
return swagger, nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
openapi: "3.0.1" | ||
info: | ||
version: 1.0.0 | ||
title: Test Server | ||
license: | ||
name: MIT | ||
components: | ||
schemas: | ||
SchemaObject: | ||
properties: | ||
role: | ||
type: string | ||
firstName: | ||
type: string | ||
required: | ||
- role | ||
- firstName | ||
responses: | ||
ResponseObject: | ||
description: A simple response object | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
Field: | ||
$ref: "#/components/schemas/SchemaObject" | ||
required: [ Field ] | ||
text/plain: | ||
schema: | ||
type: string | ||
parameters: | ||
ParameterObject: | ||
description: a parameter | ||
in: query | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
Field: | ||
$ref: "#/components/schemas/SchemaObject" | ||
required: [ Field ] | ||
text/plain: | ||
schema: | ||
type: string | ||
requestBodies: | ||
RequestBody: | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
Field: | ||
$ref: "#/components/schemas/SchemaObject" | ||
required: [ Field ] | ||
text/plain: | ||
schema: | ||
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package components | ||
|
||
//go:generate sh -c "oapi-codegen --package=components components.yaml > components.gen.go" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
func RegisterHandlers(router runtime.EchoRouter, si ServerInterface) { | ||
{{if .}} | ||
wrapper := ServerInterfaceWrapper{ | ||
Handler: si, | ||
} | ||
{{end}} | ||
{{range .}}router.{{.Method}}("{{.Path | swaggerUriToEchoUri}}", wrapper.{{.OperationId}}) | ||
{{end}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters