Nested list in CSV as jekyll datafile - csv

I have a nested list, it looks like this in YAML and when used as YAML datafile it works without any problem:
---
title: "Vlčí hory"
thumbnail: "/img/vlci-hory/thumb.jpg"
products:
- title: "Rys"
category: "sešit"
dimension: "A5"
binding: "V1"
lineature: "tečky"
paper-cover: "250g recykl"
paper-inside: "80g recykl"
image1: "/img/vlci-hory/thumb.jpg"
- title: "Sova"
category: "sešit"
dimension: "A5"
binding: "V1"
lineature: "čisté listy"
paper-cover: "250g recykl"
paper-inside: "80g recykl"
image1: "/img/vlci-hory/thumb.jpg"
- title: "Zubr"
category: "sešit"
dimension: "A5"
binding: "V1"
lineature: "linky"
paper-cover: "250g recykl"
paper-inside: "80g recykl"
image1: "/img/vlci-hory/thumb.jpg"
However, I would like to have it in CSV (since Jekyll can read CSV) so my girlfriend can edit it in spreadsheet, thus make it more friendly to her.
I'm looking for spreadsheet template which can generate CSV file with appropriate interpretation of nested lists for jekyll use.
Here’s an editable spreadsheet with some of my tests.

Related

Parsing many to many model

I have a book database looking like this (simplified):
[book]
- bookId
- title
[author]
- authorId
- name
[book_has_author]
- bookId
- authorId
So basically a book can have multiple authors and an author can have multiples books.
I created an express API that retrieve me a list of books with his authors with an inner join. Here is what it returns for one book having 2 authors:
[
{
bookId: 1,
title: "how to code",
authorId: 1,
name: "martin"
},
{
bookId: 1,
title: "how to code",
authorId: 2,
name: "Tim"
}
]
But my Angular models looks like this:
interface Author {
authorId: number,
name: string,
books: Book[]
}
interface Book {
bookId: number,
title: string,
authors: Author[]
}
I know it's a bad way to represent my database but I don't know how I can model it.
The main issue here is that interfaces have circular referencies to each other, although I imagine you already figured that out.
This is generally a problem and although it's technically correct to think about the data in those terms it's not a good approach to model your data.
The first solution would be to make a choice between having an author have-books or a book have-authors, thus removing one of the dependencies out of the circular reference. You could also create BookChild and AuthorChild interfaces while keeping the Book and Author ones, but that will end up adding unnecessary complexities if the use case isn't really worth it.
After making your choice, you would probably need to add some type safety in your query results. To do that you can create a BookAuthorResponse interface and then transform it to a Book through map and reduce operations or the imperative equivalent (for-loop).
interface Author {
authorId: number,
name: string
}
interface Book {
bookId: number,
title: string,
authors: Author[]
}
interface BookAuthorResponse {
bookId: number
title: string
authorId: number
name: string
}
const bookAuthorResponseArray: BookAuthorResponse[] = [
{
bookId: 1,
title: "how to code",
authorId: 1,
name: "martin"
},
{
bookId: 1,
title: "how to code",
authorId: 2,
name: "Tim"
}
]
const books: Book = bookAuthorResponseArray.map(ba => ({
bookId: ba.bookId,
title: ba.title,
authors: [{
authorId: ba.authorId,
name: ba.name
}]
}))
.reduce((ba, acc) => ({
bookId: ba.bookId,
title: ba.title,
authors: [...acc.authors, ba.authors[0]]
}))

JSON API property names and Swagger documentation for proper response modeling

I'm seeking the best way for documenting my rest API response according to JSON API and also how to describe it in Swagger YAML documentation.
My API receives a word and a list of URLs and returns how many times the given word appears in each website provided. My first take for the successful response was:
{
"data": {
"foo": {
"http://www.foobar.com": 12,
"http://www.bar.com": 0
}
}
}
Using the word and the URLs as property names.
I'd like to know if it is a good practice according to JSON API and if yes, how to document it in Swagger YAML:
swagger: '2.0'
info:
description: How many times a given word appears in each site provided? This API answer it
version: 1.0.0
title: WordApp
contact:
email: foo#bar.com
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
paths:
/:
get:
summary: returns how many times a given word appears in each provided URL
description: |
By passing in the appropriate options, you can search for
the number of occurrences of a given word in each URL provided
produces:
- application/json
parameters:
- in: query
name: word
description: pass a word for looking up its occurrences in each site
required: true
type: string
- in: query
name: url
description: a list of valid URLs
type: string
required: true
responses:
200:
description: search results matching criteria
schema:
type: array
items:
$ref: '#/definitions/Data'
500:
description: Internal Server Error
definitions:
Data:
type: object
required:
- word
- url
- value
properties:
word:
type: string
example: Brazil
url:
type: string
example: 'https://www.nytimes.com/'
value:
type: integer
example: 12
If it is not the best practice, what would be a better way of modeling my response?

