CN115291851A - Software development kit code generation method, device, equipment and storage medium - Google Patents

Software development kit code generation method, device, equipment and storage medium Download PDF

Info

Publication number
CN115291851A
CN115291851A CN202210997446.0A CN202210997446A CN115291851A CN 115291851 A CN115291851 A CN 115291851A CN 202210997446 A CN202210997446 A CN 202210997446A CN 115291851 A CN115291851 A CN 115291851A
Authority
CN
China
Prior art keywords
module
class
character string
file
determining
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
CN202210997446.0A
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.)
Shanghai Information2 Software Inc
Original Assignee
Shanghai Information2 Software Inc
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 Shanghai Information2 Software Inc filed Critical Shanghai Information2 Software Inc
Priority to CN202210997446.0A priority Critical patent/CN115291851A/en
Publication of CN115291851A publication Critical patent/CN115291851A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Library & Information Science (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the invention discloses a method, a device, equipment and a storage medium for generating a software development kit code. The method comprises the following steps: acquiring at least one target interface document library, and converting each target interface document library into a corresponding target object numbered musical notation file through a preset format conversion program; constructing a module array set corresponding to each target object numbered musical notation file; traversing each module in the module array set, and determining a fixed character string and a method character string corresponding to each module; and for each module, splicing the fixed character strings and the method character strings corresponding to the modules, writing the fixed character strings and the method character strings into a file according to the package path corresponding to the module, and generating a software development package code corresponding to a target interface document library. The technical scheme of the embodiment of the invention solves the problem that the interface calling and packaging development kit can be modified only by adopting a handwriting mode after the existing online API document is modified, reduces the development cost, saves the development time and improves the development efficiency.

Description

Software development kit code generation method, device, equipment and storage medium
Technical Field
The embodiment of the invention relates to the technical field of software development, in particular to a method, a device, equipment and a storage medium for generating a software development kit code.
Background
In the current internet technology and software development process, different Application systems or modules are often called through Application Program Interfaces (APIs) to implement mutual communication between computer software. One of the main functions of the API is to provide general-purpose functions and also to be a middleware that provides data sharing for various platforms. Software Development Kit (SDK) is generally a collection of APIs, development assistance tools, and documentation that are provided to facilitate the Development of applications for a system by a developer. In order to facilitate the maintenance of API documents and simulate Mock data function requirements, many on-line API interface document management tools, such as RAP2 and Easymock, have been created to improve collaborative development efficiency in team internal use.
However, since the software product will provide the API for the client as a third-party service to call, after the API is modified online, if the modified API is only a specific API, the development time of the calling method under the client's own package is still acceptable, but if deep interaction exists, the number of called APIs is large, the time for calling the package interface is correspondingly increased, and it is difficult to provide a better service. In the prior art, when the interface changes such as newly adding, reducing or changing definition, the corresponding code of the SDK needs to be synchronously modified, and more repeated labor time is needed for modifying the interface calling package in a handwriting mode every time, and the SDK code is difficult to be directly modified by the existing online API document management tool.
Disclosure of Invention
The invention provides a method, a device, equipment and a storage medium for generating a software development kit code, which are used for realizing synchronous updating of an SDK code when an API is modified through an online API interface document management tool, reducing repeated labor in the SDK code generation process, reducing the manual participation degree in the development process, improving the development efficiency, saving the development time and reducing the development cost.
In a first aspect, an embodiment of the present invention provides a method for generating a software development kit code, including:
acquiring at least one target interface document library, and converting each target interface document library into a corresponding target object numbered musical notation file through a preset format conversion program;
constructing a module array set corresponding to each target object numbered musical notation file; the target object numbered musical notation file comprises at least one module;
traversing each module in the module array set, and determining a fixed character string and a method character string corresponding to each module;
and for each module, splicing the fixed character strings and the method character strings corresponding to the modules, writing the fixed character strings and the method character strings into a file according to the package path corresponding to the module, and generating a software development package code corresponding to the target interface document library.
In a second aspect, an embodiment of the present invention further provides a software development kit code generation apparatus, including:
the file conversion module is used for acquiring at least one target interface document library and converting each target interface document library into a corresponding target object numbered musical notation file through a preset format conversion program;
the array set constructing module is used for constructing a module array set corresponding to each target object numbered musical notation file; the target object numbered musical notation file comprises at least one module;
the character string determining module is used for traversing each module in the module array set and determining a fixed character string and a method character string corresponding to each module;
and the code generation module is used for splicing the fixed character strings and the method character strings corresponding to the modules for each module, writing the fixed character strings and the method character strings into a file according to the package path corresponding to the modules and generating the software development package codes corresponding to the target interface document library.
In a third aspect, an embodiment of the present invention further provides a software development kit code generation device, where the software development kit code generation device includes: a storage device and one or more processors;
storage means for storing one or more programs;
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the software development kit code generation method as described above in the first aspect.
In a fourth aspect, embodiments of the present invention further provide a storage medium containing computer-executable instructions, which when executed by a computer processor, are configured to perform the software development kit code generation method provided in any of the embodiments of the present invention.
The embodiment of the invention provides a method, a device, equipment and a storage medium for generating a software development kit code, wherein the method comprises the steps of obtaining at least one target interface document library, and converting each target interface document library into a corresponding target object numbered musical notation file through a preset format conversion program; constructing a module array set corresponding to each target object numbered musical notation file; the target object numbered musical notation file comprises at least one module; traversing each module in the module array set, and determining a fixed character string and a method character string corresponding to each module; and for each module, splicing the fixed character strings and the method character strings corresponding to the modules, writing the fixed character strings and the method character strings into a file according to the package path corresponding to the module, and generating a software development package code corresponding to the target interface document library. By adopting the technical scheme, after the API is modified online, a target interface document library which corresponds to the modified API and needs to be generated by software development kit SDK codes is determined, the target interface document library is converted into a corresponding target object numbered notation file through a preset format conversion program, a module array set corresponding to the target object numbered notation file is constructed, traversing is carried out on each module to determine a fixed character string which is relatively fixed and unchangeable in each module and a method character string which corresponds to the changed API and is contained in each module, the fixed character string and the method character string are combined and written into the file according to rules, and the software development kit codes corresponding to the target interface document library are generated.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained according to the drawings without inventive efforts.
Fig. 1 is a flowchart of a software development kit code generation method according to a first embodiment of the present invention;
fig. 2 is a flowchart of a software development kit code generation method according to a second embodiment of the present invention;
fig. 3 is a flowchart illustrating a process of traversing each module in the module array set, replacing and filling a preset character string template according to a definition object of each module, and determining a fixed character string corresponding to each module in the second embodiment of the present invention;
fig. 4 is a flowchart illustrating a second embodiment of the present invention, in which all interfaces in a module are traversed, a class method array set corresponding to the module is determined, and the class method array set is converted into a corresponding method string;
fig. 5 is a schematic structural diagram of a software development kit code generation apparatus in a third embodiment of the present invention;
fig. 6 is a schematic structural diagram of a software development kit code generation apparatus in the fourth embodiment of the present invention.
Detailed Description
To make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in further detail below with reference to the accompanying drawings. It should be understood that the described embodiments are only some embodiments of the invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary examples do not represent all implementations consistent with the present invention. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the invention, as detailed in the appended claims.
In the description of the present invention, it is to be understood that the terms "first," "second," "third," and the like are used solely for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order, nor is it to be construed as indicating or implying relative importance. The specific meanings of the above terms in the present invention can be understood by those skilled in the art according to specific situations. In addition, in the description of the present invention, "a plurality" means two or more unless otherwise specified. "and/or" describes the association relationship of the associated object, indicating that there may be three relationships, for example, a and/or B, which may indicate: a exists alone, A and B exist simultaneously, and B exists alone. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship.
Example one
Fig. 1 is a flowchart of a software development kit code generation method according to an embodiment of the present invention, where the method is applicable to a case where a software development kit code is automatically generated after an application program interface is modified online, and the method may be executed by a software development kit code generation device, where the software development kit code generation device may be implemented by software and/or hardware, and the software development kit code generation device may be configured on a software development kit code generation device, and the software development kit code generation device may be a computer device, and the computer device may be formed by two or more physical entities or may be formed by one physical entity.
As shown in fig. 1, a method for generating a software development kit code according to an embodiment of the present invention specifically includes the following steps:
s101, at least one target interface document library is obtained, and each target interface document library is converted into a corresponding target object numbered musical notation file through a preset format conversion program.
In this embodiment, the target interface document library may be specifically understood as an online interface document library that contains the modified application program interface and needs to be generated by the software development kit code; the online interface document library can be understood as an online repository containing the same interface class and definition documents corresponding to the interfaces. The preset format conversion program may be specifically understood as a program or a script that is preset according to a format conversion requirement and can convert the content in the online interface document library into a target file format. The Object Notation (JSON) may be specifically understood as a lightweight data exchange format, and is also a data format to which the target interface document library needs to be converted in the embodiment of the present invention. The target object numbered musical notation file can be specifically understood as a file which corresponds to the target interface document library and is obtained after data format conversion.
Specifically, when an application program interface is modified online and software development kit codes are required to be automatically generated, at least one online interface document library required to be generated by the software development kit codes is acquired from all online interface document libraries and used as a target interface document library, a preset format conversion program is adopted to read data of the target interface document library and convert the read data into corresponding target object numbered musical notation files, and it is clear that the generated target object numbered musical notation files correspond to the target interface document library one to one.
And S102, constructing a module array set corresponding to each target object numbered musical notation file.
The target object numbered musical notation file comprises at least one module.
In this embodiment, the module may be specifically understood as subclass combination information under the interface class in the target object numbered musical notation file. The module array set can be specifically understood as an array set formed by all modules in the target object numbered musical notation file.
Specifically, because each target object numbered musical notation file has one or more modules, the modules in each target object numbered musical notation file can be extracted, all the modules are combined into a large array combination set, and the array combination set is determined as the module array set corresponding to each target object numbered musical notation file.
In the embodiment of the invention, all modules in the target object numbered musical notation file which need to be subjected to code generation are extracted and form a module array set, so that the modules can be conveniently subjected to traversal processing in the code generation process, and the data processing speed is improved.
S103, traversing each module in the module array set, and determining a fixed character string and a method character string corresponding to each module.
In this embodiment, a fixed string is specifically understood as a string used in software development kit code to characterize a more fixed portion of a class in a module and a test class. The method character string may be specifically understood as a character string generated by combining a corresponding language definition format and corresponding to each application program interface corresponding element in one module in a software development kit code.
Specifically, traversing is performed on each module in the module array set in sequence, and for each module, according to a definition object of the module, a fixed character string used for representing a character string of a relatively fixed part in a corresponding class and a test class when the module is converted into a software development kit code is determined, and the fixed character string can also be understood as a "header" corresponding to the class and the test class in one module. And traversing all interfaces contained in the module for determining the fixed character strings, and generating method character strings corresponding to various types and test types in the module according to the interface elements corresponding to the interfaces and the corresponding language definition formats.
And S104, splicing the fixed character strings and the method character strings corresponding to the modules for each module, writing the spliced fixed character strings and method character strings into a file according to the package path corresponding to the module, and generating a software development package code corresponding to the target interface document library.
In this embodiment, the packet path may be specifically understood as a storage path for storing data to a corresponding location under a category directory in a file.
Specifically, for each module in the module array set, the fixed character string corresponding to the module array set and the method character strings corresponding to the classes and test classes corresponding to the module array set are sequentially spliced to form a complete class code string, the complete class code string is written into a file according to a package path corresponding to the module until the writing of each module class code string in the module array set is completed, and the file generated by writing is determined to be a software development package code corresponding to the target interface document library.
The method comprises the steps of obtaining at least one target interface document library, and converting each target interface document library into a corresponding target object numbered musical notation file through a preset format conversion program; constructing a module array set corresponding to each target object numbered musical notation file; the target object numbered musical notation file comprises at least one module; traversing each module in the module array set, and determining a fixed character string and a method character string corresponding to each module; and for each module, splicing the fixed character strings and the method character strings corresponding to the modules, writing the fixed character strings and the method character strings into a file according to the package path corresponding to the module, and generating a software development package code corresponding to the target interface document library. By adopting the technical scheme, after the API is modified online, a target interface document library which corresponds to the modified API and needs to be generated by software development kit SDK codes is determined, the target interface document library is converted into a corresponding target object numbered notation file through a preset format conversion program, a module array set corresponding to the target object numbered notation file is constructed, traversing is carried out on each module to determine a fixed character string which is relatively fixed and unchangeable in each module and a method character string which corresponds to the changed API and is contained in each module, the fixed character string and the method character string are combined and written into the file according to rules, and the software development kit codes corresponding to the target interface document library are generated.
Example two
Fig. 2 is a flowchart of a software development kit code generation method provided in the second embodiment of the present invention, and the technical solution of the second embodiment of the present invention is further optimized based on the above optional technical solutions, and before at least one target interface document library is obtained, a table structure in an online interface document system database is first analyzed to generate a preset format conversion program for performing data format conversion on an interface document library, and during traversal of each module in a module array set, a preset character string template is instead filled according to a definition object of the module to determine a fixed character string corresponding to the module, and all interfaces in each module are traversed to generate a class method array set according to an interface element of each interface and convert the class method array set into a class method character string corresponding to the module and a test class method character string. And then constructing a corresponding class directory and a corresponding test class directory according to the class name, the class package name, the test class name and the test class package name contained in each module fixed character string, splicing the spliced fixed character string and the method character string, supplementing completely, sequentially writing the spliced fixed character string and the method character string into the class directory or the test class directory corresponding to the spliced fixed character string, and determining a finally generated file as a software development package code corresponding to all interfaces in the target interface document library. After the online API document management tool modifies the API stored in the online interface document system database, the automatic synchronous update of the software development kit code can be realized, the repeated operation of calling and packaging the interface in the software development kit code generation process is not required to be manually participated, the development cost is reduced, the development efficiency is improved, and the development time is saved.
As shown in fig. 2, a software development kit code generation method provided in the second embodiment of the present invention specifically includes the following steps:
s201, analyzing a table structure of an online interface document system database.
The online interface document system database comprises a plurality of online interface document libraries.
In this embodiment, the online interface document system database may be specifically understood as a database of online interface document libraries, that is, the contents of a plurality of online interface document libraries are stored in the online interface document system database. The table structure may be specifically understood as basic attributes of a table in the online interface document system database, such as a field, a type, a primary key, a foreign key, an index, and the like, to represent types of data stored in the table and storage locations of each data.
Specifically, basic attributes such as fields, types, primary keys, foreign keys, indexes and the like of each table in the online interface document system are analyzed, and the information types stored in each table are determined to obtain an analysis result.
S202, determining the position information and the associated information of the interface definition information in the online interface document system database according to the analysis result.
In the present embodiment, the interface definition information may be specifically understood as information for defining an interface name, an interface address, an interface request and a response manner, and the like. The interface definition information may specifically include, for example, an interface name, an address, a request type, an interface description, a request header, a request body, a response body, and the like. Location information may be understood in particular as the location of a table in which part of the interface definition information is located in the online interface document system database. The association information may be understood as an association field indicating an interface in a table, i.e. a link of the direct relationship of the interface definition information in a plurality of tables.
Specifically, for the interface definition information of an interface to be acquired, at least several parts of an interface name, an address, a request mode, a request body and a response body of the interface need to be clarified, according to an analysis result of a database table structure of an online interface document system, the positions of the parts in a table in the online interface document system database are clarified, the positions are determined as position information, and meanwhile, the association fields of the interface in the tables are determined as association information.
S203, constructing a preset format conversion program according to the position information, the association information and the file format of the numbered musical notation of the predefined object.
Specifically, because the object numbered musical notation file has a specific file format, the interface definition information obtainable according to the position information and the association information can be converted to the corresponding position in the object numbered musical notation format according to the determined position information and the association information, and then a preset format conversion program is constructed according to the conversion relation, so that the subsequent script can process the acquired data in the online interface document library, and the object numbered musical notation file with the uniform predefined format is output.
For example, taking the online API document management tool as RAP2, after logging in the database, the list of tables can be obtained by using the database query all tables command (show tables):
1.Users
2.Organizations
3.repositories
4.repositories_members
5.organizations_members
6.Modules
7.Interfaces
8.Loggers
9.Properies
……
combining the functions of an RAP2 online interface document system, sequentially using database instructions defined by a lookup table, and querying a table (desc xxxx) in a table list; the repositories table can be found to mainly define interface large-class set information; the Modules table mainly defines module information, namely subclass combination information under the interface major class; the interface table mainly stores interface definition information, wherein the interface definition information only comprises a name, an address, a request mode and description, and two parts of a necessary request body and a necessary response body are lacked; further, the Properties stores two parts of a request body and a response body, and the request body and the response body can be distinguished through scope fields. The complete information of the interface definition can be obtained by combining the information of several tables in the online interface document system database: properties identifies the interface to which the property belongs through the interfaceId field, and scope is used for distinguishing types; the Interfaces identify the modules which the Interfaces belong to through the modules ID, namely identify the subclasses which the Interfaces belong to; modules identifies the large class to which the Modules belong through a repositoryId field, and further obtains the final analysis result based on the online interface document system database table structure. Different online interface document system databases need to be analyzed according to corresponding table structures, storage positions of several necessary factors of interface definition information and relations among the association tables are determined, and then a preset format conversion program for converting the online interface document library to the format of the object numbered notation file is generated.
And S204, acquiring at least one target interface document library, and converting each target interface document library into a corresponding target object numbered musical notation file through a preset format conversion program.
S205, analyzing the object numbered musical notation character strings in each target object numbered musical notation file, and determining the target objects corresponding to each target object numbered musical notation file.
Specifically, target object numbered musical notation files converted by a preset format conversion program are sequentially read, and then after the reading is finished, the character string analysis function in the preset programming language is used for analyzing the object numbered musical notation character strings in the target object numbered musical notation file construction, so that the target objects corresponding to the target object numbered musical notation files are obtained.
Illustratively, the target object numbered musical notation file converted by the preset format conversion program may be read by a built-in method file _ get _ contents of a computer programming language (PHP), and after the file reading is completed, the read target numbered musical notation character string is parsed into a corresponding target object by using a json _ decode function of the PHP.
S206, extracting modules in each target object, and combining the modules to generate a module array set.
Specifically, module extraction is performed on each target object, all modules extracted from all target objects are combined into a large array set, and the array set is determined as a module array set corresponding to each target object numbered file.
And S207, traversing each module in the module array set, replacing and filling the preset character string template according to the definition object of each module, and determining the fixed character string corresponding to each module.
In this embodiment, the preset string template may be understood as a preset string template for generating a relatively fixed portion of the class and the test class in the software development kit code. Illustratively, the preset string template may specifically include import guidance package, class definition code, test class initialization method, and the like.
Specifically, traversing each module in the module array set, determining definition information of a single module, replacing a variable part in a preset character string template according to the determined definition information, filling the preset character string template according to class names and package names of classes and test classes contained in the module definition information determination module, and finally generating a fixed character string corresponding to each module.
Further, fig. 3 is a flowchart illustrating traversing each module in the module array set, replacing and filling the preset character string template according to the definition object of each module, and determining the fixed character string corresponding to each module, according to the second embodiment of the present invention, as shown in fig. 3, specifically including the following steps:
s2071, extracting class definition information in the module aiming at each module in the module array set.
Specifically, since a module may have multiple classes, the class definition information of all classes and test classes in the module is extracted for each module in the module array set.
And S2072, replacing variable information in the preset character string template according to the class definition information.
Specifically, the variable information in the preset character string template is replaced according to the declarations of the data members and the function members in the class definition information and the basic type information of the data, so that the replaced preset character string template contains parameter information which can be used for defining the corresponding class.
And S2073, filling the class name, the class package name, the test class name and the test class package name in the preset character string template according to the class definition information.
Specifically, since the class necessarily includes the corresponding class name and the storage path thereof during definition, and the package may include the class built therein, the storage path of the class may be determined according to the class package name, the class name and the class package name included therein may be extracted according to the class definition information, the test class name and the test class package name of the test class may be extracted, and the extracted class name, class package name, test class name, and test class package name may be filled in corresponding positions in the preset character string template.
Illustratively, the filling of the class name and the class package name for the class can be realized by the following code fragments:
$this->fill_class_name($test_class,$class_name_matches);
$test_class[‘obj_name’]=lcfirst($test_class[‘c_name’]);
$test_class[‘test_c_name’]=$test_class[‘c_name’].’Test’;
$test_class[‘full_test_c_name’]=’/’.$test_class[‘c_path’].’/’.$test_class[‘test_c_name’];
//for test class
$test_class[‘content’]=str_replace(‘{obj_name}’,$test_class[‘obj_name’],$test_class[‘content’]);
……
$test_class[‘content’]=str_replace(‘{test_class_name}’,$test_class[‘test_c_name’],$test_class[‘content’]);
it should be clear that the above codes are only exemplary implementation codes provided by the embodiments of the present invention, and the present invention does not limit the specific implementation manner.
And S2074, determining the replaced and filled preset character string template as a fixed character string corresponding to the module.
S208, traversing all interfaces in the modules aiming at each module, determining a class method array set corresponding to the module, and converting the class method array set into a corresponding method character string.
The method character string comprises a class method character string and a test class method character string.
In this embodiment, the class method array set can be specifically understood as an array set containing interface element information of all interfaces in the module.
Specifically, for each module in the module array set, because a plurality of interfaces exist in each module, traversal is performed on all interfaces in one module, an interface element corresponding to each interface is extracted, and a class method array set corresponding to all interfaces in the module is generated according to various kinds of field information corresponding to each interface element. And converting the class method array set into corresponding class method character strings and test class method character strings according to the specific type corresponding to the field information in the class method array set and the preset definition format of the corresponding used development language.
Further, fig. 4 is a flowchart illustrating a process of traversing all interfaces in a module, determining a class method array set corresponding to the module, and converting the class method array set into a corresponding method character string according to a second embodiment of the present invention, as shown in fig. 4, specifically including the following steps:
s2081, determining an initialization interface element array corresponding to the module according to the interface element type in the module.
In the present embodiment, the interface element type may be specifically understood as a field type for defining an interface. Initializing an array of interface elements may specifically be understood as an array having a predetermined field format for recording interface elements of an interface in a module, wherein each field in the array may be replaced by an interface element of the same type as its interface element in the interface.
For example, when the interface in the module needs to be traversed, the corresponding interface element type may be determined according to the interface type existing in the module, and then an initialized interface element array corresponding to the interface element type is adaptively initialized to perform normalized extraction on the interface element field of each interface in the module. Further, the fields that may be included in the initialization interface element array may be mainly id, name, return _ type, http _ method, httpd _ url, http _ url, params, doc _ name, doc _ param, doc _ return. It should be clear that the interface element type of each field in the initialized interface element array may be adaptively set according to actual situations, which is not limited in the embodiment of the present invention.
S2082, traversing all the interfaces in the module, assigning the initialized interface element array through the interface elements extracted from each interface, and determining the interface element array corresponding to each interface.
Specifically, all interfaces in the module are traversed, fields of different interface element types in the interface elements of each interface are extracted, the fields are correspondingly assigned to fields of the same type as the interface elements in the initialized interface element array, and the initialized interface element array after the fields are assigned and the interface element array corresponding to each interface.
For example, when each interface in the module is processed, the interface ID, the name of the software development kit method, the method return type, the request mode, the request address variable, and the request parameter of the interface, as well as the description name in the comment, the comment parameter list in the comment, and the return type in the comment, may be respectively assigned to corresponding fields in the initialized interface element array.
S2083, determining the set of each interface element array as a class method array set, and converting the class method array set into a class method character string and a test class method character string according to the corresponding development language definition format.
Specifically, interface element arrays corresponding to each interface are sequentially stored in the same set, a set containing the interface element arrays corresponding to all the interfaces of the module is determined as a class method array set, corresponding method codes are constructed according to the interface elements stored in the class method array set by developing a required development language definition format, and the class method array set is converted into corresponding class method character strings and test method character strings according to different purposes of required classes.
Illustratively, converting the corresponding method string according to the class method array set can be realized by the following code segments:
Figure BDA0003805946750000171
it should be clear that the above codes are only exemplary implementation codes provided by the embodiments of the present invention, and the present invention does not limit the specific implementation manner.
S209, aiming at each module, creating a corresponding class directory and a corresponding test class directory according to the class package name and the test class package name corresponding to the module.
Specifically, since the package may include a plurality of classes and the package name includes a path of the package, the class directory stored in the corresponding package may be determined according to the class package name corresponding to each module, so as to specify a storage location of the class code generated after the code conversion is performed on the interfaces corresponding to each class in the module, and the test class directory stored in the corresponding package may be determined according to the test class package name corresponding to the module, so as to specify a storage location of the test class code generated after the code conversion is performed on the interfaces corresponding to each test type in the module.
S210, splicing the fixed character strings with the same class name with the class method character strings, supplementing class ending character strings, and determining a complete class code corresponding to the class name.
In this embodiment, the ending character string may be specifically understood as a character string which is preset, corresponds to the development language definition format, and has a fixed form for ending the current program.
Specifically, for a fixed character string and a class method character string having the same class name, it may be considered that they belong to the same subclass under one interface major class, and a code obtained after splicing may be used to implement a method corresponding to the class.
S211, splicing the fixed character strings with the same test class name with the test class method character strings, supplementing the test class ending character strings, and determining a complete test class code corresponding to the test class name.
Specifically, for a fixed character string and a test method character string having the same test class name, it may be considered that they belong to the same subclass under one interface broad class, and a code obtained after splicing may be used to test a method corresponding to the test class.
S212, writing the complete class codes into the corresponding class directories according to the corresponding packet paths, and writing the complete test class codes into the corresponding test class directories according to the corresponding packet paths.
Specifically, the complete class code corresponding to each module is written into the class directory constructed according to the corresponding class package name according to the package path corresponding to the class thereof, and the complete test class code corresponding to each module is written into the test class directory constructed according to the corresponding test class package name according to the package path corresponding to the test class thereof.
S213, naming the file composed of all the complete class codes written in the class directory by the corresponding class name, naming the file composed of all the complete test class codes written in the test class directory by the corresponding test class name, determining the suffix of each file as the language code suffix corresponding to the file, and determining each file as the software development kit code corresponding to the target interface document library.
Specifically, when each complete class code is written into a class directory to form a corresponding file, and each complete test class code is written into a test class directory to form a corresponding file, the file is named as a class name or a test class name containing the code, a suffix of the file is named as a development language code name containing the code, such as java, and the like, and each file obtained after all modules and interfaces complete code writing is determined as a software development kit code corresponding to a target interface document library.
Illustratively, writing each complete class code into the corresponding class directory and generating the corresponding file may be implemented by the following code fragments:
Figure BDA0003805946750000191
it should be clear that the above codes are only exemplary implementation codes provided by the embodiments of the present invention, and the present invention does not limit the specific implementation manner.
The technical scheme of the embodiment of the invention comprises the steps of firstly analyzing a table structure in an online interface document system database before at least one target interface document library is obtained to generate a preset format conversion program for converting the data format of the interface document library, converting the at least one target interface document library into a target object numbered notation file according to the preset format conversion program, carrying out traversal on each module in a module array set, carrying out replacement filling on a preset character string template according to the definition object of the module to determine a fixed character string corresponding to the module, extracting interface element information of the interface through an initialized interface element array when traversing all interfaces in each module, generating a corresponding class method array set, and further converting the interface element information into a class method character string and a test class method character string corresponding to the module according to a corresponding development language definition format. And then constructing a corresponding class directory and a corresponding test class directory according to the class name, the class package name, the test class name and the test class package name contained in each module fixed character string, splicing the spliced fixed character string and the method character string, supplementing completely, sequentially writing the spliced fixed character string and the method character string into the class directory or the test class directory corresponding to the spliced fixed character string, and determining a finally generated file as a software development package code corresponding to all interfaces in the target interface document library. After the interface stored in the online interface document system database is modified, the software development kit code can be automatically and synchronously updated, the repeated operation of calling and packaging the interface in the generation process of the software development kit code does not need to be manually participated, the development cost is reduced, the development efficiency is improved, and the development time is saved.
EXAMPLE III
Fig. 5 is a schematic structural diagram of a software development kit code generation apparatus according to a third embodiment of the present invention, where the software development kit code generation apparatus includes: a file conversion module 31, an array set construction module 32, a character string determination module 33 and a code generation module 34.
The file conversion module 31 is configured to obtain at least one target interface document library, and convert each target interface document library into a corresponding target object numbered musical notation file through a preset format conversion program; an array set constructing module 32, configured to construct a module array set corresponding to each target object numbered musical notation file; the target object numbered musical notation file comprises at least one module; the character string determining module 33 is configured to traverse each module in the module array set, and determine a fixed character string and a method character string corresponding to each module; and the code generation module 34 is configured to splice the fixed character strings and the method character strings corresponding to the modules for each module, write the spliced fixed character strings and method character strings into a file according to a package path corresponding to the module, and generate a software development package code corresponding to the target interface document library.
According to the technical scheme of the embodiment of the invention, after the API is modified online, a target interface document library corresponding to the modified API and needing to be generated by software development kit SDK codes is determined, the target interface document library is further converted into a corresponding target object numbered notation file through a preset format conversion program, a module array set corresponding to the target object numbered notation file is constructed, so that each module is traversed to determine fixed character strings which are relatively fixed and unchangeable in each module and method character strings which correspond to changed APIs and are contained in each module, the fixed character strings and the method character strings are combined and written into the file according to rules, the software development kit codes corresponding to the target interface document library are generated, the problem that interface calling and packaging can be modified only in a handwriting mode after the existing online API is modified is solved, the software development kit codes are divided into two parts of fixed character strings which are not easy to change and method character strings which are easy to change when the SDK codes are generated, repeated labor work in the SDK code generation process is reduced, the manual participation degree in the SDK code generation is reduced, the development cost is reduced, the development time is saved, and the development efficiency is improved.
Optionally, the software development kit code generating apparatus further includes:
the program generation module is used for analyzing the table structure of the online interface document system database before acquiring at least one target interface document library; determining the position information and the associated information of the interface definition information in an online interface document system database according to the analysis result; constructing a preset format conversion program according to the position information, the association information and the file format of the numbered musical notation of the predefined object; the online interface document system database comprises a plurality of online interface document libraries.
Optionally, the array set building module 32 includes:
and the file conversion unit is used for analyzing the object numbered musical notation character strings in the numbered musical notation files of the target objects and determining the target objects corresponding to the numbered musical notation files of the target objects.
And the set generating unit is used for extracting the modules in the target objects and combining the modules to generate a module array set.
Optionally, the character string determining module 33 includes:
and the fixed character string determining unit is used for traversing each module in the module array set, replacing and filling the preset character string template according to the definition object of each module, and determining the fixed character string corresponding to each module.
The method character string determining unit is used for traversing all interfaces in the modules aiming at each module, determining a class method array set corresponding to the module and converting the class method array set into a corresponding method character string; the method character string comprises a class method character string and a test class method character string.
Optionally, the fixed character string determining unit is specifically configured to: extracting class definition information in the module aiming at each module in the module array set; replacing variable information in a preset character string template according to the class definition information; filling a class name, a class package name, a test class name and a test class package name in a preset character string template according to the class definition information; and determining the replaced and filled preset character string template as a fixed character string corresponding to the module.
Optionally, the method string determining unit is specifically configured to: determining an initialized interface element array corresponding to the module according to the interface element type in the module; traversing all interfaces in the module, assigning the initialized interface element array through the interface elements extracted from each interface, and determining the interface element array corresponding to each interface; and determining the set of each interface element array as a class method array set, and converting the class method array set into a class method character string and a test class method character string according to the corresponding development language definition format.
Optionally, the code generating module 34 includes:
and the catalog generation unit is used for creating a corresponding class catalog and a corresponding test class catalog according to the class package name and the test class package name corresponding to the module aiming at each module.
And the class code determining unit is used for splicing the fixed character strings with the same class name with the class method character strings, supplementing the class ending character strings and determining the complete class code corresponding to the class name.
And the test class code determining unit is used for splicing the fixed character string with the same test class name with the test class method character string, supplementing the test class ending character string and determining a complete test class code corresponding to the test class name.
And the code writing unit is used for writing the complete class codes into the corresponding class directories according to the corresponding packet paths and writing the complete test class codes into the corresponding test class directories according to the corresponding packet paths.
And the code generation unit is used for naming the file formed by each complete class code written in the class directory by a corresponding class name, naming the file formed by each complete test class code written in the test class directory by a corresponding test class name, determining a suffix of each file as a language code suffix corresponding to the file, and determining each file as a software development kit code corresponding to the target interface document library.
The software development kit code generation device provided by the embodiment of the invention can execute the software development kit code generation method provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method.
Example four
Fig. 6 is a schematic structural diagram of a software development kit code generation apparatus according to a fourth embodiment of the present invention. The software development kit code generation device includes: a processor 40, a storage device 41, a display 42, an input device 43, and an output device 44. The number of the processors 40 in the software development kit code generation device may be one or more, and one processor 40 is taken as an example in fig. 6. The number of the storage devices 41 in the software development kit code generation apparatus may be one or more, and one storage device 41 is illustrated in fig. 6. The processor 40, the storage device 41, the display screen 42, the input device 43 and the output device 44 of the software development kit code generation apparatus may be connected by a bus or other means, and fig. 6 illustrates an example of a connection by a bus. In an embodiment, the software development kit code generation device may be a computer, a notebook, or a smart tablet, etc.
The storage device 41 is a computer-readable storage medium, and can be used for storing software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the software development kit code generation device according to any embodiment of the present application (for example, the file conversion module 31, the array set construction module 32, the character string determination module 33, and the code generation module 34). The storage device 41 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to use of the device, and the like. Further, the storage device 41 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, storage 41 may further include memory located remotely from processor 40, which may be connected to the device over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The display screen 42 may be a touch-enabled display screen 42, which may be a capacitive screen, an electromagnetic screen, or an infrared screen. Generally speaking, the display screen 42 is used for displaying data according to instructions of the processor 40, and is also used for receiving touch operations applied to the display screen 42 and sending corresponding signals to the processor 40 or other devices.
The input means 43 may be used for receiving input numeric or character information and generating key signal inputs related to user settings and function controls of the presentation apparatus, and may also be a camera for acquiring images and a sound pickup apparatus for acquiring audio data. The output device 44 may include an audio device such as a speaker. It should be noted that the specific composition of the input device 43 and the output device 44 can be set according to actual conditions.
The processor 40 executes various functional applications of the device and data processing by running software programs, instructions, and modules stored in the storage device 41, that is, implements the software development kit code generation method described above.
The computer device provided above can be used to execute the software development kit code generation method provided in any of the above embodiments, and has corresponding functions and advantages.
EXAMPLE five
An embodiment of the present invention further provides a storage medium containing computer-executable instructions, where the computer-executable instructions, when executed by a computer processor, are configured to perform a method for generating software development kit code, where the method includes:
acquiring at least one target interface document library, and converting each target interface document library into a corresponding target object numbered musical notation file through a preset format conversion program;
constructing a module array set corresponding to each target object numbered musical notation file; the target object numbered musical notation file comprises at least one module;
traversing each module in the module array set, and determining a fixed character string and a method character string corresponding to each module;
and for each module, splicing the fixed character strings and the method character strings corresponding to the modules, writing the fixed character strings and the method character strings into a file according to the package path corresponding to the module, and generating a software development package code corresponding to a target interface document library.
Of course, the storage medium containing the computer-executable instructions provided by the embodiments of the present invention is not limited to the method operations described above, and may also perform related operations in the software development kit code generation method provided by any embodiment of the present invention.
From the above description of the embodiments, it is obvious for those skilled in the art that the present invention can be implemented by software and necessary general hardware, and certainly, can also be implemented by hardware, but the former is a better embodiment in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which can be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device) to execute the methods according to the embodiments of the present invention.
It should be noted that, in the embodiment of the search apparatus, each included unit and each included module are merely divided according to functional logic, but are not limited to the above division, as long as corresponding functions can be implemented; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (10)

1. A method for generating software development kit codes, comprising:
acquiring at least one target interface document library, and converting each target interface document library into a corresponding target object numbered musical notation file through a preset format conversion program;
constructing a module array set corresponding to each target object numbered musical notation file; wherein, the target object numbered musical notation file comprises at least one module;
traversing each module in the module array set, and determining a fixed character string and a method character string corresponding to each module;
and for each module, splicing the fixed character strings and the method character strings corresponding to the modules, writing the fixed character strings and the method character strings into a file according to the package path corresponding to the module, and generating a software development package code corresponding to the target interface document library.
2. The method according to claim 1, further comprising, prior to said obtaining at least one target interface document repository:
analyzing a table structure of an online interface document system database;
determining the position information and the associated information of the interface definition information in the online interface document system database according to the analysis result;
constructing a preset format conversion program according to the position information, the association information and the file format of the numbered musical notation of the predefined object;
the online interface document system database comprises a plurality of online interface document libraries.
3. The method of claim 1, wherein said constructing a set of module arrays corresponding to each of said target object profile files comprises:
analyzing the object numbered musical notation character strings in each target object numbered musical notation file, and determining a target object corresponding to each target object numbered musical notation file;
and extracting modules in each target object, and combining the modules to generate a module array set.
4. The method of claim 1, wherein traversing each module in the module array set to determine a fixed string and a method string corresponding to each module comprises:
traversing each module in the module array set, replacing and filling a preset character string template according to a definition object of each module, and determining a fixed character string corresponding to each module;
traversing all interfaces in each module, determining a class method array set corresponding to the module, and converting the class method array set into a corresponding method character string;
the method character string comprises a class method character string and a test class method character string.
5. The method of claim 4, wherein traversing each module in the module array set, performing replacement filling on a preset character string template according to a definition object of each module, and determining a fixed character string corresponding to each module comprises:
extracting class definition information in each module in the module array set;
replacing variable information in a preset character string template according to the class definition information;
filling the class name, the class package name, the test class name and the test class package name in the preset character string template according to the class definition information;
and determining the replaced and filled preset character string template as a fixed character string corresponding to the module.
6. The method of claim 4, wherein traversing all interfaces in the module, determining a set of class method arrays corresponding to the module, and converting the set of class method arrays into corresponding method strings comprises:
determining an initialized interface element array corresponding to the module according to the interface element type in the module;
traversing all interfaces in the module, assigning the initialized interface element array through the interface elements extracted by each interface, and determining the interface element array corresponding to each interface;
and determining the set of each interface element array as a class method array set, and converting the class method array set into a class method character string and a test class method character string according to the corresponding development language definition format.
7. The method according to claim 5, wherein the generating, for each module, a software development kit code corresponding to the target interface document library by splicing the fixed character string and the method character string corresponding to the module and writing the spliced fixed character string and method character string into a file according to a package path corresponding to the module comprises:
aiming at each module, creating a corresponding class directory and a test class directory according to the class package name corresponding to the module and the test class package name;
splicing a fixed character string with the same class name with a class method character string, supplementing a class ending character string, and determining a complete class code corresponding to the class name;
splicing a fixed character string with the same test class name with a test class method character string, supplementing a test class ending character string, and determining a complete test class code corresponding to the test class name;
writing the complete class codes into corresponding class directories according to corresponding packet paths, and writing the complete test class codes into corresponding test class directories according to corresponding packet paths;
naming the file formed by each complete class code written in the class directory by a corresponding class name, naming the file formed by each complete test class code written in the test class directory by a corresponding test class name, determining the suffix of each file as the language code suffix corresponding to the file, and determining each file as the software development kit code corresponding to the target interface document library.
8. A software development kit code generation apparatus, comprising:
the file conversion module is used for acquiring at least one target interface document library and converting each target interface document library into a corresponding target object numbered musical notation file through a preset format conversion program;
the array set building module is used for building a module array set corresponding to each target object numbered musical notation file; wherein, the target object numbered musical notation file comprises at least one module;
the character string determining module is used for traversing each module in the module array set and determining a fixed character string and a method character string corresponding to each module;
and the code generation module is used for splicing the fixed character strings and the method character strings corresponding to the modules aiming at each module, writing the fixed character strings and the method character strings into a file according to the package path corresponding to the modules and generating the software development package codes corresponding to the target interface document library.
9. A software development kit code generation device, characterized by comprising: a storage device and one or more processors;
the storage device to store one or more programs;
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the software development kit code generation method of any of claims 1-7.
10. A storage medium containing computer-executable instructions for performing the software development kit code generation method of any one of claims 1-7 when executed by a computer processor.
CN202210997446.0A 2022-08-19 2022-08-19 Software development kit code generation method, device, equipment and storage medium Pending CN115291851A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210997446.0A CN115291851A (en) 2022-08-19 2022-08-19 Software development kit code generation method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210997446.0A CN115291851A (en) 2022-08-19 2022-08-19 Software development kit code generation method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115291851A true CN115291851A (en) 2022-11-04

