Skip to content

Duplicates and Broken code is generated  #1

@franzen

Description

@franzen

Test case

Use the following code to generate the data structures

package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"

	jsonschema "github.com/tfkhsr/jsonschema"
	golang "github.com/tfkhsr/jsonschema/golang"
)

func main() {
	url := "https://raw.githubusercontent.com/microsoft/botframework-sdk/master/schemas/protocol/botframework.json"
	fmt.Println("fetch", url)

	response, err := http.Get(url)
	if err != nil {
		log.Fatal(err)
	}
	defer response.Body.Close()
	schema, _ := ioutil.ReadAll(response.Body)

	idx, err := jsonschema.Parse(schema)
	if err != nil {
		panic(err)
	}

	src, err := golang.PackageSrc(idx, "bot")
	if err != nil {
		panic(err)
	}

	output := "data.go"
	fmt.Println("writing", output)
	err = ioutil.WriteFile(output, src, 0644)
	if err != nil {
		panic(err)
	}
	fmt.Println("done")
}

The generated data.go file is broken

Duplicates

Contains duplicates like:

type Buttons []CardAction
type Buttons []CardAction
type Buttons []CardAction
type Buttons []CardAction
type Buttons []CardAction
type Buttons []CardAction
type Buttons []CardAction
type Buttons []CardAction
type Buttons []CardAction
type Buttons []CardAction

Wrong Property used

The generated code mixes the names of the created properties, eg. ConversationAccount and Conversation, see the following code generated:

type Activity struct {
...
	Conversation     *ConversationAccount   `json:"ConversationAccount,omitempty"`
...
}

and

func (t *Activity) Validate() error {
...
	err = t.ConversationAccount.Validate()
...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions