Code processing method, interface calling method, electronic device and storage medium

CN122672833BActive Publication Date: 2026-10-30GOERTEK INC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611171135.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-08-04
Publication Date
2026-10-30
Estimated Expiration
2046-08-04

AI Technical Summary

Technical Problem

[0003]随着业务持续迭代,接口定义文件中的接口方法不断变更,若两端的接口方法代码未能同步更新,则两端所使用的接口方法代码可能会存在版本差异,导致接口调用出现版本兼容性问题,调用端调用接口方法失败后才知道接口不兼容,调试成本高

Benefits of technology

[0015]本公开实施例中的代码生成器通过提取版本字段信息,并基于该版本字段信息生成具有接口版本校验功能的接口方法代码,以使调用端调用接口方法时,先对被调用端当前使用的该接口方法的版本信息进行校验,在校验未通过的情况下,阻止该接口方法被调用,从而及时发现接口版本不兼容,而无需等待调用失败即可发现接口版本不兼容,降低调试成本。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122672833B_ABST
    Figure CN122672833B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a code processing method, an interface calling method, an electronic device and a storage medium. The code processing method is applied to a code generator, and the method comprises: in response to a code generation request, obtaining a target file, the target file comprising version field information corresponding to an interface method; parsing the target file to extract the version field information; based on the version field information, generating an interface method code for each interface method, the interface method code being used to verify version information corresponding to the interface method currently used by a calling end when the interface method code is called, and preventing the interface method from being called in the case that the verification fails. The method can generate an interface method code with an interface version verification function, so that interface version incompatibility problems can be discovered in time before the interface method is called, thereby reducing the debugging cost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer software technology, and more specifically, to a code processing method, an interface calling method, an electronic device, and a computer-readable storage medium. Background Technology

[0002] In scenarios where the calling and called ends collaborate, communication between them typically requires a predefined interface protocol. During the development phase, developers define these interface protocols using a specialized interface description language, generating interface definition files. Then, a code generator automatically converts these interface definition files into the interface protocol code required by both the calling and called ends, thereby reducing the cost of manually writing interface protocol code and improving development efficiency. This interface protocol code includes the interface method code for each interface method.

[0003] As business processes continue to iterate, the interface methods in the interface definition file are constantly changing. If the interface method code on both ends is not updated in sync, there may be version differences in the interface method code used by both ends, leading to version compatibility issues in interface calls. The calling end only realizes the incompatibility after the interface method fails to be called, resulting in high debugging costs. Summary of the Invention

[0004] One objective of this disclosure is to provide a technical solution for a code processing method, an interface calling method, an electronic device, and a computer-readable storage medium, so as to verify the interface method version before the calling end calls the interface method, thereby reducing debugging costs.

[0005] According to a first aspect of the present disclosure, a code processing method is provided, applied to a code generator, the method comprising: in response to a code generation request, obtaining a target file, the target file including version field information corresponding to an interface method; parsing the target file and extracting the version field information; generating interface method code for each interface method based on the version field information, wherein the interface method code, when invoked, is used to verify the version information corresponding to the interface method currently used by the invoked end, and if the verification fails, preventing the interface method from being invoked.

[0006] Optionally, generating interface method code for each interface method based on the version field information includes: Based on the version field information, a constant code block is generated, which includes a service version constant and an interface method version constant. Generate a verification code block based on the service version constant, the interface method version constant, and the preset version verification rules; Based on the constant code block, the verification code block, and the interface method call code block, the interface method code is generated. When the interface method code is called, it is specifically used to read the service version constant and the interface method version constant from the constant code block, and to verify the version information using the verification code block. If the verification fails, the interface method is prevented from being called.

[0007] Optionally, generating the interface method code based on the constant code block, the verification code block, and the interface method call code block includes: The verification code block is encapsulated into a wrapper function; Add the wrapper function before the interface method call code block to obtain a new interface method call code block; The interface method code is generated based on the constant code block and the new interface method call code block.

[0008] Optionally, the method further includes: In response to a code save request or a code commit request, the generated interface method code is validated. If the verification passes, the interface method code will be saved or submitted; otherwise, if the verification fails, the saving or submission of the interface method code will be prevented.

[0009] Optionally, the verification of the generated interface method code includes at least one of the following: Scan all the interface method numbers in the interface method code to check for duplicate numbers; Verify whether the current interface method code has changed compared to the historical interface method code. If there is a change, verify whether the version field information corresponding to the current interface method code has been changed based on the version field information corresponding to the historical interface method code. The current interface method code is the interface method code generated this time, and the historical interface method code is the interface method code of the previous version stored in the history.

