CN108958727A - A kind of generation method and system of API client code - Google Patents

A kind of generation method and system of API client code Download PDF

Info

Publication number
CN108958727A
CN108958727A CN201810330934.XA CN201810330934A CN108958727A CN 108958727 A CN108958727 A CN 108958727A CN 201810330934 A CN201810330934 A CN 201810330934A CN 108958727 A CN108958727 A CN 108958727A
Authority
CN
China
Prior art keywords
code
api
client code
client
template
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201810330934.XA
Other languages
Chinese (zh)
Inventor
彭璟文
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Sailing Technology Co Ltd
Original Assignee
Beijing Sailing Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Sailing Technology Co Ltd filed Critical Beijing Sailing Technology Co Ltd
Priority to CN201810330934.XA priority Critical patent/CN108958727A/en
Publication of CN108958727A publication Critical patent/CN108958727A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/35Creation or generation of source code model driven
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Abstract

The invention discloses the generation methods and system of a kind of API client code, are related to computer field.This method comprises: carrying out standardization description to API, API is made to be converted to structural data;Obtain any one programming language Code Template and preset configuration file;The client code of API is generated according to structural data and Code Template, and the generating process of client code is controlled according to configuration file.The generation method and system of a kind of API client code provided by the invention, by carrying out standardization description to API, API is set to be converted to structural data, Code Template and preset configuration file further according to preset programming language generate the client code of API, it can be realized the generation to the API client code of a variety of programming languages, can be improved the formation efficiency of API client code.

Description

A kind of generation method and system of API client code
Technical field
The present invention relates to computer field more particularly to a kind of generation methods and system of API client code.
Background technique
Developer is developing client for API (Application Programming Interface, Application Programming Interface) When end, corresponding client code will be manually write for each API.Under normal conditions, the quantity of API can be more, And the client of a variety of programming languages is needed while developing, existing development approach opens the API client of a variety of programming languages Low efficiency is sent out, test, maintenance are also inconvenient.
Summary of the invention
The technical problem to be solved by the present invention is in view of the deficiencies of the prior art, provide a kind of API client code Generation method and system.
The technical scheme to solve the above technical problems is that
A kind of generation method of API client code, comprising:
Standardization description is carried out to API, the API is made to be converted to structural data;
Obtain any one programming language Code Template and preset configuration file;
The client code of the API is generated according to the structural data and the Code Template, and is matched according to described Set the generating process of client code described in document control.
The beneficial effects of the present invention are: a kind of generation method of API client code provided by the invention, by API Standardization description is carried out, the API is made to be converted to structural data, Code Template further according to preset programming language and default Configuration file generate API client code, can be realized the generation to the API client code of a variety of programming languages, energy Enough improve the formation efficiency of API client code.
Based on the above technical solution, the present invention can also be improved as follows.
Further, described that standardization description is carried out to API, before so that the API is converted to structural data, also wrap It includes:
Select a plurality of types of programming languages;
Write the Code Template of the various programming languages respectively, the Code Template of the programming language of all categories by Identical template instruction writes generation.
Further, described that standardization description is carried out to API, after so that the API is converted to structural data, also wrap It includes:
It is verified by correctness of the calibration tool to the structural data, when an error is discovered, to the mistake It is modified.
Beneficial effect using above-mentioned further scheme is: by calibration tool to the correctness of the structural data into Row verifying in time can be modified mistake after discovery API carries out standardization description when the error occurs.
Further, further includes:
Processing is formatted to the client code;
Error detection is carried out to the client code.
Beneficial effect using above-mentioned further scheme is:, can be true by being formatted processing to client code The readability of the code generated is protected, and by carrying out error detection to client code, can be improved the standard of client code True property.
Further, further includes:
Pass through unified natural language description displaying test case;
Test data is set;
Code skeleton is tested according to the displaying Test cases technology;
The client code is called in the test code skeleton, according to the test data to the client generation Code is tested.
The another technical solution that the present invention solves above-mentioned technical problem is as follows:
A kind of generation system of API client code, comprising:
API describes unit, for carrying out standardization description to API, the API is made to be converted to structural data;
Acquiring unit, for obtain any one programming language Code Template and preset configuration file;
Code generating unit, for generating the client of the API according to the structural data and the Code Template Code, and control according to the configuration file generating process of the client code.
The beneficial effects of the present invention are: a kind of generation system of API client code provided by the invention, is retouched by API It states unit and standardization description is carried out to API, so that the API is converted to structural data, then by code generating unit according to pre- If programming language Code Template and preset configuration file generate API client code, can be realized to a variety of programmings The generation of the API client code of language, can be improved the formation efficiency of API client code.
Further, further includes:
Code Template generation unit for selecting a plurality of types of programming languages, and writes the various programming languages respectively The Code Template of the Code Template of speech, the programming language of all categories writes generation by identical template instruction.
Further, further includes:
Verification unit, for being verified by correctness of the calibration tool to the structural data, and when discovery is wrong It mistakes, the mistake is modified.
Further, further includes:
Formatting unit, for being formatted processing to the client code;
Error detection units, for carrying out error checking to the client code.
Further, further includes:
For by unified natural language description displaying test case, and test data is arranged, and root in test cell Code skeleton is tested according to the displaying Test cases technology, and calls the client generation in the test code skeleton Code, tests the client code according to the test data.
The another technical solution that the present invention solves above-mentioned technical problem is as follows:
A kind of storage medium is stored with instruction in the storage medium, when computer reads described instruction, makes the meter Calculation machine executes method as described in the above technical scheme.
The advantages of additional aspect of the invention, will be set forth in part in the description, and will partially become from the following description It obtains obviously, or practice is recognized through the invention.
Detailed description of the invention
Fig. 1 is a kind of flow diagram that one embodiment of the generation method of API client code provides of the present invention;
Fig. 2 is a kind of flow diagram that another embodiment of the generation method of API client code provides of the present invention;
Fig. 3 is a kind of structural framing figure that one embodiment of the generation system of API client code provides of the present invention.
Specific embodiment
The principle and features of the present invention will be described below with reference to the accompanying drawings, and illustrated embodiment is served only for explaining the present invention, It is not intended to limit the scope of the present invention.
As shown in Figure 1, showing for a kind of process that one embodiment of the generation method of API client code provides of the present invention It is intended to, this method comprises:
S1 carries out standardization description to API, API is made to be converted to structural data.
It should be noted that by carrying out standardization description to API base can be provided for code building and automatic operation Plinth.Standardization description is carried out to API to refer to API being converted to structural data.
For example, standardization description can be carried out to API by Swagger.Swagger(OpenAPI It Specification is) specification for describing RESTful API, in the support of Linux foundation and numerous third party manufacturers Under, tool and ecology are relatively perfect, are widely used at present by industry.
In another example standardization description can also be carried out to API by description standards such as RAML, Blueprint.
S2, obtain any one programming language Code Template and preset configuration file.
It should be noted that Code Template can write in advance, can be write for different programming languages different Code Template, each programming language write a set of code template, this code template can be applied to all API.Code Template can be write by identical template language, further the entire development process of specification.
Configuration file can also write in advance, can write different configuration files for different programming languages, often A kind of programming language writes a configuration file, and content described in configuration file is only related to current programming language.
S3 generates the client code of API according to structural data and Code Template, and controls client according to configuration file Hold the generating process of code.
It should be noted that corresponding Code Generator can read the configuration file, is controlled and generated according to configuration file The behavior of code.
A kind of generation method of API client code provided in this embodiment is made by carrying out standardization description to API API is converted to structural data, and the Code Template and preset configuration file further according to preset programming language generate the visitor of API Family end code can be realized the generation to the API client code of a variety of programming languages, can be improved API client code Formation efficiency.
As shown in Fig. 2, showing for a kind of process that another embodiment of the generation method of API client code provides of the present invention It is intended to, this method comprises:
S1 carries out standardization description to API, API is made to be converted to structural data.
S2, obtain any one programming language Code Template and preset configuration file.
S3 generates the client code of API according to structural data and Code Template, and controls client according to configuration file Hold the generating process of code.
It should be noted that the explanation of step same as the previously described embodiments in the present embodiment, can refer to above-mentioned implementation In example pair it should be noted that details are not described herein.
Preferably, before step S1, can also include:
S01 selectes a plurality of types of programming languages.
S02 writes the Code Template of various programming languages respectively, and the Code Template of the programming language of all categories is by identical Template instruction write generation.
That is, every kind of programming language accordingly writes a kind of Code Template.
It should be noted that by the way that the Code Template of the programming language of all categories is write life by identical template instruction At can the further entire development process of specification.
Preferably, after step S1, can also include:
S03 is verified by correctness of the calibration tool to structural data, when an error is discovered, is carried out to mistake Amendment.
It should be noted that carrying out verifying to the correctness of structural data is determined according to the format of API Description standard 's.
For example, when API is described using Swagger description standard, since Swagger description standard is JSON format , therefore, it is possible to use JSON Schema come verify API standardization description correctness.
In another example kwalify can be used to verify the standardization of API and retouch when API is described using YAML format The correctness stated.
Preferably, this method can also include:
S4 is formatted processing to client code, carries out error detection to client code.
It should be noted that being formatted the mistake that processing refers to amendment client code style to client code Accidentally, it is ensured that generate the readability of the code come.
Preferably, this method can also include:
S5 passes through unified natural language description displaying test case.
For example, can carry out test scene description by Cucumber, Cucumber is a Behaviour- Driven Development (BDD) tool is supported to support predefined test data with natural language description test case.
In another example displaying test case can also be described by JDave, Concordion, Easyb, Jbehave etc..
Test data is arranged in S6.
Preferably, the test data including specific border situation can be set, can farthest reflect API client The correctness of the function at end.
It should be noted that general test data will include the test data of normal test data and mistake.With normal Test data test when, if test result be correctly, illustrate that code is correct;It is surveyed with the test data of mistake When examination, if test the result is that expected error value, illustrates that code is correct.But it also will include border condition, just It is those special data, when user's normal use hardly uses, it is likely that can cause the data of mistake.In addition It can be directed to newfound code error, individually increase dependence test.
S7 tests code skeleton according to displaying Test cases technology.
S8 calls client code in test code skeleton, is tested according to test data client code.
It should be noted that can be obtained by API if all test results all meet with default test result The function of client is normal.
The above is only a kind of development processes of the API client for programming language, can be to the API of every kind of programming language The identical development process of client executing, the API client functionality to guarantee all programming languages are consistent.
It preferably, can also be to API client progress side after completing to the exploitation of API client by above-mentioned process Just, efficiently update.
When needing to be updated API client, it is only necessary to which the standardization description for updating API regenerates each volume The code of the API client of Cheng Yuyan, so that it may complete the update to API client, can greatly reduce the dimension of API client Cost is protected, to avoid writing the relevant code of this API manually for every kind of language.
It should be noted that needing to update the corresponding displaying test case of API, after API update to ensure to test Cover all API.
After updating displaying test case, need to regenerate test code skeleton, and rerun API client The test at end, to ensure that the function of API client is newest.
A kind of generation method of API client code provided in this embodiment is made by carrying out standardization description to API API is converted to structural data, and the Code Template and preset configuration file further according to preset programming language generate the visitor of API Family end code can be realized the generation to the API client code of a variety of programming languages, can be improved API client code Formation efficiency.And verified by correctness of the calibration tool to structural data, standardization can be carried out in discovery API retouch After stating when the error occurs, mistake is modified in time.And by being formatted processing to client code, it can be ensured that The readability of the code of generation, and by carrying out error detection to client code, it can be improved the accurate of client code Property.
As shown in figure 3, for a kind of structural frames that one embodiment of the generation system of API client code provides of the present invention Frame figure, the system include:
API describes unit 1, for carrying out standardization description to API, API is made to be converted to structural data.
Acquiring unit 2, for obtain any one programming language Code Template and preset configuration file.
Code generating unit 3, for the client code according to structural data and Code Template generation API, and according to The generating process of configuration file control client code.
Preferably, which can also include:
Code Template generation unit 4 for selecting a plurality of types of programming languages, and writes various programming languages respectively The Code Template of Code Template, the programming language of all categories writes generation by identical template instruction.
Preferably, which can also include:
Verification unit 5, for being verified by correctness of the calibration tool to structural data, and when discovery mistake When, mistake is modified.
Preferably, which can also include:
Formatting unit 6, for being formatted processing to client code.
Error detection units 7, for carrying out error checking to client code.
Preferably, which can also include:
For by unified natural language description displaying test case, and test data is arranged in test cell 8, and Code skeleton is tested according to displaying Test cases technology, and calls client code in test code skeleton, according to test Data test client code.
A kind of generation system of API client code provided in this embodiment, describes unit by API and advises to API Generalized description makes API be converted to structural data, then by code generating unit according to the Code Template of preset programming language The client code that API is generated with preset configuration file, can be realized the life to the API client code of a variety of programming languages At can be improved the formation efficiency of API client code.
In another embodiment, the present invention also provides a kind of storage medium, it is stored with instruction in the storage medium, works as calculating It is machine-readable when taking the instruction, so that computer is executed method described in above-described embodiment.
Reader should be understood that in the description of this specification reference term " one embodiment ", " is shown " some embodiments " The description of example ", " specific example " or " some examples " etc. mean specific features described in conjunction with this embodiment or example, structure, Material or feature are included at least one embodiment or example of the invention.In the present specification, above-mentioned term is shown The statement of meaning property need not be directed to identical embodiment or example.Moreover, particular features, structures, materials, or characteristics described It may be combined in any suitable manner in any one or more of the embodiments or examples.In addition, without conflicting with each other, this The technical staff in field can be by the spy of different embodiments or examples described in this specification and different embodiments or examples Sign is combined.
It is apparent to those skilled in the art that for convenience of description and succinctly, the dress of foregoing description The specific work process with unit is set, can refer to corresponding processes in the foregoing method embodiment, details are not described herein.
In several embodiments provided herein, it should be understood that disclosed device and method can pass through it Its mode is realized.For example, the apparatus embodiments described above are merely exemplary, for example, the division of unit, only A kind of logical function partition, there may be another division manner in actual implementation, for example, multiple units or components can combine or Person is desirably integrated into another system, or some features can be ignored or not executed.
Unit may or may not be physically separated as illustrated by the separation member, shown as a unit Component may or may not be physical unit, it can and it is in one place, or may be distributed over multiple networks On unit.It can select some or all of unit therein according to the actual needs to realize the mesh of the embodiment of the present invention 's.
It, can also be in addition, the functional units in various embodiments of the present invention may be integrated into one processing unit It is that each unit physically exists alone, is also possible to two or more units and is integrated in one unit.It is above-mentioned integrated Unit both can take the form of hardware realization, can also realize in the form of software functional units.
It, can if integrated unit is realized in the form of SFU software functional unit and when sold or used as an independent product To be stored in a computer readable storage medium.Based on this understanding, technical solution of the present invention substantially or Say that all or part of the part that contributes to existing technology or the technical solution can embody in the form of software products Out, which is stored in a storage medium, including some instructions are used so that a computer equipment (can be personal computer, server or the network equipment etc.) executes all or part of each embodiment method of the present invention Step.And storage medium above-mentioned includes: USB flash disk, mobile hard disk, read-only memory (ROM, Read-OnlyMemory), deposits at random The various media that can store program code such as access to memory (RAM, RandomAccessMemory), magnetic or disk.
More than, only a specific embodiment of the invention, but scope of protection of the present invention is not limited thereto, and it is any to be familiar with Those skilled in the art in the technical scope disclosed by the present invention, can readily occur in various equivalent modifications or substitutions, These modifications or substitutions should be covered by the protection scope of the present invention.Therefore, protection scope of the present invention should be wanted with right Subject to the protection scope asked.

Claims (10)

1. a kind of generation method of API client code characterized by comprising
Standardization description is carried out to API, the API is made to be converted to structural data;
Obtain any one programming language Code Template and preset configuration file;
The client code of the API is generated according to the structural data and the Code Template, and according to the configuration text Part controls the generating process of the client code.
2. generation method according to claim 1, which is characterized in that it is described that standardization description is carried out to API, make described API is converted to before structural data, further includes:
Select a plurality of types of programming languages;
The Code Template of the various programming languages is write respectively, and the Code Template of the programming language of all categories is by identical Template instruction write generation.
3. generation method according to claim 1, which is characterized in that it is described that standardization description is carried out to API, make described API is converted to after structural data, further includes:
It is verified by correctness of the calibration tool to the structural data, when an error is discovered, the mistake is carried out Amendment.
4. generation method according to any one of claim 1 to 3, which is characterized in that further include:
Processing is formatted to the client code;
Error detection is carried out to the client code.
5. generation method according to any one of claim 1 to 3, which is characterized in that further include:
Pass through unified natural language description displaying test case;
Test data is set;
Code skeleton is tested according to the displaying Test cases technology;
Call the client code in the test code skeleton, according to the test data to the client code into Row test.
6. a kind of generation system of API client code characterized by comprising
API describes unit, for carrying out standardization description to API, the API is made to be converted to structural data;
Acquiring unit, for obtain any one programming language Code Template and preset configuration file;
Code generating unit, for generating the client code of the API according to the structural data and the Code Template, And the generating process of the client code is controlled according to the configuration file.
7. generation system according to claim 6, which is characterized in that further include:
Code Template generation unit for selecting a plurality of types of programming languages, and writes the various programming languages respectively The Code Template of Code Template, the programming language of all categories writes generation by identical template instruction.
8. generation system according to claim 6, which is characterized in that further include:
Verification unit, for being verified by correctness of the calibration tool to the structural data, and when an error is discovered, The mistake is modified.
9. the generation system according to any one of claim 6 to 8, which is characterized in that further include:
Formatting unit, for being formatted processing to the client code;
Error detection units, for carrying out error checking to the client code.
10. the generation system according to any one of claim 6 to 8, which is characterized in that further include:
For by unified natural language description displaying test case, and test data is arranged, and according to institute in test cell Displaying Test cases technology test code skeleton is stated, and calls the client code, root in the test code skeleton The client code is tested according to the test data.
CN201810330934.XA 2018-04-13 2018-04-13 A kind of generation method and system of API client code Pending CN108958727A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810330934.XA CN108958727A (en) 2018-04-13 2018-04-13 A kind of generation method and system of API client code

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810330934.XA CN108958727A (en) 2018-04-13 2018-04-13 A kind of generation method and system of API client code

