Skip to content

Commit

Permalink
chore: corrections for line spaces, error handling, stray comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Prashansa-K committed Aug 19, 2024
1 parent 4af8ef3 commit d14c3ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
18 changes: 5 additions & 13 deletions openapi2kong/jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,15 @@ func dereferenceSchema(sr *base.SchemaProxy, seenBefore map[string]*base.SchemaP
}

s := sr.Schema()

for _, schema := range s.AllOf {
dereferenceSchema(schema, seenBefore)
}

for _, schema := range s.AnyOf {
dereferenceSchema(schema, seenBefore)
}

for _, schema := range s.OneOf {
dereferenceSchema(schema, seenBefore)
allSchemas := [][]*base.SchemaProxy{s.AllOf, s.AnyOf, s.OneOf}
for _, schemas := range allSchemas {
for _, schema := range schemas {
dereferenceSchema(schema, seenBefore)
}
}

schemaMap := s.Properties
schema := schemaMap.First()

for schema != nil {
dereferenceSchema(schema.Value(), seenBefore)
schema = schema.Next()
Expand Down Expand Up @@ -70,7 +63,6 @@ func extractSchema(s *base.SchemaProxy) string {
finalSchema := make(map[string]interface{})

if s.IsReference() {
// Add ref key and string
finalSchema["$ref"] = s.GetReference()
} else {
// copy the primary schema, if no ref string is present
Expand Down
16 changes: 5 additions & 11 deletions openapi2kong/openapi2kong.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,12 @@ func getKongTags(doc v3.Document, tagsProvided []string) ([]string, error) {
}

kongTags, ok := doc.Extensions.Get("x-kong-tags")

if !ok {
// there is no extension by the name "x-kong-tag", so return an empty array
return make([]string, 0), nil
}

resultArray := make([]string, len(kongTags.Content))

for i, v := range kongTags.Content {
var tagsValue interface{}
err := yaml.Unmarshal([]byte(v.Value), &tagsValue)
Expand Down Expand Up @@ -176,13 +174,9 @@ func getXKongComponents(doc v3.Document) (*map[string]interface{}, error) {

var xKong interface{}
_ = yaml.Unmarshal(xKongComponentsBytes, &xKong)

switch val := xKong.(type) {
case map[string]interface{}:
components = val

default:
return nil, fmt.Errorf("expected '/components/x-kong' to be a YAML object")
components, err = jsonbasics.ToObject(xKong)
if err != nil {
return nil, fmt.Errorf("expected '/components/x-kong' to be a JSON/YAML object")
}

return &components, nil
Expand Down Expand Up @@ -398,7 +392,7 @@ func getPluginsList(
var pluginConfig map[string]interface{}
err = json.Unmarshal(jsonstr, &pluginConfig)
if err != nil {
return nil, fmt.Errorf(fmt.Sprintf("failed to parse JSON object for '%s': %%w", extensionName), err)
return nil, fmt.Errorf("failed to parse JSON object for '%s': %w", extensionName, err)
}

pluginConfig["name"] = pluginName
Expand Down Expand Up @@ -692,7 +686,7 @@ func Convert(content []byte, opts O2kOptions) (map[string]interface{}, error) {
return nil, fmt.Errorf("failed to create plugins list from document root: %w", err)
}

// // get the OIDC stuff from top level, bail out if the requirements are unsupported
// get the OIDC stuff from top level, bail out if the requirements are unsupported
if opts.OIDC {
docOIDCdefaults, err = getOIDCdefaults(doc.Security, doc, nil, opts.IgnoreSecurityErrors)
if err != nil {
Expand Down

0 comments on commit d14c3ed

Please sign in to comment.