Skip to content

Commit

Permalink
Added blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
rjtokenring committed Oct 16, 2024
1 parent 9bc2e93 commit ccc3a6f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 66 deletions.
23 changes: 20 additions & 3 deletions openapi-merger/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package main

import (
"encoding/json"
"fmt"
"log"
"os"
"slices"

"github.com/getkin/kin-openapi/openapi3"
"gopkg.in/yaml.v3"

_ "embed"
)

const (
Expand All @@ -19,10 +23,22 @@ const (
MergedOpenApi = BasePath + "swagger.yaml"
)

var pathBlacklist = make(map[string]bool)
//go:embed path-blacklist.json
var pathBlacklist string

type blacklist struct{
Blacklist []string `json:"blacklist"`
}

func main() {

// Load blacklist
var bl blacklist
_ = json.Unmarshal([]byte(pathBlacklist), &bl)

log.Println("Merging OpenAPI specifications...")
log.Println("Blacklisted paths: ", bl.Blacklist)

// Load the main OpenAPI specification
loader := openapi3.NewLoader()
docIOT, err := loader.LoadFromFile(IotAPIOpenApi)
Expand All @@ -32,7 +48,7 @@ func main() {

mergedPaths := []openapi3.NewPathsOption{}
for _, path := range docIOT.Paths.InMatchingOrder() {
if _, ok := pathBlacklist[path]; ok {
if slices.Contains(bl.Blacklist, path) {
continue
}
pathItem := docIOT.Paths.Find(path)
Expand Down Expand Up @@ -68,7 +84,8 @@ func main() {

// Merge the paths
for _, path := range docVIEWS.Paths.InMatchingOrder() {
if _, ok := pathBlacklist[path]; ok {
if slices.Contains(bl.Blacklist, path) {
log.Println("Blacklisted path: ", path)
continue
}
pathItem := docVIEWS.Paths.Find(path)
Expand Down
3 changes: 3 additions & 0 deletions openapi-merger/path-blacklist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"blacklist": ["/groups/v1/sketches"]
}
63 changes: 0 additions & 63 deletions spec/v2/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4610,69 +4610,6 @@ paths:
summary: Move a resource under a folder
tags:
- folders
/groups/v1/sketches:
get:
description: Returns all sketches to which user has access to
operationId: ListSketches
parameters:
- example: D3FB5026-7337-4AB3-B203-2E6792C7C65B
in: header
name: X-Organization
schema:
format: uuid
type: string
x-oapi-codegen-extra-tags:
validate: omitnil,uuid
responses:
"200":
content:
application/json:
schema:
items:
$ref: '#/components/schemas/Sketch'
type: array
description: Success
"400":
content:
application/json:
schema:
$ref: '#/components/schemas/ValidationError'
description: Bad request
"401":
content:
application/json:
schema:
$ref: '#/components/schemas/APIError'
description: Authentication failed
"403":
content:
application/json:
schema:
$ref: '#/components/schemas/APIError'
description: Access denied
"404":
content:
application/json:
schema:
$ref: '#/components/schemas/APIError'
description: Not found
"500":
content:
application/json:
schema:
$ref: '#/components/schemas/APIError'
description: Internal server error
default:
content:
application/json:
schema:
$ref: '#/components/schemas/APIError'
description: Default error
security:
- jwt_bearer_authentication: []
summary: Get all sketches
tags:
- views
/groups/v1/things:
get:
description: Returns all things to which user has access to
Expand Down

0 comments on commit ccc3a6f

Please sign in to comment.