Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

Commit

Permalink
Added Open API 3 support, Insomnia v4 support, new config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyb3roptik committed Jan 29, 2020
1 parent d02da35 commit 7781e44
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 84 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
./swaggomnia
config.json
swagger.yaml
swaggomnia
test.json
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ Generate Swagger Documentation from Insomnia REST Client.
<br />
*This is a fork of [swaggymnia](https://github.com/mlabouardy/swaggymnia) which is now dead.*

## Releases
[![Build Status](https://travis-ci.com/Fyb3roptik/swaggomnia.svg?branch=master)](https://travis-ci.com/Fyb3roptik/swaggomnia) | [Latest Release](https://github.com/Fyb3roptik/swaggomnia/releases/latest)
## Changelog

`2.0`
* Open API 3 support
* Insomnia v4 support
* New Config Format

## How to use it

Expand Down Expand Up @@ -59,9 +63,7 @@ $ swaggomnia generate -i examples/watchnow.json -c examples/config.json -o json
{
"title" : "API Name",
"version" : "API version",
"host" : "API URL",
"basePath" : "Base URL",
"schemes" : "HTTP protocol",
"basePath" : "https://api.domain.com/v1",
"description" : "API description"
}
```
Expand Down
2 changes: 1 addition & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func main() {
app := cli.NewApp()
app.Name = "swaggonmia"
app.Usage = "Insomnia to Swagger converter"
app.Version = "1.0.1"
app.Version = "1.1.0"
app.Compiled = time.Now()
app.Authors = []*cli.Author{
&cli.Author{
Expand Down
4 changes: 1 addition & 3 deletions examples/config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"title" : "WatchNow API",
"version" : "1.0.0",
"host" : "api.watchnow.com",
"basePath" : "/v1",
"schemes" : "https",
"basePath" : "https://api.domain.com/v1",
"description" : "This API allows you to get in real time movies playing in theatre."
}
2 changes: 1 addition & 1 deletion swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (s Swagger) generateYAML() {
}

func fetchVariables(resource *Resource) {
re := regexp.MustCompile("/{(.*?)}#*")
re := regexp.MustCompile("/{{ (.*?) }}#*")
for _, param := range re.FindAllStringSubmatch(resource.URL, -1) {
resource.InsomniaParams = append(resource.InsomniaParams, param[1])
}
Expand Down
114 changes: 85 additions & 29 deletions template.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 8 additions & 16 deletions tmpl/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
swagger: "2.0"
openapi: 3.0.0
info:
description: "{{ .Config.Description }}"
version: "{{ .Config.Version }}"
title: "{{ .Config.Title }}"
host: "{{ .Config.Host }}"
basePath: "{{ .Config.BasePath }}"
servers:
- url: "{{ .Config.BasePath }}"
tags:
{{ range $key, $value := .Entities }}
- name: "{{ $key | GetGroupName }}"
description: ""
{{ end }}
schemes:
- "{{ .Config.Schemes }}"
paths:
{{- range $key, $paths := .Entities }}
{{- range $path, $resources := $paths }}
Expand All @@ -23,28 +21,22 @@ paths:
summary: "{{ $resource.Name }}"
{{- if or $resource.InsomniaParams $resource.Body.Params $resource.Headers }}
{{- if $resource.Body.MimeType }}
consumes:
- "{{ $resource.Body.MimeType }}"
description: "{{ $resource.Description }}"
{{- end }}
parameters:
{{- range $p, $param := $resource.InsomniaParams}}
- name: "{{ $param }}"
in: "path"
type: "string"
description: ""
required: true
{{- end }}
{{- range $p, $param := $resource.Body.Params}}
- name: "{{ $param.Name }}"
in: "formData"
type: "string"
schema:
type: "string"
description: ""
required: true
{{- end }}
{{- range $p, $param := $resource.Headers}}
- name: "{{ $param.Name }}"
in: "header"
type: "string"
schema:
type: "string"
description: ""
required: true
{{- end }}
Expand Down

0 comments on commit 7781e44

Please sign in to comment.