Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExtractSchema() does not consider option type #1252

Closed
psmolinsky opened this issue Dec 13, 2021 · 3 comments
Closed

ExtractSchema() does not consider option type #1252

psmolinsky opened this issue Dec 13, 2021 · 3 comments
Assignees
Labels
bug Something isn't working Michelson 🥸 Related to Michelson language and Taquito's handling of same
Milestone

Comments

@psmolinsky
Copy link

Description
Schema.ExtractSchema() method does not consider the option type. This make it indistinguishable if the option is there or not.

Steps To Reproduce

  1. Create a Schema with Michelson containing the option type and call the method.
const schema = new Schema({ prim: 'option', args: [{ prim: 'nat' }] });
const extracted = schema.ExtractSchema();
  1. It returns:
"nat"
  1. Do the same with similar schema without option and call the method
const schema = new Schema({ prim: 'nat' });
const extracted = schema.ExtractSchema();
  1. It returns the same result:
"nat"

Expected behavior

The option type should be expressed in the extracted schema. For example in the step 2 the result could be "option nat" or an object { option: "nat" }. The step 4 could stay as it is.

@psmolinsky psmolinsky added the bug Something isn't working label Dec 13, 2021
@Innkst Innkst added the Michelson 🥸 Related to Michelson language and Taquito's handling of same label Dec 16, 2021
@Innkst Innkst added this to the v11.2 milestone Dec 16, 2021
@roxaneletourneau roxaneletourneau self-assigned this Jan 14, 2022
roxaneletourneau added a commit that referenced this issue Jan 14, 2022
ExtractSchema is missing some important details (i.e. there is no distinction between "or" and
"pair" types, "option" type is not marked as optional). A new method called "generateSchema" has
been implemented and is intended to replace the "ExtractSchema" method. "generateSchema" provides a
more accurate and uniform schema representation.

BREAKING CHANGE: The schema representation is different between ExtractSchema and generateSchema
method. ExtractSchema will be marked as deprecated and the migration to generateSchema will incur
breaking change.

re #1252, re #1303, re #1304
@roxaneletourneau
Copy link
Collaborator

roxaneletourneau commented Jan 15, 2022

@psmolinsky
The ExtractSchema method is missing some important detail for some types and is not uniform across all tokens. (as mentioned in tickets #1303 and #1304 also)
If adding a property option for the option type, I feel that at some point it might become confusing to distinguish between the contract annotations and properties added by Taquito to the schema.
As the change mentioned in the current ticket would result in a breaking change, I thought it was a good occasion to refactor the ExtractSchema method to make it more uniform and easy to discover.
I implemented a new method named generateSchema. The intention is to deprecate ExtractSchema in favor of this new one.
For each token, generateSchema returns an object of type TokenSchema. TokenSchema has a property __michelsonType which is a string and a property schema that contains information on the schema of the subtoken when applicable.

I would like to know if the proposed solution seems convenient for you.

Here is a link to preview builds: #1316 (comment)
Some schema examples can be found in the unit tests here: https://github.com/ecadlabs/taquito/pull/1317/files

Examples:

The michelson type: { prim: 'option', args: [{ prim: 'int' }], annots: [] } will be represented as follow by the generateSchema method:

{
        __michelsonType: 'option',
        schema: {
          __michelsonType: 'int',
          schema: 'int'
        }
}

The michelson type: { prim: 'pair', args: [{ prim: 'int', annots: ['test'] }, { prim: 'string', annots: ['test2'] }], } will be represented as follow by the generateSchema method:

// Nested pair will be brought to the same level (as it is the case with the ExtractSchema)
{
        __michelsonType: 'pair',
        schema: {
          test: {
            __michelsonType: 'int',
            schema: 'int'
          },
          test2: {
            __michelsonType: 'string',
            schema: 'string'
          }
        }
}

The michelson type: { prim: 'map', args: [{ prim: 'string' }, { prim: 'int' }], annots: [] } will be represented as follow by the generateSchema method:

// schema of a map has `key` and `value` properties
{
        __michelsonType: 'map',
        schema: {
          key: {
            __michelsonType: 'string',
            schema: 'string'
          },
          value: {
            __michelsonType: 'int',
            schema: 'int'
          }
        }
}

@roxaneletourneau
Copy link
Collaborator

Improved the Tokenschema type and replaced the link for the preview version in the comment above.

@psmolinsky
Copy link
Author

Great move, thanks. It makes the schema object much less ambiguous.

roxaneletourneau added a commit that referenced this issue Jan 21, 2022
ExtractSchema is missing some important details (i.e. there is no distinction between "or" and
"pair" types, "option" type is not marked as optional). A new method called "generateSchema" has
been implemented and is intended to replace the "ExtractSchema" method. "generateSchema" provides a
more accurate and uniform schema representation.

BREAKING CHANGE: The schema representation is different between ExtractSchema and generateSchema
method. ExtractSchema will be marked as deprecated and the migration to generateSchema will incur
breaking change.

re #1252, re #1303, re #1304
@ac10n ac10n moved this to Done in Taquito Dev Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Michelson 🥸 Related to Michelson language and Taquito's handling of same
Projects
Status: Done
Development

No branches or pull requests

3 participants