jomei / notionapi

A Notion API SDK, written in Golang

Home Page:https://pkg.go.dev/github.com/jomei/notionapi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proposal: Define a basic block type with the common fields

kertox662 opened this issue · comments

The Blocks returned by the API all have some common fields like the type, ID, etc. A basic block type can be defined which has these fields and then embedded in the other blocks. This would reduce the duplication of these fields in the different block types.

For example:

type basicBlock struct {
	Object         ObjectType `json:"object"`
	ID             BlockID    `json:"id,omitempty"`
	Type           BlockType  `json:"type"`
	CreatedTime    *time.Time `json:"created_time,omitempty"`
	LastEditedTime *time.Time `json:"last_edited_time,omitempty"`
	HasChildren    bool       `json:"has_children,omitempty"`
        Archived       bool       `json:"archived,omitempty"`
}

...
type ParagraphBlock struct {
         basicBlock
         Paragraph      Paragraph  `json:"paragraph"`
}

The idea being similar to https://play.golang.org/p/BTwPIwzuFJ8
Not sure how compatible this is with #10

commented

The idea being similar to https://play.golang.org/p/BTwPIwzuFJ8

Let me post another example to also show the unmarshaling:
https://play.golang.org/p/6F1b-UBebWn

Not sure how compatible this is with #10

I wouldn't worry much about that issue as it has been open for a very long time. It is known that Notion is planning on making public an OpenAPI specification, and the implementation described is quite complicated for just a small api.

resolved by #47