Publications (1)

Publication Number Publication Date
CN108958727A true CN108958727A (en) 2018-12-07

Family

ID=64498804

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810330934.XA Pending CN108958727A (en) 2018-04-13 2018-04-13 A kind of generation method and system of API client code

Country Status (1)

Country Link
CN (1) CN108958727A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113064585A (en) * 2021-04-30 2021-07-02 中国电子科技集团公司第二十九研究所 JSON mode-based real-time message interface automatic generation method
CN117370242A (en) * 2023-10-09 2024-01-09 汇付天下有限公司 Adapter and method for generating multilingual SDK client by parsing interface document

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2008305079A (en) * 2007-06-06 2008-12-18 Fuji Electric Holdings Co Ltd Requirement specification automatic verification method
CN103135976A (en) * 2011-11-30 2013-06-05 阿里巴巴集团控股有限公司 Code automatic generation method and device
CN105117233A (en) * 2015-09-14 2015-12-02 百度在线网络技术(北京)有限公司 API calling method and device
CN107688526A (en) * 2017-08-25 2018-02-13 上海壹账通金融科技有限公司 Performance test methods, device, computer equipment and the storage medium of application program

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2008305079A (en) * 2007-06-06 2008-12-18 Fuji Electric Holdings Co Ltd Requirement specification automatic verification method
CN103135976A (en) * 2011-11-30 2013-06-05 阿里巴巴集团控股有限公司 Code automatic generation method and device
CN105117233A (en) * 2015-09-14 2015-12-02 百度在线网络技术(北京)有限公司 API calling method and device
CN107688526A (en) * 2017-08-25 2018-02-13 上海壹账通金融科技有限公司 Performance test methods, device, computer equipment and the storage medium of application program

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113064585A (en) * 2021-04-30 2021-07-02 中国电子科技集团公司第二十九研究所 JSON mode-based real-time message interface automatic generation method
CN113064585B (en) * 2021-04-30 2023-04-11 中国电子科技集团公司第二十九研究所 JSON mode-based real-time message interface automatic generation method
CN117370242A (en) * 2023-10-09 2024-01-09 汇付天下有限公司 Adapter and method for generating multilingual SDK client by parsing interface document

