https://github.com/denismakogon/fn-openapi-v3
Fn-powered serverless application OpenAPI v3.0.0 generator tool
https://github.com/denismakogon/fn-openapi-v3
fnproject go golang openapi3 serverless swagger
Last synced: 11 months ago
JSON representation
Fn-powered serverless application OpenAPI v3.0.0 generator tool
- Host: GitHub
- URL: https://github.com/denismakogon/fn-openapi-v3
- Owner: denismakogon
- License: apache-2.0
- Created: 2018-01-16T20:38:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-17T18:35:11.000Z (over 8 years ago)
- Last Synced: 2025-02-12T07:45:36.352Z (over 1 year ago)
- Topics: fnproject, go, golang, openapi3, serverless, swagger
- Language: Go
- Size: 16.6 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
OpenAPI v3 spec generator tool for Fn applications
==================================================
Idea
----
The Fn application is nothing but set of function where each has its own HTTP route for execution.
What if there's a way to build client binding for the particular serverless application?
This library and tool are designed to provide necessary API to generate OpenAPI v3.0.0 specification using Function spec language.
Function spec language
----------------------
This tool relies on improved Swagger API 2.0 plus additional inline referencing features
that are missing in both Swagger 2.0 and OpenAPI 3.0 that are allowing developers to structure their application in more modular way.
Function spec example
---------------------
```yaml
version: 0.0.1
description: Functions spec that describes Fn-powered serverless application
functions:
createUser:
handler: handler.create
events:
- http:
method: post
fn: ${file(models/func.yml):first}
documentation:
summary: Create User
description: Creates a user and then sends a generated password email
requestBody:
schema: ${file(models/request.json)}
parameters:
- name: username
description: The username for a user to create
required: true
in: path
schema:
type: string
pattern: "^[-a-z0-9_]+$"
- name: membershipType
description: The user's Membership Type
required: true
in: query
schema:
type: string
enum:
- premium
- standard
responses:
200:
description: create a user
content:
application/json:
schema: ${file(models/request.json)}
500:
description: error
content:
application/json:
schema: ${file(models/error.json)}
```
This sample you can find [here](examples/fn.yml)
using the following code:
```go
package main
import (
"fmt"
"github.com/denismakogon/fn-openapi/models"
"io/ioutil"
"os"
)
func main() {
yamlFile, err := ioutil.ReadFile(os.Args[1])
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
var fn models.Fn
err = fn.Unmarshal(yamlFile, os.Stdout)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
var oai models.OpenAPISpec
err = oai.FromFnSpec("http://localhost:8080", &fn)
err = oai.Marshal(os.Stdout)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}
```
it is possible to turn Function spec into valid OpenAPI v3 specification.
To confirm that spec is valid use the following command:
```bash
docker run --rm -i -v `pwd`:/go fnproject/openapiv3-validator:0.0.1 /go/examples/openapi.yml
```