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

Generate md file for zod schemas using modified version of zod2md #622

Open
wants to merge 5 commits into
base: epic-v0.6.x
Choose a base branch
from

Conversation

Muhammad-Altabba
Copy link

@Muhammad-Altabba Muhammad-Altabba commented Feb 20, 2025

Type of PR:

  • Bugfix
  • Feature
  • Documentation
  • Other

Required reviews:

  • 1
  • 2
  • 3

What this does:

High-level idea of the changes introduced in this PR. List relevant API
changes (if any), as well as related PRs and issues.

Issues fixed/closed:

  • Fixes #...

Why it's needed:

Explain how this PR fits in the greater context of the NuCypher Network. E.g.,
if this PR address a nucypher/productdev issue, let reviewers know!

Notes for reviewers:

What should reviewers focus on? Is there a particular commit/function/section
of your PR that requires more attention from reviewers?


The generated file would be something similar to:

Conditions Schemas

AnyCondition

Union of the following possible types:

UserAddress

Enum string, one of the following possible values:

  • ':userAddress'
  • ':userAddressExternalEIP4361'

BaseCondition

Object containing the following properties:

Property Type
conditionType (*) string

(*) Required.

HttpsURL

String which is a valid URL.

JsonPath

String.

PlainString

String.

CompoundCondition

Object containing the following properties:

Property Type Default
conditionType 'compound' 'compound'
operator (*) 'and' | 'or' | 'not'
operands (*) Array of at least 1 and at most 5 AnyCondition item

(*) Required.

ContextParam

String which matches the regular expression /^:[a-zA-Z_][a-zA-Z0-9_]*$/.

ParamOrContextParam

Union of the following possible types:

ContractCondition

Object containing the following properties:

Property Description Type Default
conditionType 'contract' 'contract'
chain (*) number (int, ≥0)
method (*) string
parameters (*) Array of ParamOrContextParam items
returnValueTest (*) Update to allow multiple return values after expanding supported methods ReturnValueTest
contractAddress (*) string
standardContractType 'ERC20' | 'ERC721'
functionAbi FunctionAbi

(*) Required.

FunctionAbi

Object containing the following properties:

Property Type
name (*) string
type (*) 'function'
inputs (*) Array of at least 0 FunctionAbiVariable item
outputs (*) Array of at least 1 FunctionAbiVariable items
stateMutability (*) 'view' | 'pure'

(*) Required.

FunctionAbiVariable

Object containing the following properties:

Property Type
name (*) string
type (*) 'bool' | 'string' | 'address' | 'address payable' | 'bytes1' | 'bytes2' | 'bytes3' | 'bytes4' | 'bytes5' | 'bytes6' | 'bytes7' | 'bytes8' | 'bytes9' | 'bytes10' | 'bytes11' | 'bytes12' | 'bytes13' | 'bytes14' | 'bytes15' | 'bytes16' | ...
internalType (*) 'bool' | 'string' | 'address' | 'address payable' | 'bytes1' | 'bytes2' | 'bytes3' | 'bytes4' | 'bytes5' | 'bytes6' | 'bytes7' | 'bytes8' | 'bytes9' | 'bytes10' | 'bytes11' | 'bytes12' | 'bytes13' | 'bytes14' | 'bytes15' | 'bytes16' | ...

(*) Required.

IfThenElseCondition

Object containing the following properties:

Property Type Default
conditionType 'if-then-else' 'if-then-else'
ifCondition (*) AnyCondition
thenCondition (*) AnyCondition
elseCondition (*) AnyCondition or boolean

(*) Required.

JsonApiCondition

Object containing the following properties:

Property Type Default
conditionType 'json-api' 'json-api'
endpoint (*) HttpsURL
parameters Object with dynamic keys of type string and values of type unknown (optional & nullable)
query JsonPath
authorizationToken ContextParam
returnValueTest (*) ReturnValueTest

(*) Required.

JsonRpcCondition

Object containing the following properties:

Property Type Default
conditionType 'json-rpc' 'json-rpc'
endpoint (*) HttpsURL
method (*) string
params Array<unknown> or Object with dynamic keys of type string and values of type unknown (optional & nullable)
query JsonPath
authorizationToken ContextParam
returnValueTest (*) ReturnValueTest

(*) Required.

ReturnValueTest

Object containing the following properties:

Property Type
index number (int, ≥0)
comparator (*) '==' | '>' | '<' | '>=' | '<=' | '!='
value (*) ParamOrContextParam

(*) Required.

RpcCondition

eth_getBalance schema specification

Object containing the following properties:

Property Description Type Default
conditionType 'rpc' 'rpc'
chain (*) number (int, ≥0)
method (*) Only 'eth_getBalance' method is supported 'eth_getBalance'
parameters (*) Tuple:
  1. string, UserAddress or ContextParam
  2. number (int, ≥0), string (regex: /^0x[a-fA-F0-9]{64}$/) or 'earliest' | 'finalized' | 'safe' | 'latest' | 'pending' or ContextParam
Description: Spec requires 2 parameters: an address and a block identifier

or Tuple:
  1. string, UserAddress or ContextParam
Description: Block identifier can be omitted, since web3py (which runs on TACo exec layer) defaults to 'latest'

returnValueTest (*) Update to allow multiple return values after expanding supported methods ReturnValueTest

(*) Required.

ConditionVariable

Object containing the following properties:

Property Type
varName (*) PlainString
condition (*) AnyCondition

(*) Required.

SequentialCondition

Object containing the following properties:

Property Type Default
conditionType 'sequential' 'sequential'
conditionVariables (*) Array of at least 2 and at most 5 ConditionVariable item

(*) Required.

TimeCondition

Object containing the following properties:

Property Description Type Default
conditionType 'time' 'time'
chain (*) number (int, ≥0)
method 'blocktime' 'blocktime'
returnValueTest (*) Update to allow multiple return values after expanding supported methods ReturnValueTest

(*) Required.

@Muhammad-Altabba
Copy link
Author

To check the generated file: zod-schemas.md

Or locally run:
Go inside the package taco (cd packages/taco) and then run pnpm run generate-zod-docs. Please, let me know if adding a script command at the mono-repo root is recommended.

@Muhammad-Altabba Muhammad-Altabba force-pushed the 125-automated-documentation-generation-for-taco-web-condition-schemas branch from 525d232 to 0c9b750 Compare February 24, 2025 19:45
@Muhammad-Altabba Muhammad-Altabba changed the title [DRAFT] Generate md file for zod schemas using modified version of zod2md Generate md file for zod schemas using modified version of zod2md Feb 24, 2025
@Muhammad-Altabba Muhammad-Altabba marked this pull request as ready for review February 24, 2025 19:47
@Muhammad-Altabba
Copy link
Author

An issue has been created at zod2md for the changes made in its fork. In this issue a list of the modifications has been provided along with a reference to the pushed commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant