Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for attributes with multiple types #51

Merged
merged 3 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,24 @@ func collectFlagsAndOptions() map[string]map[string][]string {
if attribute.Value.Enum != nil {

for _, enum := range attribute.Value.Enum {
allFlags[command][flagName] = append(allFlags[command][flagName], enum.(string))
allFlags[command][flagName] = append(allFlags[command][flagName], enum.(string)+" ")
}

}

//Collect valid flag values in case of AnyOf
if attribute.Value.AnyOf != nil {
for _, item := range attribute.Value.AnyOf {

if item.Value.Enum != nil {
for _, enum := range item.Value.Enum {
allFlags[command][flagName] = append(allFlags[command][flagName], enum.(string)+" ")
}
}

}
}

}

}
Expand Down
16 changes: 15 additions & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,21 @@ func parseCommand(format string, verbose bool) {
continue
}

switch attribute.Value.Type {
theType := attribute.Value.Type

//If no type is specified, look deeper
if theType == "" && attribute.Value.AnyOf != nil {
for _, item := range attribute.Value.AnyOf {

if item.Value.Type != "" {
theType = item.Value.Type
break
}

}
}

switch theType {
case "relationship":
//Special case for arrays in relationships
for _, item := range strings.Split(value, ",") {
Expand Down
30 changes: 23 additions & 7 deletions help.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"regexp"
Expand Down Expand Up @@ -57,13 +56,13 @@ func printHelp() {
for _, path := range doc.Paths {
for _, method := range path.Operations() {

var group string
group := ""

json.Unmarshal(method.ExtensionProps.Extensions["x-resource"].(json.RawMessage), &group)

//Fallback to Tag if x-resource group is missing
if group == "" {
if method.Extensions["x-resource"] == nil {
//Fallback to Tag if x-resource group is missing
group = strings.Title(method.Tags[0])
} else {
group = method.Extensions["x-resource"].(string)
}

//Add a space before each uppercase letter
Expand Down Expand Up @@ -252,11 +251,28 @@ func printHelpCommand(command string) {
theType = inheritType
}

enum := attribute.Value.Enum

//Special case: ProviderConfiguration and maybe others?
if theType == "" && attribute.Value.AnyOf != nil {
for _, item := range attribute.Value.AnyOf {

if item.Value.Enum != nil {
enum = item.Value.Enum
}

if item.Value.Type != "" {
theType = item.Value.Type
}

}
}

flags[flagName] = Parameter{
varType: theType,
description: description,
required: required,
enum: attribute.Value.Enum,
enum: enum,
}

}
Expand Down