Similar Documents

Publication Publication Date Title
JP4961123B2 (en) Automated test case validation loosely coupled with respect to automated test case execution
US7908518B2 (en) Method, system and computer program product for failure analysis implementing automated comparison of multiple reference models
US20060156287A1 (en) Auto conversion of tests between different functional testing tools
CN109408357A (en) A kind of automatic interface testing method and device
CN103744680B (en) Method and device for business process processing
CN104794048B (en) A kind of UI automated testing methods and system
CN112131829A (en) Verification method, system and related device of chip register
CN109783388A (en) UI automated testing method, device and electronic equipment
CN108694118B (en) Application testing method and device
CN103399814B (en) The method and device of automatic test
US20070061641A1 (en) Apparatus and method for generating test driver
CN109901985B (en) Distributed test apparatus and method, storage medium, and electronic device
CN107656872A (en) Method for testing software, device, equipment and computer-readable storage medium
CN109933521A (en) Automated testing method, device, computer equipment and storage medium based on BDD
CN112241360A (en) Test case generation method, device, equipment and storage medium
CN111679982A (en) Automatic testing method for REST API (representational State transfer) interface software
CN108958727A (en) A kind of generation method and system of API client code
CN106874202A (en) Method, device and readable storage medium storing program for executing for unit testing
EP2883134A1 (en) Executable software specification generation
CN112100078A (en) Method, device and equipment for generating interface test case
CN108153635B (en) System memory edge testing method, system device and computer readable storage medium
CN112988578A (en) Automatic testing method and device
Lipka et al. A method for semi-automated generation of test scenarios based on use cases
CN109474822B (en) Android television multi-language automatic testing method and device
CN110489336A (en) A kind of software interface Test cases technology and maintaining method and its device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information
CB02 Change of applicant information

Address after: 100020 601, 6 floor, 16 building, No. 36 Chuang Yuan Road, Chaoyang District, Beijing.

Applicant after: Beijing Qingyun Science and Technology Co., Ltd.

Address before: 100020 601, 6 floor, 16 building, No. 36 Chuang Yuan Road, Chaoyang District, Beijing.

Applicant before: Beijing sailing Technology Co., Ltd.

RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20181207