Coder Social home page Coder Social logo

Comments (5)

nightstream avatar nightstream commented on June 20, 2024

found this:

def _build_merged_dict(self):
defined_dict = self.__dict__.copy()
autodoc_dict = self._autodoc or {}
default_dict = self._default
merged_dict = {}
for d in (default_dict, autodoc_dict, defined_dict):
cleaned = {
k: v for k, v in d.items() if v and not k.startswith("_")
}
merged_dict.update(cleaned)
return merged_dict

the _build_merged_dict function can merge three dicts which names are default_dict, autodoc_dict and defined_dict into one, but when the key is 'parameters' for example, it will just cover the autodoc_dict's value by the defined_dict's value and not merge these values.

from sanic-ext.

ahopkins avatar ahopkins commented on June 20, 2024

@nightstream Thanks for debugging this! You are right, swapping the order fixes the problem.

@app.get("/<pk:strorempty>")
async def handler(request: Request, pk: Optional[str]):
    """
    openapi:
    ---
    parameters:
      - pk:
        name: pk
        in: path
        required: false
        schema:
            type: string
    """
    return json({"foo": pk})

With this line in place, it works as expected

for d in (default_dict, defined_dict, autodoc_dict):

image
Will get this in the next bug release coming soon.

from sanic-ext.

ahopkins avatar ahopkins commented on June 20, 2024

There is probably a bigger issue that needs to be addressed in that Optional[str] should auto-imply strorempty, which should mark it as required=false automatically. But a simple fix for now is the order.

from sanic-ext.

ahopkins avatar ahopkins commented on June 20, 2024

So, upon further thought, this one might need a little more consideration. Because there are certain things that we DO want defined_dict to take precedence. Primarily when you do not intend for docstring to be included and want to override the description or summary.

I think we either need another hierarchy to split apart decorators and route definitions, or carve an exception into the priority ordering for this use case.

from sanic-ext.

ahopkins avatar ahopkins commented on June 20, 2024

Just pushed another change to that PR. This should do the trick and not mess up the existing preferences.

from sanic-ext.

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.