Swagger / JSON — Optional fields being treated as required

I'm having some difficulty with Swagger 2.0 insiting that fields are required when they are not in fact defined to be required.
Here's a snipped version of my Swagger YML file.
definitions:
category:
type: object
required:
- name
- code
properties:
name:
type: string
description: Category name
code:
type: string
description: Category code
_links:
$ref: '#/definitions/categoryLinks'
children:
type: array
items:
$ref: '#/definitions/category'
categoryLinks:
required:
- self
- parent
- children
properties:
self:
description: Canonical link to this category
$ref: '#/definitions/genericLink'
parent:
description: Link to the parent category
$ref: '#/definitions/genericLink'
children:
description: Link to the child categories
$ref: '#/definitions/genericLink'
genericLink:
properties:
href:
type: string
description: The absolute URL being linked to.
paths:
'/categories/{category_code}':
get:
summary: Get a specific category
description: Returns information about a specific category.
parameters:
- name: category_code
description: Code of category to get
type: string
in: path
required: true
responses:
200:
description: Information about requested category.
schema:
$ref: '#/definitions/category'
The response from get '/categories/awesome-cat' looks like:
{
"name" => "My awesome Category",
"code" => "awesome-cat",
"_links" => {
"self" => {
"href" => "https://api.test.testing/categories/awesome-cat.json"
},
"parent"=> {},
"children" => {}
}
}
Which is as expected, and which conforms to my definiton of a category above.
I'm using the swagger rspec matcher called conform_to_the_documented_model_for provided by the Apivore project to validate the output from all my API endpoints:
matcher :conform_to_the_documented_model_for do |swagger, fragment|
match do |body|
body = JSON.parse(body)
#errors = JSON::Validator.fully_validate(swagger, body, fragment: fragment)
#errors.empty?
end
failure_message do |body|
#errors.map { |e| e.sub("'#", "'#{path}#").gsub(/^The property|in schema.*$/,'') }.join("\n")
end
end
Alas my test is failing.
3) the V1 API path /categories/{category_code} method get response 200 responds with the specified models
Failure/Error: expect(response.body).to conform_to_the_documented_model_for(swagger, fragment)
'#/_links/parent' did not contain a required property of 'href'
'#/_links/children' did not contain a required property of 'href'
'#' did not contain a required property of 'children'
For some reason the JSON validator is not regarding the href property of the link as optional, nor is it regarding rhe children property of category as optional.
It was my understanding that properties not listed under the required section are optional. Why is the JSON::Validator.fully_validate regarding them as non-optional?
Dave, just answering here too for completeness. The latest version of the Apivore gem, 0.0.2, no longer uses the :strict mode of the JSON Validator gem json-schema, which makes the assumption that all fields are required. This is a recent change I made after we sorted out the misunderstandings around additionalProperties. I am now of the opinion that the :strict mode of the validator isn't very helpful. The default JSON schema validation is correct, there is no reason to be any 'stricter'.
Making sure you have the latest version of the Apivore gem (0.0.2, or greater) should solve your problem.

adding json element in json file

I have a json file in my android local device, im able to read and edit the json file and store json data in it.
But the problem is arising when i want to insert new element in the json file. Im able to change the value of existing variables.
the json file data is:
var data = {items:
{id: "1", name: "Snatch", type: "crime"}
};
i want to add one more element to it so that json file will look like
var data = {items: [
{id: "1", name: "Snatch", type: "crime"},
{id: "7", name: "Douglas Adams", type: "comedy"}
};
i tried with
data.items.push{id: "7", name: "Douglas Adams", type: "comedy"}
but its not working.
im creating android app using phonegap framework with telerik IDE.
Try
data.items.push(
{id: "7", name: "Douglas Adams", type: "comedy"}
);
You are missing ()
Your first file example is missing []
Check out this links to know more about json addition and removal
Link 1 , Link 2

Jekyll ignoring permalink for title

In my _config.yml, I specify my permalink format as permalink: /:title.
In my post, I have the following front matter and content in a file _posts/2011/2011-10-06-articles-october-11-2011.md
---
layout: post
title: Ecommerce Season – Why Site Speed Matters More Than You Think
categories: [articles]
tags: []
status: publish
type: post
published: true
meta: {}
---
[Ecommerce Season – Why Site Speed Matters More Than You Think](http://blog.yottaa.com/2011/09/ecommerce-season-%E2%80%93-why-site-speed-matters-more-than-you-think-in-2011)
However, this generates the following URL:
http://www.markrichman.com/articles-october-6-2011/
and not what I was expecting, which would be:
http://www.markrichman.com/ecommerce-season-why-site-speed-matters-more-than-you-think/
What if you rename your file to
2011-10-06-ecommerce-season-why-site-speed-matters-more-than-you-think.md
Quote from Permalinks
title: Title from the Post’s filename