[0010] Optionally, the step of verifying whether the version field information corresponding to the current interface method code has been changed based on the version field information corresponding to the historical interface method code when changes occur includes: If changes have occurred, obtain the change level; Verify whether the version field information corresponding to the current interface method code follows the change rules corresponding to the change level, and make changes based on the version field information corresponding to the historical interface method code.

[0011] According to a second aspect of the embodiments of this disclosure, an interface invocation method is also provided, including: Receive API call requests initiated by the client; In response to the call request, the version field information of the interface method carried in the interface method code is obtained. The interface method code is the code generated by the code generator based on the version field information of the interface method in the target file. The target file is the file obtained in response to the code generation request. Obtain the version information of the interface method currently used by the called client; The version information is validated using the version field information. If the validation fails, the interface method is prevented from being called.

[0012] Optionally, the version field information includes the iteration version number of the interface service where the interface method is located and the effective version number of the interface method. The version information also includes the service version number of the interface service where the interface method is located and the interface version number of the interface method currently used by the called end. The step of using the version field information to verify the version information, and preventing the interface method from being called if the verification fails, includes at least one of the following: The service version number and the iteration version number are compared, and if the service version number is lower than the iteration version number, the interface method is prevented from being called. If the service version number is not lower than the iteration version number, the interface version number and the effective version number are compared. If the interface version number is lower than the effective version number, the interface method is prevented from being called.

[0013] According to a third aspect of the present disclosure, an electronic device is also provided, including a memory and a processor, the memory being used to store a computer program; the processor being used to execute the computer program to implement the method according to the first or second aspect of the present disclosure.

[0014] According to a fourth aspect of the present disclosure, a computer-readable storage medium is also provided, on which a computer program is stored, which, when executed by a processor, implements the method described according to the first or second aspect of the present disclosure.

[0015] The code generator in this embodiment extracts version field information and generates interface method code with interface version verification function based on the version field information. This allows the calling end to first verify the version information of the interface method currently used by the called end when calling the interface method. If the verification fails, the interface method is prevented from being called, thereby timely detection of interface version incompatibility without waiting for the call to fail, reducing debugging costs.

[0016] Other features and advantages of the embodiments of this disclosure will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. Attached Figure Description

[0017] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments of the present disclosure and, together with the description, serve to explain the principles of the disclosure.

[0018] Figure 1 This is a flowchart illustrating a code processing method according to some embodiments.

[0019] Figure 2 This is a flowchart illustrating a code processing method according to some other embodiments.

[0020] Figure 3 This is a flowchart illustrating the interface call method according to some embodiments.

[0021] Figure 4 This is a block schematic diagram of an electronic device according to some embodiments. Detailed Implementation

[0022] Various exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that, unless otherwise specifically stated, the relative arrangement, numerical expressions, and values ​​of the components and steps set forth in these embodiments do not limit the scope of the present disclosure.

[0023] The following description of at least one exemplary embodiment is merely illustrative and is not intended to limit the scope of this disclosure or its application or use.

[0024] Techniques, methods, and equipment known to those skilled in the art may not be discussed in detail, but where appropriate, such techniques, methods, and equipment should be considered part of the specification.

[0025] In all the examples shown and discussed herein, any specific values ​​should be interpreted as merely exemplary and not as limitations. Therefore, other examples of exemplary embodiments may have different values.

[0026] It should be noted that similar labels and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be discussed further in subsequent figures.

[0027] It should be noted that all data acquisition actions in this disclosure were carried out in compliance with the relevant data protection laws and policies of the country where the data is located, and with the authorization of the relevant equipment owner.

[0028] This disclosure relates to a code processing method and an interface invocation method. For ease of understanding, an application scenario involved in this disclosure is first briefly described. This application scenario includes a caller and a callee. The caller can be an application (App), and the callee can be a smart hardware device (such as a smart wearable device). The two ends communicate through a predefined interface protocol. An interface protocol refers to the agreed-upon communication specifications between the caller and the callee, defining how they exchange data, such as: what interface methods are available, what the parameters of each method are, what the return value is, and what the number is, etc. During the development phase, developers define these interface protocols using a specialized interface description language, generating interface definition files. Then, a code generator automatically converts the interface definition files into the interface protocol code required by both the caller and the callee. This interface protocol code contains interface method code for each interface method. The generated interface protocol code is compiled, packaged, and deployed to the corresponding devices along with the respective program versions of the caller and the callee.

