nelmio / NelmioApiDocBundle

Generates documentation for your REST API from annotations
MIT License
2.23k stars 834 forks source link

Specify the input other than FormType #12

Closed ruudk closed 12 years ago

ruudk commented 12 years ago

I'm using FOSRestBundle with JMSSerializerBundle for my API. The input isn't specified with a Form but with a Class that is annotated with JMSSerializer annotations.

Would it be possible to support this too?

Seldaek commented 12 years ago

It definitely would/should be possible yes :) If you feel like contributing it, even better.

ruudk commented 12 years ago

What would be the best way to set this up? Maybe I can find some time to develop it.

Seldaek commented 12 years ago

There are a few things to change:

willdurand commented 12 years ago
<?php

class AbstractFormatter implements FormatterInterface
{
    protected $registeredParsers = array();

    // …

    protected function getData(ApiDoc $apiDoc, Route $route)
    {
        // …

        if (null !== $inputClass = $apiDoc->getInputClass()) {
            foreach ($this->registeredParsers as $parser) {
                if ($parser->supports($inputClass)) {
                    $data['parameters'] = $parser->parse(new $inputClass());

                    break;
                }
            }

            // ...
        }
    }
}
grEvenX commented 12 years ago

@willdurand was that a suggestion for the interface? I can't find the code implemented in the git repo?

willdurand commented 12 years ago

No it's a suggestion to handle the different parsers.

willdurand commented 12 years ago

@ruudk any news on this?

ruudk commented 12 years ago

@willdurand Sorry, but I don't have time for it right now. Quite busy with the development of the API.

evillemez commented 12 years ago

Enabling the suggestions mentioned here seems like a necessary step before tackling issue #47, which would enable the suggestions in issue #48.

If no one is working on this, I have some thoughts on implementing it, and as I have a project in the early stages that needs it, I can justify time to work on it.

evillemez commented 12 years ago

To implement this, I was thinking of doing the following (I just noticed some refactoring going on, so I might have some things in the wrong spot conceptually):

This way it would leave the door open for implementing new parsers down the road fairly easily. Thoughts?

EDIT: And this raises a question... if someone doesn't have JMS installed, then what? Just document that it's something you can enable manually via configuration if you do have it installed?

willdurand commented 12 years ago

Why not just registering parsers in the Extractor? Then, we just iterate over the list of parsers, and that's it.

evillemez commented 12 years ago

Yeah, that's simpler... remove passing parsers via the constructor and just have a registerParser setter method?

willdurand commented 12 years ago

yes

evillemez commented 12 years ago

This can be closed now.

evillemez commented 12 years ago

ping @willdurand This one can be closed too