Code Monkey home page Code Monkey logo

Comments (6)

rubenfonseca avatar rubenfonseca commented on August 9, 2024 1

Hi @MCR2019 I've tried to use https://redocly.github.io/redoc/ to upload the OpenAPI generated by your code sample, and I see this.

image

With you change, what would be different in the UI?

from powertools-lambda-python.

rubenfonseca avatar rubenfonseca commented on August 9, 2024

Looking at this now

from powertools-lambda-python.

MCR2019 avatar MCR2019 commented on August 9, 2024

Hi @rubenfonseca , thanks for taking a look at that so quickly and apologies that my example wasn't as accurate as it could be.

I've had another look at it and updated the requestBody so that it uses a Pydantic schema for the type (which is what I would use to enable validation).

example code is now:

from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.event_handler.openapi.params import Body, Path
from aws_lambda_powertools.shared.types import Annotated
from pydantic import BaseModel, Extra, Field

app = APIGatewayRestResolver(enable_validation=True)


class ExamplePayloadSchema(BaseModel):
    """Pydantic example payload schema."""

    example_attribute: str = Field(description="Warning limit for remaining IDs.", format="number")

    class Config:
        """Pydantic model config."""

        extra = Extra.forbid


@app.put(
    "/example-resource/<path_parameter>",
)
def put(
        path_parameter: Annotated[str, Path(description="test path description appears at schema and higher level", example="example01")],
        event_body: Annotated[ExamplePayloadSchema, Body(description="test body description only appears at the schema level")]
):
    pass


if __name__ == "__main__":
    openapi_json_schema = app.get_openapi_json_schema()

    with open("openapi_spec_without.json", "w") as json_spec_file:
        json_spec_file.writelines(openapi_json_schema)

this produces the spec:
openapi_spec_without.json

which when an html file is generated using redoc-cli bundle -o openapi/index_without.html openapi/openapi_spec_without.json looks like this:
image

(There is no description for the request body)

  • Manually updating for desired output:

Manually updating the json spec file to include a description in the requestBody (line 46):
openapi_spec_with.json

and generating html file with redoc-cli bundle -o openapi/index_with.html openapi/openapi_spec_with.json gives an html file which shows a description for the request body:

image

Hopefully that illustrates the issue more clearly, I'll keep looking into what's going on and add more details if I can.

Thanks

from powertools-lambda-python.

rubenfonseca avatar rubenfonseca commented on August 9, 2024

This helps a lot! Let me see what's missing on our side.

from powertools-lambda-python.

github-actions avatar github-actions commented on August 9, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

from powertools-lambda-python.

github-actions avatar github-actions commented on August 9, 2024

This is now released under 2.31.0 version!

from powertools-lambda-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.