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

Define a query in path as an Enum #19

Open
sofianinho opened this issue Nov 17, 2017 · 0 comments
Open

Define a query in path as an Enum #19

sofianinho opened this issue Nov 17, 2017 · 0 comments

Comments

@sofianinho
Copy link

sofianinho commented Nov 17, 2017

Hi,

Thanks for this project. Great job, well written documentation and really useful for my work.

I was wondering whether it was possible to define an enum in an in-path query (https://swagger.io/docs/specification/2-0/enums/).
In swagger, you can write something like this:

paths:
  /users:
    get:
      parameters:
        - in: query
          name: role
          type: string
          enum: [user, poweruser, admin]
          required: true

With swag/endpoint's API, you can do something like this using endpoint.Query function:

var PostSession = endpoint.New("post", "/session/", "Create a new session on your  manager",
	endpoint.Query("name", "string", "the name for this session", false),
	endpoint.Query("scheduler", "string", "the VNF scheduler for this session (system, docker)", false),
	endpoint.Handler(NewSession),
	endpoint.Response(http.StatusCreated, types.Session{}, "Successfully created a new session"),
	endpoint.Description("Session creation in your manager"),
	endpoint.Tags("Session"),
)

which is already expressive enough. What I would like to do, is having the (system, docker) comment as an enum instead. This would then make initial control over the choices the user does, instead of doing it in the code (which is far from being painful or anything, just a nice thing to have if possible). I guess replacing the "typ" in the Query function by a schema struct would do the trick. Something like this:

type Schema struct{
    type     string
    enum   []string 
}

func Query(name string, typ Schema, description string, required bool) Option

Or for more simplicity, modifying the function itself with something like this;

func Query(name, typ string, enum []string, description string, required bool) Option

Do you think it's worth a pull request ?

Thanks for your feedback on this.
Sofiane

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant