eduardoboucas / static-api-generator

🔧 Generate a static JSON API from a tree of directories and files
https://www.npmjs.com/package/static-api-generator
146 stars 9 forks source link

static-api-generator generates .json #1

Open schmanat opened 6 years ago

schmanat commented 6 years ago

First of all, thx for your greate tool. I'm playing arround with it and have a issue that i couldn't solve.

I read the article from CSS Tricks.

I create a source folder with the following structure:

source
    slogan1.yaml
    slogan2.yaml

the structure of slogan is only author: "Hugo" slogan: "Lorem ipsum ..."

I want to generate the following endpoint /slogans

The Code of my server.js:

    const API = require('static-api-generator')
    const slogansAPI = new API({
        blueprint: 'source/:slogan',
        outputPath: 'output'
    })

    slogansAPI.generate({
        endpoints: ['slogans'],
    })

After generating it with npm start I get 2 json files

Can you tell me what I'm doing wrong. The strange thing ist the content of slogans.json. It contains two result objects?

The content of .json seems right, but why is there no filename?

Content of slogans.json

    {
        "results": [
            {
                "results": [
                    {
                        "undefined_id": "10c8f19f2d98c3eb66ec911b5dc5abd0",
                        "author": "Hugo",
                        "title": "Lorem ipsum"
                    },
                    {
                        "undefined_id": "dfbdfa8f69d0b629153207a17e565fd9",
                        "author": "Hugo",
                        "slogan": "Lorem ipsum dolor"
                    }
                ]
            }
         ],
        "metadata": {
            "itemsPerPage": 10,
            "pages": 1
        }
    }

Content of .json

    {
        "results": [
            {
                "undefined_id": "10c8f19f2d98c3eb66ec911b5dc5abd0",
                "author": "Hugo",
                "title": "Lorem ipsum"
            },
            {
                "undefined_id": "dfbdfa8f69d0b629153207a17e565fd9",
                "author": "Hugo",
                "slogan": "Lorem ipsum dolor"
            }
        ],
            "metadata": {
            "itemsPerPage": 10,
            "pages": 1
        }
    }    
david-genger commented 6 years ago

I am having the same issue, can you please help me.

ClydeDz commented 5 years ago

I'm having the same issue. And if I add another level, the json output doesn't contain anything.

gavinmcfarland commented 4 years ago

I'm going to take a guess that static-api-generator always expects a collection and that collection has to be grouped by a folder.

As a temporary fix you could try using source/:slogans/:slogan and place all files in a sub folder source/slogans/.