[0029] In this application scenario, one possible implementation is as follows: After reading the interface definition file, the code generator only generates basic data structure code, lacking version field information for the corresponding interface methods, and also lacking version checking and compatibility verification code. Relying solely on manual checks by developers after modifying the interface methods is prone to omissions. Furthermore, as business processes continuously iterate, the interface methods in the interface definition file constantly change. If the interface method code on both ends fails to update synchronously, version differences may exist between the interface method code used by both ends. The calling end cannot detect this in advance when initiating an interface call; the version incompatibility information is only discovered after the call fails, resulting in high debugging costs.

[0030] To this end, this embodiment of the disclosure introduces a mechanism for extracting and transmitting version field information in the code generator, automatically generates interface method code with version verification logic, and automatically performs access control checks during the code saving or submission stage, thereby automatically intercepting calls with incompatible interface versions during compilation and runtime.

[0031] The following describes various embodiments of this disclosure in conjunction with application scenarios.

[0032] <First Embodiment> Figure 1 This is a flowchart illustrating a code processing method provided in an embodiment of this disclosure. The method is applied to a code generator. For example... Figure 1 As shown, the method may include steps S110 to S130.

[0033] Step S110: In response to the code generation request, obtain the target file.

[0034] In this embodiment of the disclosure, the target file is the input to the code generator.

[0035] Code generation requests can be triggered manually (e.g., by developers) or automatically. A response to a code generation request could be, for example, a submission request following a developer's modification of an API definition file.

[0036] The code generation request is used to request the generation of corresponding interface method code for each interface method. The generated interface method code can be called by the business side to implement the functionality of the interface method.

[0037] In this embodiment, the target file includes extended interface definitions. The target file may include version field information corresponding to the interface methods. This version field information may include service version information of the interface service where the interface method resides (e.g., the service version field and its corresponding iteration version number), and version information of the interface method (e.g., the method active field and its corresponding active version number, and the method deprecated field and its corresponding deprecated version number). The iteration version number identifies the overall version of the interface service; for example, it may correspond to the `service_version` field in the target file. The active version number identifies the version from which the corresponding interface method is supported; for example, it may correspond to the `method_added_in` field in the target file. The deprecated version number identifies the version from which the corresponding interface method is deprecated; for example, it may correspond to the `method_deprecated_in` field in the target file. By explicitly annotating the above version semantics in the target file, the version information can be fully preserved during subsequent code generation.

[0038] The target file can be an interface definition file, which defines the communication protocol between the caller and the callee. During development, developers add a version field to the interface definition file. For example, the version field information would look like this: - service_version: Service version number - method_added_in: The version number that the method is now supported on. - method_deprecated_in: The version number at which the method began to be deprecated. The target file can also be a standalone configuration file. In other words, the version field information can be carried in an interface definition file or a standalone configuration file.

[0039] The target file can be in various formats. For example, the target file can be a .proto file in Protocol Buffers (Protobuf) format, or a configuration file in YAML or JSON format. The specific format can be selected according to the needs of the project's technology stack.

[0040] Step S120: Parse the target file and extract the version field information.

[0041] The code generator parses the target file, identifies and extracts the version field information it carries, and uses it for subsequent code generation steps.

[0042] Step S130: Generate interface method code for each interface method based on the version field information.

[0043] The interface method code in this embodiment of the disclosure is used to verify the version information of the interface method currently used by the called end when it is invoked. If the verification fails, the interface method is prevented from being invoked. In other words, the interface method code in this embodiment of the disclosure can verify the version before the interface method is invoked, and if the verification fails, the interface method will not actually be invoked.

[0044] As can be seen from steps S110 to S130 above, the code generator in this embodiment of the present disclosure has added the ability to generate verification code. By extracting version field information and generating interface method code with interface version verification function based on the version field information, the version field information is transmitted from the interface definition file to the code that runs when the interface method is called. This allows the calling end to automatically verify the version information of the interface method currently used by the called end when calling the interface method. If the verification fails, the interface method is prevented from being called, thereby timely detection of interface incompatibility without waiting for the call to fail, thus reducing debugging costs.

[0045] In some examples, the interface method code may include a constant code block, a validation code block, and an interface method call code block. The constant code block is used to store code constants. In these examples, step S130 may include: generating a constant code block based on the version field information. That is, the version number in the version field information is fixed as a code constant, version metadata code is generated, and stored in the constant code block.

[0046] Constant code blocks can include service version constants and interface method version constants. For example, for the `GetBloodPressure` method in the `HealthMonitoring` health monitoring service, the service version constant `HealthMonitoring_VERSION` corresponds to the overall iteration version number of the service, and the method's effective version constant `GetBloodPressure_ADDED_IN` corresponds to the effective version number of that method. Constant code blocks are determined at compile time and can be directly referenced during interface calls without repeatedly parsing the target file. In this way, version information is permanently stored and preserved as code constants.

[0047] Step S130 may further include: generating a verification code block based on the service version constant, the interface method version constant, and preset version verification rules. The preset version verification rules may include the judgment conditions for version comparison and the handling logic when verification fails. In these examples, the verification code block may reference the version constant in the constant code block, and perform verification logic on the version information of the called end before the interface is called.

[0048] For example, for the GetBloodPressure method in the HealthMonitoring interface service mentioned above, the code generator can generate the following constant code block, as shown in the example below: const HealthMonitoring_VERSION = "2.1.0"; const GetBloodPressure_ADDED_IN = "2.1.0".

[0049] The business code can obtain the version field information by referencing the above constants. The version field information is fixed and retained in the form of code constants.

[0050] The interface method call block can contain the actual calling logic of the interface method, which is used to execute the actual interface call after the validation passes.

[0051] Step S130 may further include: generating interface method code based on the constant code block, the validation code block, and the interface method call code block. In these examples, when the interface method code is called, it is specifically used to read the service version constant and the interface method version constant from the constant code block, use the validation code block to validate the version information, and prevent the interface method from being called if the validation fails.

[0052] In these examples, when the interface method code is invoked, the validation code block is executed first. If the validation passes, the interface method invocation code block is executed. When the business code calls the interface method, it actually invokes the interface method code generated above, without needing to be aware of the implementation details of the version validation.

[0053] In these examples, by embedding version field information into constant code blocks, version information can be traced and referenced at the code level, and the verification logic can be decoupled from the business call logic.

[0054] In some examples, the steps to generate interface method code based on constant code blocks, validation code blocks, and interface method call code blocks may include: encapsulating the validation code block into a wrapper function; adding the wrapper function before the interface method call code block to obtain a new interface method call code block; and generating interface method code based on the constant code block and the new interface method call code block.

[0055] By encapsulating the validation code block into a wrapper function and placing it before each interface method call code block, the validation logic can transparently intercept the original interface method call. The business caller does not need to be aware of the validation details, and the code structure is clear and easy to maintain.

[0056] In addition to generating constant code blocks, validation code blocks, and interface method call code blocks, the code generator in this embodiment also generates regular data structure code blocks. For example, interface method code is generated based on the constant code blocks, validation code blocks, interface method call code blocks, and data structure code blocks.

[0057] Using the above method, version verification logic is automatically generated with the code, eliminating the need for business code to manually write version checking logic at each interface method call. Version compatibility verification is automatically executed during code runtime.

[0058] <Second Embodiment> Figure 2 This is a flowchart illustrating another code processing method provided in an embodiment of this disclosure. This method is applied to a code generator. For example... Figure 2 As shown, the method may include steps S210 to S260.

[0059] Step S210: In response to the code generation request, obtain the target file.

[0060] Step S220: Parse the target file and extract the version field information.

[0061] Step S230: Generate interface method code for each interface method based on the version field information.

[0062] Step S240: In response to a code save request or code commit request, verify the generated interface method code.

[0063] Step S250: If the verification passes, save or submit the interface method code.

[0064] Alternatively, in step S260, if the validation fails, the saving or submission of the interface method code is prevented.

[0065] The specific implementation of steps S210 to S230 can be referred to steps S110 to S130 in the first embodiment, and will not be repeated here.

[0066] The verification in step S240 is essentially a gatekeeping check. After code generation but before saving or committing, the generated interface method code undergoes a compliance check. In some examples, the interface method code needs to be saved and committed to the code repository after generation. Before saving or committing, the interface method code is verified. If the verification passes, saving or committing is allowed; if the verification fails, saving or committing is prevented, and a problem report is output.

