-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add review contracts endpoint. (#1128)
* feat: new endpoint.
- Loading branch information
Showing
25 changed files
with
611 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@moralisweb3/common-evm-utils': patch | ||
'@moralisweb3/evm-api': patch | ||
'moralis': patch | ||
--- | ||
|
||
Added the new endpoint method to the EVM API module: `Moralis.EvmApi.utils.reviewContracts`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
packages/apiGenerator/src/reader/OpenApiReader.inlineEnum.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { OpenApiReader } from './OpenApiReader'; | ||
import { OpenApiReaderConfiguration } from './OpenApiReaderConfiguration'; | ||
|
||
describe('OpenApiReader', () => { | ||
it('inline enum', () => { | ||
const configuration: OpenApiReaderConfiguration = { | ||
v3: { | ||
operations: { | ||
groupRef: '#/operationId', | ||
isEnabledRef: '#/operationId', | ||
}, | ||
}, | ||
}; | ||
const result = OpenApiReader.create( | ||
{ | ||
openapi: '3.0.0', | ||
info: { | ||
title: 'test', | ||
version: '1', | ||
}, | ||
paths: { | ||
'/contracts-review': { | ||
post: { | ||
operationId: 'reviewContracts', | ||
requestBody: { | ||
description: 'Body', | ||
required: true, | ||
content: { | ||
'application/json': { | ||
schema: { | ||
$ref: '#/components/schemas/ContractsReviewDto', | ||
}, | ||
}, | ||
}, | ||
}, | ||
parameters: [], | ||
responses: { | ||
'200': { | ||
description: 'Response', | ||
content: { | ||
'application/json': { | ||
schema: { | ||
type: 'object', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
components: { | ||
schemas: { | ||
contractsReviewItem: { | ||
required: ['report_type'], | ||
properties: { | ||
report_type: { | ||
type: 'string', | ||
enum: ['spam', 'not_spam'], | ||
}, | ||
}, | ||
}, | ||
ContractsReviewDto: { | ||
required: ['contracts'], | ||
properties: { | ||
contracts: { | ||
type: 'array', | ||
items: { | ||
$ref: '#/components/schemas/contractsReviewItem', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
configuration, | ||
).read(); | ||
|
||
const operation = result.operations[0]; | ||
expect(operation.operationId).toBe('reviewContracts'); | ||
expect(operation.httpMethod).toBe('post'); | ||
expect(operation.routePattern).toBe('/contracts-review'); | ||
expect(operation.body).toBeDefined(); | ||
|
||
const body = operation.body!; | ||
expect(body.descriptor.ref.toString()).toBe('#/components/schemas/ContractsReviewDto'); | ||
|
||
expect(result.complexTypes).toHaveLength(2); | ||
|
||
const complexType0 = result.complexTypes[0]; | ||
expect(complexType0.descriptor.ref.toString()).toBe('#/components/schemas/ContractsReviewDto'); | ||
expect(complexType0.properties).toHaveLength(1); | ||
|
||
const complexType1 = result.complexTypes[1]; | ||
expect(complexType1.descriptor.ref.toString()).toBe('#/components/schemas/contractsReviewItem'); | ||
expect(complexType1.properties).toHaveLength(1); | ||
|
||
expect(result.simpleTypes).toHaveLength(2); | ||
|
||
const simpleType0 = result.simpleTypes[0]; | ||
expect(simpleType0.descriptor.ref.toString()).toBe( | ||
'#/paths/~1contracts-review/post/responses/200/content/application~1json/schema', | ||
); | ||
expect(simpleType0.descriptor.isArray).toBe(false); | ||
expect(simpleType0.descriptor.typeName.toString()).toBe('reviewContracts'); | ||
expect(simpleType0.nativeType).toBe('object'); | ||
expect(simpleType0.enum).toBeUndefined(); | ||
|
||
const simpleType1 = result.simpleTypes[1]; | ||
expect(simpleType1.descriptor.ref.toString()).toBe( | ||
'#/components/schemas/contractsReviewItem/properties/report_type', | ||
); | ||
expect(simpleType1.descriptor.isArray).toBe(false); | ||
expect(simpleType1.descriptor.typeName.toString()).toBe('contractsReviewItem_report_type_Enum'); | ||
expect(simpleType1.nativeType).toContain('string'); | ||
expect(simpleType1.enum).toContain('spam'); | ||
expect(simpleType1.enum).toContain('not_spam'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/common/evmUtils/src/generated/operations/ReviewContractsOperation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { EvmChain, EvmChainInput, EvmChainJSON } from '../../dataTypes'; | ||
import { EvmReviewContracts, EvmReviewContractsJSON } from '../types/EvmReviewContracts'; | ||
import { EvmContractsReviewDto, EvmContractsReviewDtoInput, EvmContractsReviewDtoJSON } from '../types/EvmContractsReviewDto'; | ||
|
||
// request parameters: | ||
// - chain ($ref: #/components/schemas/chainList) | ||
|
||
export interface ReviewContractsOperationRequest { | ||
/** | ||
* @description The chain to query | ||
*/ | ||
readonly chain?: EvmChainInput | EvmChain; | ||
} | ||
|
||
export interface ReviewContractsOperationRequestJSON { | ||
readonly chain?: EvmChainJSON; | ||
} | ||
|
||
export type ReviewContractsOperationResponse = EvmReviewContracts; | ||
export type ReviewContractsOperationResponseJSON = EvmReviewContractsJSON; | ||
|
||
export type ReviewContractsOperationBody = EvmContractsReviewDtoInput | EvmContractsReviewDto; | ||
|
||
export const ReviewContractsOperation = { | ||
operationId: "reviewContracts", | ||
groupName: "utils", | ||
httpMethod: "post", | ||
routePattern: "/contracts-review", | ||
parameterNames: ["chain"], | ||
hasResponse: true, | ||
hasBody: true, | ||
|
||
parseResponse(json: EvmReviewContractsJSON): EvmReviewContracts { | ||
return EvmReviewContracts.fromJSON(json); | ||
}, | ||
|
||
serializeRequest(request: ReviewContractsOperationRequest): ReviewContractsOperationRequestJSON { | ||
const chain = request.chain ? EvmChain.create(request.chain) : undefined; | ||
return { | ||
chain: chain ? chain.toJSON() : undefined, | ||
}; | ||
}, | ||
|
||
serializeBody(body: EvmContractsReviewDtoInput | EvmContractsReviewDto): EvmContractsReviewDtoJSON { | ||
const value = EvmContractsReviewDto.create(body); | ||
return value.toJSON(); | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
98035a8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test coverage