Family

ID=83830427

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210997446.0A Pending CN115291851A (en) 2022-08-19 2022-08-19 Software development kit code generation method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115291851A (en)

Similar Documents

Publication Publication Date Title
KR101908162B1 (en) Live browser tooling in an integrated development environment
CN111427561A (en) Service code generation method and device, computer equipment and storage medium
CN112100550A (en) Page construction method and device
CN110580189A (en) method and device for generating front-end page, computer equipment and storage medium
CN115202626A (en) Low-code front-end development method supporting multi-technology stack components
CN114201615B (en) Scientific research data change review method and server based on data snapshot
CN116244387A (en) Entity relationship construction method, device, electronic equipment and storage medium
CN113127776A (en) Breadcrumb path generation method and device and terminal equipment
CN113419711A (en) Page guiding method and device, electronic equipment and storage medium
CN112783482A (en) Visual form generation method, device, equipment and storage medium
CN110275712B (en) Text replacement method, device and equipment
CN117389538A (en) Page component content development method, device, equipment and storage medium
CN116028062A (en) Target code generation method, NPU instruction display method and device
CN113642295B (en) Page typesetting method, device and computer program product
CN115291851A (en) Software development kit code generation method, device, equipment and storage medium
CN114625372A (en) Automatic component compiling method and device, computer equipment and storage medium
JP2019133534A (en) Merging method, merging device, and merging program
CN114968235A (en) Page form generation method and device, computer equipment and storage medium
CN114637499A (en) Visualization component processing method, device, equipment and medium
CN111881220A (en) Data operation method and device under list storage, electronic equipment and storage medium
CN112130860A (en) JSON object analysis method and device, electronic device and storage medium
Mou et al. Visual orchestration and autonomous execution of distributed and heterogeneous computational biology pipelines
CN112905164A (en) Project code processing method and device
CN117112021B (en) Route configuration generation method, device, equipment and computer readable storage medium
CN118210809B (en) Object definition method, system, equipment and medium based on ER information

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