CN110389899A - Detect square law device, medium and the equipment of the API data type of JS program - Google Patents

Detect square law device, medium and the equipment of the API data type of JS program Download PDF

Info

Publication number
CN110389899A
CN110389899A CN201910543771.8A CN201910543771A CN110389899A CN 110389899 A CN110389899 A CN 110389899A CN 201910543771 A CN201910543771 A CN 201910543771A CN 110389899 A CN110389899 A CN 110389899A
Authority
CN
China
Prior art keywords
type
data
api
detection
ids
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.)
Granted
Application number
CN201910543771.8A
Other languages
Chinese (zh)
Other versions
CN110389899B (en
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 ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network 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 ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN201910543771.8A priority Critical patent/CN110389899B/en
Publication of CN110389899A publication Critical patent/CN110389899A/en
Application granted granted Critical
Publication of CN110389899B publication Critical patent/CN110389899B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3624Software debugging by performing operations on the source code, e.g. via a compiler
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing

Abstract

Present disclose provides method, apparatus, medium and the equipment of a kind of API data type for detecting JS program, this method comprises: parsing IDS file obtains the IDS data type of API request data and returned data;It is JS data type by the IDS DATATYPES TO;Type detection function is generated according to the JS data type;The type detection function is called to carry out type detection to the request data and/or returned data in the bank code of API.The JS type detection code that the disclosure generates can help developer to find not meeting the data of desired type in time, can effectively promote the joint debugging efficiency of API and improve the code quality of JS.

Description

Detect square law device, medium and the equipment of the API data type of JS program
Technical field
This disclosure relates to field of computer technology, in particular to a kind of detection JS program based on IDS file Method, apparatus, medium and the electronic equipment of API data type.
Background technique
JavaScript (abbreviation JS) is a kind of interpreted languages, not traditional compilation process, therefore can not run Before know mistake in JS program.In addition, JS is a kind of weak type language again, when defining JS variable, statement variable is not needed Type, different types of variable can mutual assignment, therefore, JS does not have type detection ability.If developer is in JS program It is passed to the variable for not meeting desired type, JS program can't report an error when running, and there will not be any prompt, potential Bug It is difficult to be found.In the prior art, some code specification detection instruments, such as Eslint are developed.These tools can help Developer has found some Bug, for example directly uses undefined variable, but can not detect the legitimacy of types of variables.
TypeScript (abbreviation TS) is the superset of JS, and developer needs the type of specifying variable when writing TS program.TS The legitimacy of compiler meeting detection type, and TS code compilation at JS code.TS, which solves JS, not can be carried out type detection Problem, is effectively promoted the quality of code, and use is more and more extensive.But TS will increase many learning costs and exploitation dimension Protect cost.In addition, TS uses static types to detect, regime type problem can not be found.For example, TS can not detect API Call whether the type of the data returned meets expection.
In progress (Application Programming Interface, application programming interface) API exploitation, Developer generally can first write according to certain IDS (Interface Description Specification, interface definition standard) Interface document, such as OAS (OpenAPI Specification, open interface specification), Thrift IDL (Interface Description Language, Interface Definition Language) and Protocol Buffers Language.These IDS files can be with For generating code library.But existing tool is according to the JS code library that IDS is generated that there is no the abilities of type detection.For The case where generating RPC (Remote Procedure Call, remote procedure call) API code library, if developer passes to API Enter or return one and IDS defines the data of Type-Inconsistencies, data can be smoothly serialized, meeting when unserializing It obtains not meeting expected data or dishing out parsing exception.For generating HTTP (HyperText Transfer Protocol, hypertext transfer protocol) API code library the case where, program will not dish out any exception.Thus, it is found that or positioning The cost that the data that API is passed to or returns do not meet the problem of IDS defines type is relatively high, is unfavorable for promoting the joint debugging effect of API Rate and the code quality for improving JS.
Disclosure
A kind of method of the API data type for being designed to provide detection JS program based on IDS file of the disclosure, dress It sets, medium and electronic equipment, is able to solve at least one technical problem mentioned above.Concrete scheme is as follows:
According to the specific embodiment of the disclosure, in a first aspect, the disclosure provides a kind of detection JS based on IDS file The method of the API data type of program, comprising:
Parsing IDS file obtains the IDS data type of API request data and returned data;
It is JS data type by the IDS DATATYPES TO;
Type detection function is generated according to the JS data type;
The type detection function is called to carry out class to the request data and/or returned data in the bank code of API Type detection.
It is optionally, described that type detection function is generated according to the JS data type, comprising:
General detection function and special detection function are generated according to the JS data type.
Optionally, described to call the type detection function to the request data and/or return in the bank code of API Data carry out type detection, comprising:
For API Calls side, the JS type detection function of generation is before request data is sent out or after returned data receives The type of data is detected;
For the provider of API, the JS type detection function of generation is after request data receives or returned data is sent out The preceding type to data detects.
Optionally, the parsing IDS file obtains the IDS data type of API request data and returned data, comprising:
When the IDS file be json format when, call JS built in analytical function parsing, obtain API request data and The IDS data type of returned data;And/or
When the IDS file is Thrift IDL or Protocol Buffers Language format, it is parsed into abstract Syntax tree obtains the IDS data type of API request data and returned data.
Optionally, described to call the type detection function to the request data and/or return in the bank code of API Data carry out type detection, comprising:
The general detection function includes generic function, detects the request data by the generic function and/or returns Return whether data are Number, String, Boolean, Array or Object type;And/or
The general detection function includes recursive function, and the subitem of Array and Object is checked by the recursive function Type.
Optionally, described to call the type detection function to the request data and/or return in the bank code of API Data carry out type detection, comprising:
The special project detection function calls the general detection function to detect the request data and/or returned data type It whether is " Object " type;
Each field of detection " Container " correspond to the type of attribute value, when the type of field be " Number ", When " String " or " Boolean ", common detection function is called to be detected;When field type be " Array " or When " Object ", recursive detection function is called to be detected;When the type of field is " Object ", the special detection is called Function is detected.
It is optionally, described that special detection function is generated according to the JS data type, comprising:
By the type package for entering ginseng and return value of " API " type at " Container " type, generate corresponding special Item detection function.
Optionally, further includes:
Whether meet expection by the type of request data described in the type detection function check and/or returned data;
Exception information is provided if not meeting and being expected.
According to the specific embodiment of the disclosure, second aspect, the disclosure provides a kind of detection JS based on IDS file The installation method of the API data type of program, comprising:
Resolution unit obtains the IDS data type of API request data and returned data for parsing IDS file;
Map unit, for being JS data type by the IDS DATATYPES TO;
Generation unit, for generating type detection function according to the JS data type;
Detection unit, for calling the type detection function in the bank code of API to the request data and/or returning It returns data and carries out type detection.
According to the specific embodiment of the disclosure, the third aspect, the disclosure provides a kind of computer readable storage medium, On be stored with computer program, when described program is executed by processor realize as above described in any item methods.
According to the specific embodiment of the disclosure, fourth aspect, the disclosure provides a kind of electronic equipment, comprising: one or Multiple processors;Storage device, for storing one or more programs, when one or more of programs are by one or more When a processor executes, so that one or more of processors realize as above described in any item methods.
The above scheme of the embodiment of the present disclosure compared with prior art, at least has the advantages that the disclosure passes through A kind of method of the API data type of detection JS program based on IDS file is provided, parsing IDS file first obtains API request The IDS type of data and returned data, and it is mapped as JS data type, the generation of type detection is then generated according to JS data type Code finally calls corresponding type detection function to carry out type detection to request data or returned data in the bank code of API. The JS type detection code of generation can help developer to find not meeting the data of desired type in time, can effectively be promoted The joint debugging efficiency of API and the code quality for improving JS.The method that the disclosure proposes is suitable for any environment for supporting JS, such as clear Look at device, Node.js, small routine and WebView.
Detailed description of the invention
The drawings herein are incorporated into the specification and forms part of this specification, and shows the implementation for meeting the disclosure Example, and together with specification for explaining the principles of this disclosure.It should be evident that the accompanying drawings in the following description is only the disclosure Some embodiments for those of ordinary skill in the art without creative efforts, can also basis These attached drawings obtain other attached drawings.In the accompanying drawings:
Fig. 1 shows the side of the API data type of the detection JS program based on IDS file according to the embodiment of the present disclosure The flow chart of method;
Fig. 2 shows the dresses according to the API data type of the detection JS program based on IDS file of the embodiment of the present disclosure The block diagram set;
Fig. 3 shows electronic equipment attachment structure schematic diagram according to an embodiment of the present disclosure.
Specific embodiment
In order to keep the purposes, technical schemes and advantages of the disclosure clearer, below in conjunction with attached drawing to the disclosure make into It is described in detail to one step, it is clear that described embodiment is only disclosure a part of the embodiment, rather than whole implementation Example.It is obtained by those of ordinary skill in the art without making creative efforts based on the embodiment in the disclosure All other embodiment belongs to the range of disclosure protection.
The term used in the embodiments of the present disclosure is only to be not intended to be limiting merely for for the purpose of describing particular embodiments The disclosure.In the embodiment of the present disclosure and the "an" of singular used in the attached claims, " described " and "the" It is also intended to including most forms, unless the context clearly indicates other meaning, " a variety of " generally comprise at least two.
It should be appreciated that term "and/or" used herein is only a kind of incidence relation for describing affiliated partner, indicate There may be three kinds of relationships, for example, A and/or B, can indicate: individualism A, exist simultaneously A and B, individualism B these three Situation.In addition, character "/" herein, typicallys represent the relationship that forward-backward correlation object is a kind of "or".
It will be appreciated that though in the embodiments of the present disclosure so-and-so may be described using term first, second, third, etc. Certain, but these certain so-and-so should not necessarily be limited by these terms.These terms are only used to that so-and-so distinguishes by certain.For example, not departing from this In the case where open scope of embodiments, first certain so-and-so can also be referred to as second certain so-and-so, and similarly, second certain so-and-so can also To be referred to as first certain so-and-so.
Depending on context, word as used in this " if ", " if " can be construed to " ... when " or " when ... " or " in response to determination " or " in response to detection ".Similarly, context is depended on, phrase " if it is determined that " or " such as Fruit detection (condition or event of statement) " can be construed to " when determining " or " in response to determination " or " when detection (statement Condition or event) when " or " in response to detection (condition or event of statement) ".
It should also be noted that, the terms "include", "comprise" or its any other variant are intended to nonexcludability Include, so that commodity or device including a series of elements not only include those elements, but also including not clear The other element listed, or further include for this commodity or the intrinsic element of device.In the feelings not limited more Under condition, the element that is limited by sentence "including a ...", it is not excluded that in the commodity or device for including the element also There are other identical elements.
Relational language is explained as follows:
JavaScript (abbreviation JS) is a kind of interpreted languages, is a kind of literal translation formula scripting language, is a kind of dynamic class Type, weak type, the language based on prototype, built-in support type.Its interpreter is referred to as JavaScript engine, is browser A part, be widely used in the scripting language of client, be at HTML (under standard generalized markup language one application) earliest It is used on webpage, is used to increase dynamic function to html web page.
TypeScript (abbreviation TS) is the superset of JS, and developer needs the type of specifying variable when writing TS program.TS The legitimacy of compiler meeting detection type, and TS code compilation at JS code.
API (Application Programming Interface, application programming interface) is some fixed in advance The function of justice, it is therefore an objective to application program and the developer ability that one group of routine of access is able to based on certain software or hardware are provided, And it is not necessarily to access source code, or understand the details of internal work mechanism.
IDS (Interface Description Specification), interface definition standard, including OAS (OpenAPI Specification, open interface specification), Thrift IDL (Interface Description Language, Interface Definition Language) and Protocol Buffers Language, IDS file can be used to generate code library.
The alternative embodiment of the disclosure is described in detail with reference to the accompanying drawing.
Embodiment 1
When carrying out JS program development, developer generally will first negotiate API and write IDS file.IDS refers to interface definition rule Model, the specification that usually interface is completely described using structured language, such as Thrift IDL, Protocol Buffers Language and OAS.IDS file refers to according to certain IDS API definition write or description file.Then, developer Can be with relevant tool according to the corresponding API library code of IDS file generated, and carry out functional development and joint debugging.
As shown in Figure 1, the disclosure provides a kind of detection JS based on IDS file according to the specific embodiment of the disclosure The method of the API data type of program, including following method and step:
Step S102: parsing IDS file obtains the IDS data type of API request data and returned data.
Optionally, the parsing IDS file obtains the IDS data type of API request data and returned data, comprising:
When the IDS file be json format when, call JS built in analytical function parsing, obtain API request data and The IDS data type of returned data;And/or
When the IDS file is Thrift IDL or Protocol Buffers Language format, need to be parsed into AST (Abstract syntax code, abstract syntax tree), obtains the IDS data type of API request data and returned data.
Step S104: being JS data type by the IDS DATATYPES TO.
Wherein, OAS itself contains Type Map Information.Thrift IDL and Protocol Buffers Language The mapping relations of type and JS type are as follows:
Wherein, " Container " and " API " is not the type of JS, only with making marks.In addition, the not type in upper table, It does not detect.
Step S106: type detection function is generated according to the JS data type.
Optionally, described that type detection function is generated according to the JS data type, comprising: according to the JS data type Generate general detection function and special detection function.
Optionally, described that special detection function is generated according to the JS data type, comprising: " API " type is entered into ginseng Type package with return value generates corresponding special detection function at " Container " type.
Specifically, whether the type of the type detection function check data generated meets expection, dish out if not meeting It is abnormal.Type detection function is divided into two classes.One kind is general detection function, including detection data whether be Number, String, The generic function and recurrence of Boolean, Array and Object type check passing for the type of the subitem of Array and Object Return function.Another kind of is dedicated test function.Only " Container " type can generate corresponding dedicated test function.It is dedicated Detection function calls general detection function to detect whether the data are " Object " type first, then detects " Container " Each field correspond to the type of attribute value.When the type of field is " Number ", " String " or " Boolean ", call Common detection function is detected;When the type of field is " Array " or " Object ", recursive detection function is called to be examined It surveys, needs to be passed to all recurrence types with certain format;When the type of field is " Object ", call corresponding dedicated Detection function is detected.The type package for entering ginseng and return value of " API " type at " Container " type and life At corresponding special detection function.
In the code library of generation, each API type can have a corresponding api function.In api function, adjust With the type joined special detection function and detect incoming data is entered accordingly, return value special project detection function is called to detect returned data Type.The legitimacy of the type of incoming data and returned data can be detected.
Step S108: the type detection function is called in the bank code of API to the request data and/or returns to number According to progress type detection.
Optionally, described to call the type detection function to the request data and/or return in the bank code of API Data carry out type detection, comprising: for API Calls side, the JS type detection function of generation before request data is sent out or Returned data detects the type of data after receiving;For the provider of API, the JS type detection function of generation is being requested Data are received before rear or returned data is sent out and are detected to the type of data.
Optionally, described to call the type detection function to the request data and/or return in the bank code of API Data carry out type detection, comprising:
The general detection function includes generic function, detects the request data by the generic function and/or returns Return whether data are Number, String, Boolean, Array or Object type;And/or
The general detection function includes recursive function, and the subitem of Array and Object is checked by the recursive function Type.
Optionally, described to call the type detection function to the request data and/or return in the bank code of API Data carry out type detection, comprising:
The special project detection function calls the general detection function to detect the request data and/or returned data type It whether is " Object " type;
Each field of detection " Container " correspond to the type of attribute value, when the type of field be " Number ", When " String " or " Boolean ", common detection function is called to be detected;When field type be " Array " or When " Object ", recursive detection function is called to be detected;When the type of field is " Object ", the special detection is called Function is detected.
Specifically, detection process is as follows:
It can be seen that the legitimacy of data type can be effectively detected in the type detection code generated according to the present invention.
Optionally, further include step S110: by request data described in the type detection function check and/or returning to number According to type whether meet expection;Exception information is provided if not meeting and being expected.
The disclosure is parsed first by providing a kind of method of the API data type of detection JS program based on IDS file IDS file obtains the IDS type of API request data and returned data, and is mapped as JS data type, then according to JS data class Type generates the code of type detection, and corresponding type detection function is finally called in the bank code of API to request data or is returned It returns data and carries out type detection.The JS type detection code of generation can help developer to find not meeting desired type in time Data can effectively promote the joint debugging efficiency of API and improve the code quality of JS.The method that the disclosure proposes is suitable for any Hold the environment of JS, such as browser, Node.js, small routine and WebView.
Embodiment 2
The present embodiment is accepted embodiment 1 and is contained for realizing method and step as described in Example 1 based on identical title The explanation of justice is same as Example 1, has technical effect same as Example 1, details are not described herein again.
As shown in Fig. 2, developer generally will first negotiate API and write IDS file when carrying out JS program development.IDS refers to Interface definition standard, the specification that usually interface is completely described using structured language, such as Thrift IDL, Protocol Buffers Language and OAS.IDS file refers to according to certain IDS API definition write or description file. Then, developer can be with relevant tool according to the corresponding API library code of IDS file generated, and carries out functional development and joint debugging.
According to the specific embodiment of the disclosure, the disclosure provides a kind of API of detection JS program based on IDS file The device of data type, including resolution unit 202, map unit 204, generation unit 206, detection unit 208, judging unit 210。
Resolution unit 202: the IDS data type of API request data and returned data is obtained for parsing IDS file.
Optionally, resolution unit 202 is also used to:
When the IDS file be json format when, call JS built in analytical function parsing, obtain API request data and The IDS data type of returned data;And/or
When the IDS file is Thrift IDL or Protocol Buffers Language format, need to be parsed into AST (Abstract syntax code, abstract syntax tree), obtains the IDS data type of API request data and returned data.
Map unit 204: for being JS data type by the IDS DATATYPES TO.
Generation unit 206: for generating type detection function according to the JS data type.
Optionally, the generation unit 206 is also used to: generating general detection function and special project according to the JS data type Detection function.
Optionally, the generation unit 206 is also used to: by the type package for entering ginseng and return value of " API " type at one A " Container " type generates corresponding special detection function.
Specifically, whether the type of the type detection function check data generated meets expection, dish out if not meeting It is abnormal.Type detection function is divided into two classes.One kind is general detection function, including detection data whether be Number, String, The generic function and recurrence of Boolean, Array and Object type check passing for the type of the subitem of Array and Object Return function.Another kind of is dedicated test function.Only " Container " type can generate corresponding dedicated test function.It is dedicated Detection function calls general detection function to detect whether the data are " Object " type first, then detects " Container " Each field correspond to the type of attribute value.When the type of field is " Number ", " String " or " Boolean ", call Common detection function is detected;When the type of field is " Array " or " Object ", recursive detection function is called to be examined It surveys, needs to be passed to all recurrence types with certain format;When the type of field is " Object ", call corresponding dedicated Detection function is detected.The type package for entering ginseng and return value of " API " type at " Container " type and life At corresponding special detection function.
In the code library of generation, each API type can have a corresponding api function.In api function, adjust With the type joined special detection function and detect incoming data is entered accordingly, return value special project detection function is called to detect returned data Type.The legitimacy of the type of incoming data and returned data can be detected.
Detection unit 208: for called in the bank code of API the type detection function to the request data and/ Or returned data carries out type detection.
Optionally, the detection unit 208 is also used to: for API Calls side, the JS type detection function of generation is being asked It asks data to send out after preceding or returned data receives to detect the type of data;For the provider of API, the JS class of generation Type detection function after request data receives or returned data send out before the type of data is detected.
Optionally, the detection unit 208 is also used to: the general detection function includes generic function, by described general Pass function detects the request data and/or whether returned data is Number, String, Boolean, Array or Object Type;And/or
The general detection function includes recursive function, and the subitem of Array and Object is checked by the recursive function Type.
Optionally, the detection unit 208 is also used to: the special project detection function calls the general detection function detection Whether the request data and/or returned data type are " Object " type;
Each field of detection " Container " correspond to the type of attribute value, when the type of field be " Number ", When " String " or " Boolean ", common detection function is called to be detected;When field type be " Array " or When " Object ", recursive detection function is called to be detected;When the type of field is " Object ", the special detection is called Function is detected.
Optionally, further include judging unit 210: by request data described in the type detection function check and/or returning Whether the type for returning data meets expection;Exception information is provided if not meeting and being expected.
The disclosure is parsed first by providing a kind of device of the API data type of detection JS program based on IDS file IDS file obtains the IDS type of API request data and returned data, and is mapped as JS data type, then according to JS data class Type generates the code of type detection, and corresponding type detection function is finally called in the bank code of API to request data or is returned It returns data and carries out type detection.The JS type detection code of generation can help developer to find not meeting desired type in time Data can effectively promote the joint debugging efficiency of API and improve the code quality of JS.The method that the disclosure proposes is suitable for any Hold the environment of JS, such as browser, Node.js, small routine and WebView.
Embodiment 3
As shown in figure 3, the equipment is used for the detection JS program based on IDS file the present embodiment provides a kind of electronic equipment API data type, the electronic equipment, comprising: at least one processor;And at least one described processor communication The memory of connection;Wherein,
The memory is stored with the instruction that can be executed by one processor, and described instruction is by described at least one It manages device to execute, so that at least one described processor is able to carry out method and step described in embodiment as above.
Embodiment 4
The embodiment of the present disclosure provides a kind of nonvolatile computer storage media, and the computer storage medium is stored with Method and step described in embodiment as above can be performed in computer executable instructions, the computer executable instructions.
Embodiment 5
Below with reference to Fig. 3, it illustrates the structural schematic diagrams for the electronic equipment for being suitable for being used to realize the embodiment of the present disclosure.This Terminal device in open embodiment can include but is not limited to such as mobile phone, laptop, digit broadcasting receiver, PDA (personal digital assistant), PAD (tablet computer), PMP (portable media player), car-mounted terminal (such as vehicle mounted guidance Terminal) etc. mobile terminal and such as number TV, desktop computer etc. fixed terminal.Electronic equipment shown in Fig. 3 An only example, should not function to the embodiment of the present disclosure and use scope bring any restrictions.
As shown in figure 3, electronic equipment may include processing unit (such as central processing unit, graphics processor etc.) 301, Random access storage device can be loaded into according to the program being stored in read-only memory (ROM) 302 or from storage device 308 (RAM) program in 303 and execute various movements appropriate and processing.In RAM 303, it is also stored with electronic device institute The various programs and data needed.Processing unit 301, ROM 302 and RAM 303 are connected with each other by bus 306.Input/defeated (I/O) interface 306 is also connected to bus 306 out.
In general, following device can connect to I/O interface 306: including such as touch screen, touch tablet, keyboard, mouse, taking the photograph As the input unit 306 of head, microphone, accelerometer, gyroscope etc.;Including such as liquid crystal display (LCD), loudspeaker, vibration The output device 306 of dynamic device etc.;Storage device 308 including such as tape, hard disk etc.;And communication device 306.Communication dress It sets 306 and can permit electronic equipment and wirelessly or non-wirelessly communicated with other equipment to exchange data.Although Fig. 3, which is shown, to be had The electronic equipment of various devices, it should be understood that being not required for implementing or having all devices shown.It can be alternatively Implement or have more or fewer devices.
Particularly, in accordance with an embodiment of the present disclosure, it may be implemented as computer above with reference to the process of flow chart description Software program.For example, embodiment of the disclosure includes a kind of computer program product comprising be carried on computer-readable medium On computer program, which includes the program code for method shown in execution flow chart.In such reality It applies in example, which can be downloaded and installed by communication device 306 from above, or be pacified from storage device 308 Dress, or be mounted from ROM 302.When the computer program is executed by processing unit 301, the side of the embodiment of the present disclosure is executed The above-mentioned function of being limited in method.
It should be noted that the above-mentioned computer-readable medium of the disclosure can be computer-readable signal media or meter Calculation machine readable storage medium storing program for executing either the two any combination.Computer readable storage medium for example can be --- but not Be limited to --- electricity, magnetic, optical, electromagnetic, infrared ray or semiconductor system, device or device, or any above combination.Meter The more specific example of calculation machine readable storage medium storing program for executing can include but is not limited to: have the electrical connection, just of one or more conducting wires Taking formula computer disk, hard disk, random access storage device (RAM), read-only memory (ROM), erasable type may be programmed read-only storage Device (EPROM or flash memory), optical fiber, portable compact disc read-only memory (CD-ROM), light storage device, magnetic memory device, Or above-mentioned any appropriate combination.In the disclosure, computer readable storage medium can be it is any include or storage journey The tangible medium of sequence, the program can be commanded execution system, device or device use or in connection.And at this In open, computer-readable signal media may include in a base band or as the data-signal that carrier wave a part is propagated, In carry computer-readable program code.The data-signal of this propagation can take various forms, including but not limited to Electromagnetic signal, optical signal or above-mentioned any appropriate combination.Computer-readable signal media can also be computer-readable and deposit Any computer-readable medium other than storage media, the computer-readable signal media can send, propagate or transmit and be used for By the use of instruction execution system, device or device or program in connection.Include on computer-readable medium Program code can transmit with any suitable medium, including but not limited to: electric wire, optical cable, RF (radio frequency) etc. are above-mentioned Any appropriate combination.
Above-mentioned computer-readable medium can be included in above-mentioned electronic equipment;It is also possible to individualism, and not It is fitted into the electronic equipment.
The calculating of the operation for executing the disclosure can be write with one or more programming languages or combinations thereof Machine program code, above procedure design language include object oriented program language-such as Java, Smalltalk, C+ +, it further include conventional procedural programming language-such as " C " language or similar programming language.Program code can Fully to execute, partly execute on the user computer on the user computer, be executed as an independent software package, Part executes on the remote computer or executes on a remote computer or server completely on the user computer for part. In situations involving remote computers, remote computer can pass through any kind --- including local area network (LAN) or extensively Domain net (WAN)-be connected to subscriber computer, or, it may be connected to outer computer (such as provided using Internet service Quotient is connected by internet).
Flow chart and block diagram in attached drawing are illustrated according to the system of the various embodiments of the disclosure, method and computer journey The architecture, function and operation in the cards of sequence product.In this regard, each box in flowchart or block diagram can generation A part of one module, program segment or code of table, a part of the module, program segment or code include one or more use The executable instruction of the logic function as defined in realizing.It should also be noted that in some implementations as replacements, being marked in box The function of note can also occur in a different order than that indicated in the drawings.For example, two boxes succeedingly indicated are actually It can be basically executed in parallel, they can also be executed in the opposite order sometimes, and this depends on the function involved.Also it to infuse Meaning, the combination of each box in block diagram and or flow chart and the box in block diagram and or flow chart can be with holding The dedicated hardware based system of functions or operations as defined in row is realized, or can use specialized hardware and computer instruction Combination realize.
Being described in unit involved in the embodiment of the present disclosure can be realized by way of software, can also be by hard The mode of part is realized.Wherein, the title of unit does not constitute the restriction to the unit itself under certain conditions.

Claims (11)

1. a kind of method of the API data type of the detection JS program based on IDS file characterized by comprising
Parsing IDS file obtains the IDS data type of API request data and returned data;
It is JS data type by the IDS DATATYPES TO;
Type detection function is generated according to the JS data type;
The type detection function is called to carry out type inspection to the request data and/or returned data in the bank code of API It surveys.
2. the method as described in claim 1, which is characterized in that described to generate type detection letter according to the JS data type Number, comprising:
General detection function and special detection function are generated according to the JS data type.
3. the method as described in claim 1, which is characterized in that described to call the type detection letter in the bank code of API It is several that type detection is carried out to the request data and/or returned data, comprising:
For API Calls side, the JS type detection function of generation before request data is sent out or returned data receive after logarithm According to type detected;
For the provider of API, the JS type detection function of generation after request data receives or returned data send out before it is right The type of data is detected.
4. the method as described in claim 1, which is characterized in that the parsing IDS file obtains API request data and returns to number According to IDS data type, comprising:
When the IDS file is json format, the analytical function parsing built in JS is called, API request data and return are obtained The IDS data type of data;And/or
When the IDS file is Thrift IDL or Protocol Buffers Language format, it is parsed into abstract syntax Tree, obtains the IDS data type of API request data and returned data.
5. method according to claim 2, which is characterized in that described to call the type detection letter in the bank code of API It is several that type detection is carried out to the request data and/or returned data, comprising:
The general detection function includes generic function, detects the request data by the generic function and/or returns to number According to whether being Number, String, Boolean, Array or Object type;And/or
The general detection function includes recursive function, and the class of the subitem of Array and Object is checked by the recursive function Type.
6. method according to claim 2, which is characterized in that described to call the type detection letter in the bank code of API It is several that type detection is carried out to the request data and/or returned data, comprising:
The special project detection function calls whether the general detection function detects the request data and/or returned data type For " Object " type;
Each field of detection " Container " corresponds to the type of attribute value, when the type of field is " Number ", " String " Or when " Boolean ", common detection function is called to be detected;When the type of field is " Array " or " Object ", call Recursive detection function is detected;When the type of field is " Object ", the special detection function is called to be detected.
7. method according to claim 2, which is characterized in that described to generate special detection letter according to the JS data type Number, comprising:
By the type package for entering ginseng and return value of " API " type at " Container " type, corresponding special inspection is generated Survey function.
8. the method as described in claim 1, which is characterized in that further include:
Whether meet expection by the type of request data described in the type detection function check and/or returned data;
Exception information is provided if not meeting and being expected.
9. a kind of installation method of the API data type of the detection JS program based on IDS file characterized by comprising
Resolution unit obtains the IDS data type of API request data and returned data for parsing IDS file;
Map unit, for being JS data type by the IDS DATATYPES TO;
Generation unit, for generating type detection function according to the JS data type;
Detection unit, for calling the type detection function in the bank code of API to the request data and/or returning to number According to progress type detection.
10. a kind of computer readable storage medium, is stored thereon with computer program, which is characterized in that described program is processed Such as method described in any item of the claim 1 to 8 is realized when device executes.
11. a kind of electronic equipment characterized by comprising
One or more processors;
Storage device, for storing one or more programs, when one or more of programs are by one or more of processing When device executes, so that one or more of processors realize such as method described in any item of the claim 1 to 8.
CN201910543771.8A 2019-06-21 2019-06-21 Method and device for detecting API data type of JS program, medium and equipment Active CN110389899B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910543771.8A CN110389899B (en) 2019-06-21 2019-06-21 Method and device for detecting API data type of JS program, medium and equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910543771.8A CN110389899B (en) 2019-06-21 2019-06-21 Method and device for detecting API data type of JS program, medium and equipment

Publications (2)

Publication Number Publication Date
CN110389899A true CN110389899A (en) 2019-10-29
CN110389899B CN110389899B (en) 2023-12-19

Family

ID=68285751

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910543771.8A Active CN110389899B (en) 2019-06-21 2019-06-21 Method and device for detecting API data type of JS program, medium and equipment

Country Status (1)

Country Link
CN (1) CN110389899B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111708526A (en) * 2020-06-05 2020-09-25 苏州瑞泰信息技术有限公司 Novel API writing method
CN111736847A (en) * 2020-06-15 2020-10-02 北京奇艺世纪科技有限公司 Script language mapping method, electronic device and readable storage medium
CN111831275A (en) * 2020-07-14 2020-10-27 绿盟科技集团股份有限公司 Method, server, medium and computer equipment for arranging micro-scene script

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101515248A (en) * 2008-02-21 2009-08-26 国际商业机器公司 Tracking method and tracking system for object-oriented program
US20140310558A1 (en) * 2013-04-10 2014-10-16 International Business Machines Corporation Low- level checking of context-dependent expected results
CN106919509A (en) * 2017-03-09 2017-07-04 腾讯科技(深圳)有限公司 A kind of client generation method, device and electronic equipment

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101515248A (en) * 2008-02-21 2009-08-26 国际商业机器公司 Tracking method and tracking system for object-oriented program
US20140310558A1 (en) * 2013-04-10 2014-10-16 International Business Machines Corporation Low- level checking of context-dependent expected results
CN106919509A (en) * 2017-03-09 2017-07-04 腾讯科技(深圳)有限公司 A kind of client generation method, device and electronic equipment

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111708526A (en) * 2020-06-05 2020-09-25 苏州瑞泰信息技术有限公司 Novel API writing method
CN111708526B (en) * 2020-06-05 2024-03-01 苏州瑞泰信息技术有限公司 API writing method
CN111736847A (en) * 2020-06-15 2020-10-02 北京奇艺世纪科技有限公司 Script language mapping method, electronic device and readable storage medium
CN111736847B (en) * 2020-06-15 2023-07-18 北京奇艺世纪科技有限公司 Script language mapping method, electronic device and readable storage medium
CN111831275A (en) * 2020-07-14 2020-10-27 绿盟科技集团股份有限公司 Method, server, medium and computer equipment for arranging micro-scene script
CN111831275B (en) * 2020-07-14 2023-06-30 绿盟科技集团股份有限公司 Method, server, medium and computer equipment for arranging micro-scene script

Also Published As

Publication number Publication date
CN110389899B (en) 2023-12-19

Similar Documents

Publication Publication Date Title
US9495543B2 (en) Method and apparatus providing privacy benchmarking for mobile application development
CN110377289A (en) A kind of data analysis method, device, medium and electronic equipment
CN110389899A (en) Detect square law device, medium and the equipment of the API data type of JS program
CN110109840A (en) Code audit method, audit device and the medium compared based on version number
CN110245030A (en) A kind of data service providing method, device, medium and electronic equipment
CN108958992A (en) test method and device
CN109062563A (en) Method and apparatus for generating the page
CN109684188A (en) Test method and device
CN109408754A (en) Processing method, device, electronic equipment and the storage medium of web page operation data
CN110377273B (en) Data processing method, device, medium and electronic equipment
CN110489165A (en) Obtain method, apparatus, medium and the equipment of call stack stack frame command offsets
CN109582317A (en) Method and apparatus for debugging boarding application
CN110489162A (en) Installation kit SO file compressing method, device, medium and equipment
CN109462648A (en) A kind of user behavior tracking, device, equipment and storage medium
CN110489333A (en) A kind of method, apparatus based on detector tune-up data, medium and electronic equipment
CN110489041A (en) Method, apparatus, equipment and the medium of small routine dragging element automatic aligning
CN110188782A (en) Image similarity determines method, apparatus, electronic equipment and readable storage medium storing program for executing
CN110221877A (en) A kind of operation method of application program, device, electronic equipment and storage medium
CN109614327A (en) Method and apparatus for output information
CN111752644A (en) Interface simulation method, device, equipment and storage medium
CN111506904A (en) Method and device for online vulnerability repair
CN110489164A (en) It is a kind of to hide acquisition methods, device, medium and the equipment for asserting information
CN110134601A (en) A kind of software pressure surveys coverage measure method, system, medium and electronic equipment
CN109145591A (en) The plug-in loading method of application program
CN112379967B (en) Simulator detection method, device, equipment and medium

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
GR01 Patent grant
GR01 Patent grant