Git Product home page Git Product logo

go-codegen's People

Contributors

bdeneux avatar kakucodes avatar mahiro72 avatar srdtrk 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

Watchers

 avatar

go-codegen's Issues

[EPIC] Add support for other chains when generating the test suite

Description

Currently, the testsuite only comes with wasmd v0.50.0. I'd like the interactive menu to allow users to select the chain's they'd like to use. I'll list the chains that should be supported:

  • #87
  • Add an option to generate osmosis in interchaintest
  • Add an option to generate ibc-go simd v8.3 in interchaintest
  • Add an option to generate gaia (Cosmos Hub) in interchaintest

And there are some other additional tasks that need to be completed:

  • Add an interactive prompt to enable chain selection by the user.

Add `interchaintest add contract` command

Currently, in the feature branch, we can scaffold a testsuite using interchaintest scaffold command. Also add support for adding contracts with go-codegen interchaintest add contract [json_schema]

Issue generating types for ics721

Similar to the other issue looks like it can parse array
https://github.com/public-awesome/cw-ics721/blob/main/packages/ics721/schema/ics721.json

9:22AM INF Generating code to cosmwasm/types/ics721/types.go
panic: unsupported type array for definition CallbackMsg_RedeemOutgoingChannelEntries
  {
            "description": "Redeem all entries in outgoing channel.",
            "type": "object",
            "required": ["redeem_outgoing_channel_entries"],
            "properties": {
              "redeem_outgoing_channel_entries": {
                "type": "array",
                "items": {
                  "type": "array",
                  "items": [
                    {
                      "$ref": "#/definitions/ClassId"
                    },
                    {
                      "$ref": "#/definitions/TokenId"
                    }
                  ],
                  "maxItems": 2,
                  "minItems": 2
                }
              }
            },
            "additionalProperties": false
          },

Would it be possible to pass a prefix when generating types? Ideally I'd like to have a single package and do something like

 go-codegen generate  cosmwasm/schemas/ics721.json --prefix ICS721 --output cosmwasm/types/ics721.go --package-name  types

 go-codegen generate  cosmwasm/schemas/cw721-base.json --prefix CW271 --output cosmwasm/types/cw721.go --package-name  types

Failed generation on enum struct with same property name

Following a comment on my last PR (#98), I've encountered an issue when generating schema types from our smart contract JSON schema.

To illustrate the problem, consider the following Rust code snippet:

/// # Value
#[cw_serde]
#[serde(tag = "type")]
pub enum Value {
    /// # String
    String { value: String },
    /// # Number
    Number { value: i64 },
}
**Whole JSON Schema for example**

{
  "contract_name": "nested-enum-same-name",
  "contract_version": "0.0.1",
  "idl_version": "1.0.0",
  "instantiate": {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "InstantiateMsg",
    "description": "Instantiate message",
    "type": "object",
    "additionalProperties": false
  },
  "execute": {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "ExecuteMsg",
    "description": "Execute messages",
    "oneOf": [
      {
        "title": "Foo",
        "type": "object",
        "required": [
          "foo"
        ],
        "properties": {
          "foo": {
            "type": "object",
            "required": [
              "value"
            ],
            "properties": {
              "value": {
                "$ref": "#/definitions/Value"
              }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      }
    ],
    "definitions": {
      "Value": {
        "title": "Value",
        "oneOf": [
          {
            "title": "String",
            "type": "object",
            "required": [
              "type",
              "value"
            ],
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "string"
                ]
              },
              "value": {
                "type": "string"
              }
            },
            "additionalProperties": false
          },
          {
            "title": "Number",
            "type": "object",
            "required": [
              "type",
              "value"
            ],
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "number"
                ]
              },
              "value": {
                "type": "integer",
                "format": "int64"
              }
            },
            "additionalProperties": false
          }
        ]
      }
    }
  },
  "query": {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "QueryMsg",
    "description": "Query messages",
    "oneOf": [
      {
        "title": "Bar",
        "type": "object",
        "required": [
          "bar"
        ],
        "properties": {
          "bar": {
            "type": "object",
            "required": [
              "foo"
            ],
            "properties": {
              "foo": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      }
    ]
  },
  "migrate": null,
  "sudo": null,
  "responses": {
    "bar": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "title": "BarResponse",
      "type": "object",
      "required": [
        "foo"
      ],
      "properties": {
        "foo": {
          "description": "The foo value",
          "type": "string"
        }
      },
      "additionalProperties": false
    }
  },
  "description": "# nested-enum-same-same",
  "title": "nested-enum-same-same"
}

Internally tagged enum

In this code, we're using the serde tag #[serde(tag="type")] to transform the representation of our enum into an internally tagged format, as described in the serde documentation. This results in a generated JSON schema with an enum Type that can take string or number as a value.

Here's a snippet of the generated JSON schema:

<...>
       {
            "title": "String",
           <...>
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "string"
                ]
              },
              "value": {
                "type": "string"
              }
            },
          },
          {
            "title": "Number",
          <...>
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "number"
                ]
              },
              "value": {
                "type": "integer",
                "format": "int64"
              }
            },
          }

I've created a branch on a fork that includes a fix for merging multiple enums with the same name in the definition registry. This situation arises here because the possible values of the Type enum are defined in each definition of the Value enum. You can find the fix in this commit: d210cad.

Struct enum with same attribute name

Another issue arises because each enumeration struct variant contains a value property with a different type. When generating code with go-codegen, this leads to the following error:

duplicate definition `Value_Value` with differing implementations: different types [string] != [integer]

The issue arises due to a conflict in the type registration of Value_Value in the definition registry. Initially, Value_Value was registered as a string type. However, an attempt to register it again as an integer type has led to this problem.

For a more comprehensive understanding of the issue, you can refer to the original JSON schema that triggered this problem. It is available here. The corresponding representation in the Rust contract can be found here.

Add a `--check` flag

I don't like github workflows that generate code and push, which go-codegen can be used to create. Instead, I like workflows that check validity.

Therefore, I want to add a --check flag where go-codegen checks whether or not the output file provided (with -o flag) matches the output of the program.

Issue generating types for cw-nfts

When I try generating types for the latest main branch of cw-nfts I get this error panic: response get_withdraw_address is not supported, please create an issue in https://github.com/srdtrk/go-codegen

      {
        "type": "object",
        "required": ["get_withdraw_address"],
        "properties": {
          "get_withdraw_address": {
            "type": "object",
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      }

Improve package name inferrence

Currently, the package name is the contract name with all non alphabetic characters removed. Improve this by:

  • Allowing numbers
  • Converting all capital letters to lower case.

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.