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

Specify enum paths in OpenAPI #887

Open
musjj opened this issue Sep 29, 2024 · 0 comments
Open

Specify enum paths in OpenAPI #887

musjj opened this issue Sep 29, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@musjj
Copy link

musjj commented Sep 29, 2024

Description of the feature

Currently, there's no nice way to specify enums in paths. You can do something like this:

pub struct Api;

#[derive(Enum, Deserialize)]
#[oai(rename_all = "lowercase")]
pub enum Choices {
    Foo,
    Bar,
}

#[OpenApi]
impl Api {
    #[oai(path = "/pick/:choices", method = "get")]
    pub async fn pick(&self, choices: Path<Choices>) -> PlainText<String> {
        PlainText("hello world".to_string())
    }
}

But the resulting paths will be /pick/Foo and /pick/Bar (rename_all is ignored). The enum choices will not be included in the spec either.

In OpenAPI, it should be possible to define enums in the path:

paths:
  /pick/{choices}:
    get:
      parameters:
      - in: path
        name: choices
        required: true
        type: string
        enum: [foo, bar]

It would be nice if we can express this constraint with poem-openapi.

@musjj musjj added the enhancement New feature or request label Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant