Giter VIP home page Giter VIP logo

schematyper's People

Contributors

idubinskiy avatar jmkho-spirent avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

schematyper's Issues

Duplicated identifier names if the schema contains special character

input example:

{
  "$schema": "http://json-schema.org/draft-04/schema",
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "name$": {
      "type": "string"
    },
    "name-": {
      "type": "string"
    },
    "schema": {
      "type": "string"
    },
    "$schema": {
      "type": "string"
    }
  }
}

the output result:

type Test struct {
	Name   string `json:"name,omitempty"`
	Name   string `json:"name$,omitempty"`
	Name   string `json:"name-,omitempty"`
	Schema string `json:"$schema,omitempty"`
	Schema string `json:"schema,omitempty"`
}

panic can't resolve: (#/items/properties/collection-editor/item...

panics with the following message
2020/03/21 13:07:39 Can't resolve: (#/items/properties/collection-editor/items #/items/properties/reviewed-author/items #/items/properties/original-author/items #/items/properties/director/items #/items/properties/interviewer/items # #/items/properties/container-author/items #/items/properties/editor/items #/items/properties/composer/items #/items)

when running against this file https://raw.githubusercontent.com/citation-style-language/schema/master/csl-data.json

RFE: Don't create new types with non-$ref definitions in allOf

Right now using allOf results in embedding any $refs and creating new structs for those that are defined in a new block. For those not using $ref would it be possible (and correct?) to generate those as members of the struct that currently embeds the generated one? I.e. instead of generating:

type Bar struct { ... }

type FooEmbedded1 struct {
    A int
    B string
}

type Foo struct {
    Bar
    FooEmbedded1
}

for an allOf block including $ref: "path/to/barand an object block withAandB` generate:

type Bar struct { ... }

type Foo struct {
    Bar
    A int
    B string
}

Cannot generate go code when nested schema

I cannot convert the schema like follows to go code.
I'm using prmd and combine some schemas. It generates nested schema like this.
So I'd like you to support the nested schema.

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {
    "app": {
      "definitions": {
        "domains": {
          "items": {
            "$ref": "#/definitions/domain"
          },
          "type": "array"
        },
        "name": {
          "pattern": "^[a-z][a-z0-9-]{2,30}$",
          "type": "string"
        }
      },
      "properties": {
        "domains": {
          "$ref": "#/definitions/app/definitions/domains"
        },
        "name": {
          "$ref": "#/definitions/app/definitions/name"
        }
      },
      "required": [
        "name"
      ],
      "type": "object"
    },
    "domain": {
      "definitions": {
        "name": {
          "format": "hostname",
          "type": "string"
        }
      },
      "properties": {
        "name": {
          "$ref": "#/definitions/domain/definitions/name"
        }
      },
      "required": [
        "name"
      ],
      "type": "object"
    }
  },
  "properties": {
    "app": {
      "$ref": "#/definitions/app"
    },
    "domain": {
      "$ref": "#/definitions/domain"
    }
  },
  "type": "object"
}

data type is missing when "type": [ "string", "number", "boolean" ]

input
{ "description": "JSON schema for CSL input data", "$schema": "http://json-schema.org/draft-03/schema#", "id": "https://github.com/citation-style-language/schema/raw/master/csl-data.json", "type": "object", "properties": { "family": { "type": "string" }, "given": { "type": "string" }, "dropping-particle": { "type": "string" }, "non-dropping-particle": { "type": "string" }, "suffix": { "type": "string" }, "comma-suffix": { "type": [ "string", "number", "boolean" ] }, "static-ordering": { "type": [ "string", "number", "boolean" ] }, "literal": { "type": "string" }, "parse-names": { "type": [ "string", "number", "boolean" ] } }, "additionalProperties": false }
output
`package main

// generated by "schematyper csl-data.json" -- DO NOT EDIT

// JSON schema for CSL input data
type cslData struct {
CommaSuffix json:"comma-suffix,omitempty"
DroppingParticle string json:"dropping-particle,omitempty"
Family string json:"family,omitempty"
Given string json:"given,omitempty"
Literal string json:"literal,omitempty"
NonDroppingParticle string json:"non-dropping-particle,omitempty"
ParseNames json:"parse-names,omitempty"
StaticOrdering json:"static-ordering,omitempty"
Suffix string json:"suffix,omitempty"
}
`

Duplicate type generation

Two objects with the same name will generate two types with the same name, which causes a compiler error.

RFE: Support custom struct tags

It would be good to support allowing specifying struct tags in some way. JSON schema doesn't have a concept which maps nicely to it, but maybe something like additionalProperties or comments could be hijacked for use. For Ignition I'm trying to find a way to note additional metadata about each key (specifically which one acts as a unique identifier for the struct) and struct tags would be ideal.

`allOf` results in a `type <name> interface{}`

I use an allOf in my schema to avoid a little duplication,

        "file": {
          "allOf": [
            {
              "$ref": "#/definitions/storage/definitions/node"
            },
            {
              "properties": {
                "contents": {
                  "$ref": "#/definitions/storage/definitions/file-contents"
                }
              }
            }
          ]
        },

This results in the File type in the generated code being this:

type File interface{}

If this is challenging to fix I could always duplicate the node properties in my schema.

Link to my schema again: http://lpaste.net/6280590999756472320

Can't resolve: (#)

derek@proton 2 ~/go/src/github.com/coreos/ignition/schema> schematyper ignition.json      
2017/02/03 11:25:45 Can't resolve: (#)

I get this error when I try to give schematyper my schema. Any clue how to fix this?

This is ignition.json, if it helps: http://lpaste.net/5721431062916104192

Schema generated is not deterministic.

Using the Ignition schema and running:

schematyper --package=types schema/ignition.json -o config/types/schema.go --root-type=Config

from the root of the Ignition source will sometimes generate schemas with Passwd.PasswdUser.Groups as of type []Group (where Group is defined as type Group string) and sometimes as type []PasswdUserGroup (where PasswdUserGroup is also defined as type PasswdUserGroup string)

These names should not change between runs.

To Reproduce:

  1. Clone Ignition
  2. Ensure schematyper is in your path
  3. run ./generate && git diff several times and note the schema it generates differs between runs

I suspect it has something to do with the fact that there are multiple things named "group".

Workaround:
Run schematyper until the ouptut matches what you expect.

Generate New() function for schema with defaults

based on the following JSONSchema I would like to propose the generation of a New() function.

{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://example.com/root.json",
  "type": "object",
  "title": "The Root Schema",
  "required": [
    "type",
    "data"
  ],
  "properties": {
    "type": {
      "$id": "#/properties/type",
      "type": "string",
      "title": "Type",
      "default": "notify_event",
      "examples": [
        "notify_event"
      ],
      "pattern": "^(.*)$"
    },
    "data": {
      "$id": "#/properties/data",
      "type": "object",
      "title": "Data",
      "required": [
        "resourceId",
        "type",
        "title",
        "content"
      ],
      "properties": {
        "resourceId": {
          "$id": "#/properties/data/properties/resourceId",
          "type": "string",
          "title": "Resourceid",
          "default": "",
          "examples": [
            "1a2s3d4f"
          ],
          "pattern": "^(.*)$"
        },
        "type": {
          "$id": "#/properties/data/properties/type",
          "type": "string",
          "title": "Type",
          "default": "rule",
          "examples": [
            "rule"
          ],
          "pattern": "^(.*)$"
        },
        "title": {
          "$id": "#/properties/data/properties/title",
          "type": "string",
          "title": "Title",
          "default": "",
          "examples": [
            "rule violation"
          ],
          "pattern": "^(.*)$"
        },
        "content": {
          "$id": "#/properties/data/properties/content",
          "type": "string",
          "title": "Content",
          "default": "",
          "examples": [
            "some explaination about rule violation"
          ],
          "pattern": "^(.*)$"
        }
      }
    }
  }
}

Proposed Output:

package main

// generated by "schematyper schema.json" -- DO NOT EDIT

const (
	defaultType     string = "notify_event"
	defaultDataType string = "rule"
)

type schema struct {
	Data theData `json:"data"`
	Type string  `json:"type"`
}

type data struct {
	Content    string `json:"content"`
	Resourceid string `json:"resourceId"`
	Title      string `json:"title"`
	Type       string `json:"type"`
}

func NewSchema() *schema {
	return &schema{
		Data: data{
			Content:    "",
			Resourceid: "",
			Title:      "",
			Type:       defaultDataType,
		},
		Type: defaultType,
	}
}

func NewData() *data {
	return &data{
		Content:    "",
		Resourceid: "",
		Title:      "",
		Type:       defaultDataType,
	}
}

Ambiguous element detected where none exists.

Issue:

I am parsing a schema document based on JSON Schema version 7 and have run into the following error.

[yamada@localhost device-sender]$ schematyper data.json 
2018/12/21 17:08:21 Can't disabiguate: (#/properties/d/items #)

Expectation:

I have verified the schema format should be correct, as it was largely generated in this format according to https://www.jsonschema.net, the only thing taht was added are title names, and pattern matching.

I would expect that the standard array type below which adheres to JSON schema v7 should be recognized with no ambiguities.

Reference File:

{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://example.com/system/interface/data.json",
  "type": "object",
  "title": "Stamp Message Schema",
  "required": [
    "t",
    "d"
  ],
  "properties": {
    "t": {
      "$id": "#/properties/t",
      "type": "string",
      "title": "msgType",
      "default": "",
      "examples": [
        "B"
      ],
      "pattern": "^([B])$"
    },
    "d": {
      "$id": "#/properties/d",
      "type": "array",
      "title": "dataArray",
      "items": {
        "$id": "#/properties/d/items",
        "type": "object",
        "title": "data",
        "required": [
          "64",
          "dt",
          "id"
        ],
        "properties": {
          "64": {
            "$id": "#/properties/d/items/properties/64",
            "type": "string",
            "title": "base64",
            "default": "",
            "examples": [
              "aGVsbG8gd29ybGQ="
            ],
            "pattern": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"
          },
          "dt": {
            "$id": "#/properties/d/items/properties/dt",
            "type": "string",
            "title": "dataType",
            "default": "",
            "examples": [
              "C"
            ],
            "pattern": "^(.*)$"
          },
          "id": {
            "$id": "#/properties/d/items/properties/id",
            "type": "integer",
            "title": "ID",
            "default": "",
            "examples": [
              1
            ]
          }
        }
      }
    }
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.