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

Allow using a response reference in the list of responses #303

Merged
merged 5 commits into from
Sep 29, 2022

Conversation

jacob-pro
Copy link
Contributor

@jacob-pro jacob-pro commented Sep 26, 2022

First of all this updates the Responses struct to have:

pub responses: BTreeMap<String, RefOr<Response>>,

Which should now correctly match the way the OpenAPI specs work:

      responses:
        '200':
          description: Success
        '400':
          "$ref": "#/components/responses/BadRequest"

And then it enables you to use a reference in the path macro:

    responses: (
        (status = 200, description = "Success"),
        (status = 400, response = crate::BadRequestResponse),
    )

where crate::BadRequestResponse is a type that implements ToResponse and is used in:

#[openapi(
    components(
        responses(
            crate::BadRequestResponse,
        )
    ),
)]

(Note I had to use response instead of just ref since it is a reserved keyword)

This should close #300

@jacob-pro
Copy link
Contributor Author

Hey @juhaku - please can you let me know what you think of this?

@juhaku
Copy link
Owner

juhaku commented Sep 28, 2022

Hey @juhaku - please can you let me know what you think of this?

Hi @jacob-pro I will try to check this out today / tomorrow. I am bit busy during these days unfortunately. Thanks for patience. 🙂 .

I took a quick look and overall looks quite good. One thing I am wondering whether the response_ref should actually just be a response. This would work as well as a first go. But with response we could introduce possibility to inline the response as well.

Also the Parse implementation is currently implemented to ResponseValue struct. But the response could also be changed to an enum like.

enum Response {
  Value(ResponseValue),
  Ref(ResponseRef),
}

@jacob-pro
Copy link
Contributor Author

@juhaku No problem, thanks for all the quick responses!

I have updated the PR as requested - hopefully I have understood correctly?

Copy link
Owner

@juhaku juhaku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, awesome 🥇

@juhaku
Copy link
Owner

juhaku commented Sep 29, 2022

I have updated the PR as requested - hopefully I have understood correctly?

Yeah pretty much yes 🙂

@juhaku juhaku merged commit ab555d6 into juhaku:master Sep 29, 2022
@jacob-pro jacob-pro deleted the #300-response-ref branch September 29, 2022 16:59
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

Successfully merging this pull request may close these issues.

Use component response in path responses list
2 participants