Skip to content
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

Conversion not working right #71

Open
dingo-d opened this issue Feb 21, 2018 · 0 comments
Open

Conversion not working right #71

dingo-d opened this issue Feb 21, 2018 · 0 comments

Comments

@dingo-d
Copy link

dingo-d commented Feb 21, 2018

I am trying to convert the yaml file to json, my test file is the one from here, the pet store. The yaml file looks like this:

swagger: "2.0"
info:
  description: "This is a sample server Petstore server.  You can find out more about     Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).      For this sample, you can use the api key `special-key` to test the authorization     filters."
  version: "1.0.0"
  title: "Swagger Petstore"
  termsOfService: "http://swagger.io/terms/"
  contact:
    email: "[email protected]"
  license:
    name: "Apache 2.0"
    url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "petstore.swagger.io"
basePath: "/v2"
tags:
- name: "pet"
  description: "Everything about your Pets"
  externalDocs:
    description: "Find out more"
    url: "http://swagger.io"
- name: "store"
  description: "Access to Petstore orders"
- name: "user"
  description: "Operations about user"
  externalDocs:
    description: "Find out more about our store"
    url: "http://swagger.io"
...

The saved json file (from their site) looks like

{
  "swagger": "2.0",
  "info": {
    "description": "This is a sample server Petstore server.  You can find out more about     Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).      For this sample, you can use the api key `special-key` to test the authorization     filters.",
    "version": "1.0.0",
    "title": "Swagger Petstore",
    "termsOfService": "http://swagger.io/terms/",
    "contact": {
      "email": "[email protected]"
    },
    "license": {
      "name": "Apache 2.0",
      "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
    }
  },
  "host": "petstore.swagger.io",
  "basePath": "/v2",
  "tags": [
    {
      "name": "pet",
      "description": "Everything about your Pets",
      "externalDocs": {
        "description": "Find out more",
        "url": "http://swagger.io"
      }
    },
    {
      "name": "store",
      "description": "Access to Petstore orders"
    },
    {
      "name": "user",
      "description": "Operations about user",
      "externalDocs": {
        "description": "Find out more about our store",
        "url": "http://swagger.io"
      }
    }
  ],
...

But when I try to parse this, the array I get looks like

(
    [swagger] => 2.0
    [info] => Array
        (
            [description] => This is a sample server Petstore server.  You can find out more about     Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).      For this sample, you can use the api key `special-key` to test the authorization     filters.
            [version] => 1.0.0
            [title] => Swagger Petstore
            [termsOfService] => http://swagger.io/terms/
            [contact] => Array
                (
                    [email] => [email protected]
                )

            [license] => Array
                (
                    [name] => Apache 2.0
                    [url] => http://www.apache.org/licenses/LICENSE-2.0.html
                )

        )

    [host] => petstore.swagger.io
    [basePath] => /v2
    [tags] => 
    [0] => Array
        (
            [name] => pet
            [description] => Everything about your Pets
            [externalDocs] => Array
                (
                    [description] => Find out more
                    [url] => http://swagger.io
                )

        )

    [1] => Array
        (
            [name] => store
            [description] => Access to Petstore orders
        )

    [2] => Array
        (
            [name] => user
            [description] => Operations about user
            [externalDocs] => Array
                (
                    [description] => Find out more about our store
                    [url] => http://swagger.io
                )

        )

    [schemes] => 
    [3] => http
    [paths] => Array
...

Which, when converted to json looks like:

{
      "swagger": "2.0",
      "info": {
        "description": "This is a sample server Petstore server.  You can find out more about     Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).      For this sample, you can use the api key `special-key` to test the authorization     filters.",
        "version": "1.0.0",
        "title": "Swagger Petstore",
        "termsOfService": "http://swagger.io/terms/",
        "contact": {
          "email": "[email protected]"
        },
        "license": {
          "name": "Apache 2.0",
          "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
        }
      },
      "host": "petstore.swagger.io",
      "basePath": "/v2",
      "tags": "",
      "0": {
        "name": "pet",
        "description": "Everything about your Pets",
        "externalDocs": {
          "description": "Find out more",
          "url": "http://swagger.io"
        }
      },
      "1": {
        "name": "store",
        "description": "Access to Petstore orders"
      },
      "2": {
        "name": "user",
        "description": "Operations about user",
        "externalDocs": {
          "description": "Find out more about our store",
          "url": "http://swagger.io"
        }
      },
      "schemes": "",
      "3": "http",
...

So obviously the parser fails when the yaml keys aren't indented

tags:
- name: "pet"

Any fix for this?

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

No branches or pull requests

1 participant