[0067] By using the above methods, the standardization verification that originally relied on manual inspection is transformed into automatic execution by tools, realizing automated access control inspection and reducing the risk of human oversight.

[0068] In some examples, the generated interface method code is validated, including at least one of the following: scanning the IDs of all interface methods in the interface method code to check for duplicate IDs; verifying whether the current interface method code has changed compared to the historical interface method code, and if so, verifying whether the version field information corresponding to the current interface method code has changed based on the version field information corresponding to the historical interface method code. In these examples, the current interface method code is the interface method code generated this time, and the historical interface method code is the interface method code of the previous version stored in the history.

[0069] In other words, verifying the generated interface method code includes at least one of number conflict verification and version change verification.

[0070] In these examples, if duplicate IDs are present, a ID conflict report is generated, and the saving or commit of the interface method code is prevented. By automatically detecting ID conflicts during the save or commit phase, the discovery of ID conflicts can be shifted from the interface method call phase to the code commit phase, avoiding interface call failures caused by duplicate IDs when multiple teams are developing in parallel.

[0071] In these examples, when code changes occur, the version field information corresponding to the current interface method code is checked to see if it has been changed based on the version field information of the historical interface method code. If the version field information has not been changed, saving or committing the current interface method code is prevented. By requiring that the version field information be updated synchronously when the interface method changes, incompatible changes due to missed version number updates can be avoided from being released.

[0072] The current interface method code has changed compared to the historical interface method code. For example, adding an interface method, deleting an interface method, adding or deleting fields in an interface method, or modifying the data type of a field.

[0073] In some examples, when changes occur, it verifies whether the version field information corresponding to the current interface method code has been changed based on the version field information corresponding to the historical interface method code. This includes: obtaining the change level when changes occur; and verifying whether the version field information corresponding to the current interface method code has been changed according to the change rules corresponding to the change level and based on the version field information corresponding to the historical interface method code.

[0074] In other words, version change checks can further obtain the change level and verify whether the version field information has been correctly upgraded according to the change rules corresponding to the change level.

[0075] For example, change levels can be categorized as destructive and non-destructive. Destructive changes can include operations such as deleting interface methods or modifying field types, with the corresponding change rule being an upgrade of the major version number. For example, upgrading version number 2.1.1 to 3.0.0. Non-destructive changes can include operations such as adding interface methods or adding fields, with the corresponding change rule being an upgrade of the minor version number or revision number. If a destructive change exists but the major version number has not been upgraded, saving or committing the current interface method code will be prevented.

[0076] In these examples, by introducing a change level mechanism, it is possible to enforce that disruptive changes must upgrade the major version number, ensuring the accuracy of version number semantics and enabling callers to perceive the existence of disruptive changes through changes in the major version number.

[0077] In some examples, more validation rules can be added, such as checking for log format changes and marking required fields.

[0078] These checks can be integrated into a continuous integration pipeline for automatic execution, preventing code merging if the checks fail.

[0079] In other examples, the timing of the access control checks mentioned above is not limited to when the code is saved or committed. They can also be integrated into development tool plugins to trigger number conflict checks in real time when developers save interface definition files, thus moving the timing of error discovery forward to the development stage.

[0080] <Third Embodiment> Figure 3 This is a flowchart illustrating an interface invocation method provided in an embodiment of this disclosure. Figure 3 As shown, the method includes steps S310 to S340.

[0081] Step S310: Receive the call request for the interface method initiated by the calling end.

[0082] In step S310, the calling end responds to the triggering of business logic by initiating a call request to a certain interface method.

[0083] Step S320: In response to the call request of the interface method, obtain the version field information of the interface method carried in the interface method code.

[0084] The interface method code can be pre-generated by a code generator based on the version field information of the interface method in the target file. The target file can be a file obtained in response to a code generation request. When executing the interface method code, the validation code block is executed first.

[0085] Version field information can be read from the constant code block in the interface method code. The version constant in the constant code block is fixed at compile time and can be directly referenced when the interface method is called, without the need to re-parse the target file.

[0086] Step S330: Obtain the version information of the interface method currently used by the called end.

[0087] The version information of the interface method currently used by the called end is dynamically obtained when the interface method is called. It may include the service version number of the interface service currently used by the called end and the interface version number of the interface method.

[0088] Step S340: Verify the version information using the version field. If the verification fails, prevent the interface method from being called.

[0089] The method may also include: validating the version information using the version field information, and executing the call to the interface method if the verification passes.

