GithubHelp home page GithubHelp logo

Comments (5)

lafrech avatar lafrech commented on May 23, 2024 1

Done in #828.

Released in apispec 6.2.0.

Thanks.

I love it when a plan comes together

from apispec.

lafrech avatar lafrech commented on May 23, 2024

Reading "test_callback_schema_v3", it looks like a real schema is required (but not a schema name as string, but full path as string works).

I agree it would be nicer to allow a schema name.

Can't look at it right now (and not on top of my priorities since I don't use callbacks). Would you like to investigate and perhaps add the feature?

from apispec.

codectl avatar codectl commented on May 23, 2024

@lafrech thank you for having a look.

I had a look at your test and it got me wondering how that test is working because I also had a look at the _resolve_refs_in_operation and I don't see any mention to callbacks:

# apispec/core.py
...
    def _resolve_refs_in_operation(self, operation) -> None:
        if "parameters" in operation:
            parameters = []
            for parameter in operation["parameters"]:
                parameter = self.get_ref("parameter", parameter)
                self._resolve_refs_in_parameter_or_header(parameter)
                parameters.append(parameter)
            operation["parameters"] = parameters
        if "requestBody" in operation:
            self._resolve_refs_in_request_body(operation["requestBody"])
        if "responses" in operation:
            responses = {}
            for code, response in operation["responses"].items():
                response = self.get_ref("response", response)
                self._resolve_refs_in_response(response)
                responses[code] = response
            operation["responses"] = responses

It got me wondering how that test case was even working so I went to check the conftest:

# tests/confest.py

...
def make_spec(openapi_version):
    ma_plugin = MarshmallowPlugin()
    spec = APISpec(
        title="Validation",
        version="0.1",
        openapi_version=openapi_version,
        plugins=(ma_plugin,),
    )
    return namedtuple("Spec", ("spec", "marshmallow_plugin", "openapi"))(
        spec, ma_plugin, ma_plugin.converter
    )


@pytest.fixture(params=("2.0", "3.0.0"))
def spec_fixture(request):
    return make_spec(request.param)

So that test case in question is testing MarshmallowPlugin which it does contain some spec resolution for callbacks so that is why that test case works. The bug is that apispec.core does not resolve callbacks and it needs to be added.

I can implement that condition and create a test case for apispec.core, no problem !

Also would you know why does MarchmallowPlugin implement a schema resolver? To me that seems redundant considering apispec.core already provides logic to resolve schemas. Having MarchmallowPlugin schema resolver override the core resolver can lead to inconsistencies as seen in the example above. Would you know what motivated the decision to have MarchmallowPlugin a schema resolver of its own?

from apispec.

lafrech avatar lafrech commented on May 23, 2024

Oh, right.

The point of the marshmallow schema resolver is to transform a Schema object into a dict or a ref. You're right that transforming a string into a ref should be done by core.

from apispec.

codectl avatar codectl commented on May 23, 2024

PR #828 can close this issue

from apispec.

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.