danielgtaylor / restish

Restish is a CLI for interacting with REST-ish HTTP APIs with some nice features built-in
https://rest.sh/
MIT License
717 stars 69 forks source link

anyOf option is not available as flag #257

Open deefha opened 2 months ago

deefha commented 2 months ago

I have and API endpoint with following schema (taken from restish some_api some_endpoint --help:

Option Schema:
{                                                                                                                                                                                                                               
      --id: [                                                                                                                                                                                                                       
        (integer)                                                                                                                                                                                                                   
      ]                                                                                                                                                                                                                             
      --name: (string) Name                                                                                                                                                                                                         
      --content: (string) Content                                                                                                                                                                                                   
      --type: [                                                                                                                                                                                                                     
        (string enum:A,AAAA,CAA,CDNSKEY,CDS,CERT,CNAME,DNAME,DNSKEY,DS,HINFO,HTTPS,LOC,MX,NS,PTR,SMIMEA,SOA,SRV,SSHFP,SVCB,TLSA,TXT,URI) RecordType                                                                                 
      ]                                                                                                                                                                                                                             
      --zone: (string) Zone                                                                                                                                                                                                         
      --zone-type: [                                                                                                                                                                                                                
        (string enum:internal,public,catalog,rpz) ZoneType                                                                                                                                                                          
      ]                                                                                                                                                                                                                             
      --note: (string) Note                                                                                                                                                                                                         
      --owner: [                                                                                                                                                                                                                    
        anyOf{                                                                                                                                                                                                                      
          (integer)                                                                                                                                                                                                                 
          (string)                                                                                                                                                                                                                  
        }                                                                                                                                                                                                                           
      ]                                                                                                                                                                                                                             
      --is-active: (boolean) Is Active                                                                                                                                                                                              
      --ttl: (string) Ttl                                                                                                                                                                                                           
      --limit: (integer min:-1) Limit                                                                                                                                                                                               
      --offset: (integer default:0) Offset                                                                                                                                                                                          
      --order: [                                                                                                                                                                                                                    
        (string enum:id,id_desc,name,name_desc,content,content_desc,type,type_desc,zone,zone_desc,owner,owner_desc,ttl,ttl_desc,is_active,is_active_desc) OutputOrder                                                               
      ]                                                                                                                                                                                                                             
      --accept-language: (string default:en) Accept-Language                                                                                                                                                                        
}

Then in Flags section is this info:

Flags:
      --accept-language string   HTTP header indicating client's preferred natural language. (default "en")
      --content string           Content of the record or pattern to retrieve. The string between the two slashes is evaluated as a regular expression. The wildcard form is also supported.
  -h, --help                     help for get-records
      --id ints                  Internal ID(s) of the record(s) to retrieve.
      --is-active                Retrieve only records in the specified state.
      --limit int                Retrieve the first *limit* records or fewer if not enough records. Use -1 for unlimited.   
                                 *Default value* : 50
      --name string              Name of the record or pattern to retrieve. The string between the two slashes is evaluated as a regular expression. The wildcard form is also supported.
      --note string              Note of the record or pattern to retrieve. The string between the two slashes is evaluated as a regular expression. The wildcard form is also supported.
      --offset int               Skip *offset* records from the beginning of the result.
      --order strings            Sort the result by this field and order (ascending or descending). (default [id])
      --ttl min:max              Retrieve only records with the specified TTL. Possible values are either exact value or range min:max. Examples: `300`, `300:`, `:300`, `300:3600`.
      --type strings             Retrieve only records with the specified type(s).
      --zone string              Retrieve only records belonging to the specified zone(s). The string between the two slashes is evaluated as a regular expression. The wildcard form is also supported.
      --zone-type strings        Retrieve only records of the specified zone type(s).

As you can see, there is no --owner flag, although in the schema is this field defined as anyOf. When I try to use --owner flag, an error appears indeed:

Error: unknown flag: --owner

I can use global -q flag as an workaround (-q owner=johndoe), but it sure will be better if the --owner flag was generated properly.

I assume there is a problem with anyOf type maybe? I found this PR https://github.com/danielgtaylor/restish/pull/85 where is future support of anyOf mentioned...