[0090] In this embodiment of the disclosure, the specific process of executing the interface method code is as follows: obtaining the version field information of the interface method carried in the interface method code; obtaining the version information corresponding to the interface method currently used by the called end; and using the version field information to verify the version information. If the verification fails, the interface method is prevented from being called, or if the verification passes, the interface method is called.

[0091] As can be seen from steps S310 to S340 above, the version incompatibility problem is intercepted before the interface method call is initiated by the interface method method of this disclosure, which moves the error discovery time from after the call failure to before the call is initiated, significantly reducing the debugging cost and improving the reliability of the interface call.

[0092] In some examples, the version field information may include the iteration version number of the interface service where the interface method resides and the effective version number of the interface method. The version information of the interface method currently used by the called end may include the service version number and interface version number of the interface service where the interface method resides.

[0093] Step S340 may include at least one of the following: comparing the service version number and the iteration version number, and preventing the interface method from being called if the service version number is lower than the iteration version number; or comparing the interface version number and the effective version number if the service version number is not lower than the iteration version number, and preventing the interface method from being called if the interface version number is lower than the effective version number.

[0094] The version information is validated using the version field. If the validation passes, calling the interface method may include: comparing the service version number and the iteration version number; if the service version number is not lower than the iteration version number, comparing the interface version number and the effective version number; if the interface version number is not lower than the effective version number, executing the interface method call.

[0095] For example, you can prevent an interface method from being called by throwing an exception.

[0096] In these examples, two-level version verification can achieve layered version compatibility judgment from the overall service to specific interface methods, and the verification results are more accurate.

[0097] In some examples, the version field may also include the obsolete version number of the interface method. If the interface version number is not lower than the obsolete version number, a warning message can be output to inform the caller that the interface method has entered the obsolete stage and recommend migrating to the new version. By introducing an obsolete version number, callers can be notified in advance to adapt before the interface method is officially removed, reducing the compatibility risks of interface upgrades.

[0098] <Fourth Embodiment> This disclosure also provides an electronic device. Figure 4 A schematic diagram of the hardware structure of the electronic device is shown. (For example...) Figure 4 As shown, the electronic device 400 includes a processor 410 and a memory 420. The memory can be used to store computer programs, and the processor can be used to retrieve the computer programs from the memory to execute any method disclosed herein. The processor can be one or more processors, which can execute instructions individually or jointly. Similarly, the memory can be one or more, which can store the aforementioned computer programs individually or jointly. The electronic device can be a development device running a code generator or a continuous integration (CI) server, or a calling terminal for executing interface calls.

[0099] This disclosure also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the methods disclosed herein. Optionally, the computer-readable storage medium may be a non-transitory storage medium, but is not limited thereto; it may also be a temporary storage medium.

[0100] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0101] This disclosure may be a system, method, and / or computer program product. A computer program product may include a computer-readable storage medium having a computer-readable program loaded thereon for causing a processor to implement any of the methods in the foregoing embodiments of this disclosure.

[0102] Computer-readable storage media can be tangible devices capable of holding and storing instructions for use by an instruction execution device. Computer-readable storage media may include, for example, electrical storage devices, magnetic storage devices, optical storage devices, electromagnetic storage devices, semiconductor storage devices, or any suitable combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), static random access memory (SRAM), compact disc-read-only memory (CD-ROM), digital versatile disc (DVD), memory sticks, floppy disks, mechanical encoding devices, such as punch cards or recessed protrusions storing instructions thereon, and any combination thereof. The computer-readable storage medium used herein is not to be interpreted as a transient signal itself, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., light pulses through fiber optic cables), or electrical signals transmitted through wires.

[0103] The computer-readable program instructions described herein can be downloaded from computer-readable storage media to various computing / processing devices, or downloaded via a network, such as the Internet, local area network, wide area network, and / or wireless network, to an external computer or external storage device. The network may include one or more of copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to computer-readable storage media in the respective computing / processing device.

[0104] The computer program instructions used to perform the operations of this disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, or source or object programs written in any combination of one or more programming languages, including object-oriented programming languages ​​(such as Smalltalk, C++, etc.) and conventional procedural programming languages ​​(such as the "C" language or similar programming languages). The computer-readable program instructions may be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network (e.g., a local area network or a wide area network), or it may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays, or programmable logic arrays, can execute computer-readable program instructions to implement various aspects of the embodiments of this disclosure by utilizing state information from the computer-readable program instructions.

