Skip to content

Support YAML output from SwaggerCommand with --yaml #1695

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

Merged
merged 2 commits into from
Mar 3, 2018

Conversation

dkarlovi
Copy link
Contributor

@dkarlovi dkarlovi commented Feb 9, 2018

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #1688
License MIT
Doc PR api-platform/docs#389

Closes #1688.

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

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

Can you also add a test in the CI (like https://github.com/api-platform/core/blob/master/.travis.yml#L56) to check with the Swagger validator that the generated YAML file is valid?

@@ -63,7 +66,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$documentation = new Documentation($this->resourceNameCollectionFactory->create(), $this->apiTitle, $this->apiDescription, $this->apiVersion, $this->apiFormats);
$data = $this->documentationNormalizer->normalize($documentation);
$content = json_encode($data, JSON_PRETTY_PRINT);
if ($input->getOption('yaml')) {
Copy link
Member

Choose a reason for hiding this comment

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

$input->getOption('yaml') ? Yaml::dump($data) : json_encode($data, JSON_PRETTY_PRINT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you insist. 👍 I try to avoid those.

@dkarlovi
Copy link
Contributor Author

dkarlovi commented Feb 12, 2018

Can you also add a test in the CI (like https://github.com/api-platform/core/blob/master/.travis.yml#L56) to check with the Swagger validator that the generated YAML file is valid?

Sure.

Edit: good call, it seems to be invalid.

@dkarlovi dkarlovi force-pushed the swagger-command-yaml branch from 66cbedd to e249e86 Compare February 13, 2018 07:06
@dkarlovi
Copy link
Contributor Author

It seems like this is the output:

swagger: '2.0'
basePath: /
info:
    title: 'My Dummy API'
    version: 0.0.0
    description: 'This is a test API.'
paths: null
definitions: null

while this is supposed to be the output:

swagger: '2.0'
basePath: /
info:
    title: 'My Dummy API'
    version: 0.0.0
    description: 'This is a test API.'
paths: {}
definitions: {}

I've added --no-schema to the validator just to make it pass, should default these values to an empty object in another PR.

@dkarlovi
Copy link
Contributor Author

dkarlovi commented Mar 3, 2018

@dunglas Don't forget to merge this since you merged the docs describing it already. :)

@dunglas dunglas merged commit 8be05ae into api-platform:master Mar 3, 2018
@dunglas
Copy link
Member

dunglas commented Mar 3, 2018

Thanks @dkarlovi

@dkarlovi dkarlovi deleted the swagger-command-yaml branch March 3, 2018 21: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.

[Swagger] add --yaml to SwaggerCommand
4 participants