[0105] Various aspects of this disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus, and computer program products according to embodiments of this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.

[0106] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that, when executed by the processor of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner; thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of the flowchart and / or block diagram.

[0107] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions that execute on the computer, other programmable data processing apparatus, or other device to perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.

[0108] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions. It should be noted that implementation in hardware, implementation in software, and implementation using a combination of software and hardware are all equivalent.

[0109] The various embodiments of this disclosure have been described above. These descriptions are exemplary and not exhaustive, and are not limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical application, or improvement of the technology in the market, or to enable others skilled in the art to understand the embodiments disclosed herein. The scope of this disclosure is defined by the appended claims.

Claims

1. A code processing method, characterized in that, Applied to a code generator, the method includes: In response to a code generation request, a target file is obtained, the target file including version field information corresponding to the interface method; The target file is parsed to extract the version field information; Based on the version field information, a constant code block is generated, which includes a service version constant and an interface method version constant. Generate a verification code block based on the service version constant, the interface method version constant, and the preset version verification rules; Based on the constant code block, the verification code block, and the interface method call code block, the interface method code is generated. When the interface method code is called, it is used to read the service version constant and the interface method version constant from the constant code block, and use the verification code block to verify the version information corresponding to the interface method currently used by the called end. If the verification fails, the interface method is prevented from being called.

2. The method according to claim 1, characterized in that, The step of generating the interface method code based on the constant code block, the verification code block, and the interface method call code block includes: The verification code block is encapsulated into a wrapper function; Add the wrapper function before the interface method call code block to obtain a new interface method call code block; The interface method code is generated based on the constant code block and the new interface method call code block.

3. The method according to claim 1, characterized in that, The method further includes: In response to a code save request or a code commit request, the generated interface method code is validated. If the verification passes, the interface method code will be saved or submitted; otherwise, if the verification fails, the saving or submission of the interface method code will be prevented.

4. The method according to claim 3, characterized in that, The verification of the generated interface method code includes at least one of the following: Scan all the interface method numbers in the interface method code to check for duplicate numbers; Verify whether the current interface method code has changed compared to the historical interface method code. If there is a change, verify whether the version field information corresponding to the current interface method code has been changed based on the version field information corresponding to the historical interface method code. The current interface method code is the interface method code generated this time, and the historical interface method code is the interface method code of the previous version stored in the history.

5. The method according to claim 4, characterized in that, The step of verifying whether the version field information corresponding to the current interface method code has been changed based on the version field information corresponding to the historical interface method code when changes exist includes: If changes have occurred, obtain the change level; Verify whether the version field information corresponding to the current interface method code follows the change rules corresponding to the change level, and make changes based on the version field information corresponding to the historical interface method code.

6. An interface invocation method, characterized in that, include: Receive API call requests initiated by the client; In response to the call request, the version field information of the interface method carried by the constant code block in the interface method code is obtained. The interface method code is generated by the code generator based on the constant code block, the verification code block, and the interface method call code block. The constant code block is generated based on the version field information in the target file. The constant code block includes a service version constant and an interface method version constant. The verification code block is generated based on the service version constant, the interface method version constant, and a preset version verification rule. The target file is a file obtained in response to the code generation request. Obtain the version information of the interface method currently used by the called client; According to the verification code block, the version information is verified using the version field information. If the verification fails, the interface method is prevented from being called.

7. The method according to claim 6, characterized in that, The version field information includes the iteration version number of the interface service where the interface method is located and the effective version number of the interface method. The version information also includes the service version number of the interface service where the interface method is located and the interface version number of the interface method currently used by the called end. The step of using the version field information to verify the version information, and preventing the interface method from being called if the verification fails, includes at least one of the following: The service version number and the iteration version number are compared, and if the service version number is lower than the iteration version number, the interface method is prevented from being called. If the service version number is not lower than the iteration version number, the interface version number and the effective version number are compared. If the interface version number is lower than the effective version number, the interface method is prevented from being called.

8. An electronic device, characterized in that, It includes a memory and a processor, the memory being used to store a computer program; the processor being used to execute the computer program to implement the method according to any one of claims 1 to 7.

9. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, which, when executed by a processor, implements the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Call management and control method and device for remote procedure call, equipment and storage medium

    CN114466053A

  • Dynamically configured software interface parameter verification method and system

    CN120316169A