OpenAPI registration and code generation

The registration also registers a URL in the service that returns the OpenAPI files specified in the manifest in the service. This enables you to test the service in the API UI in Portal.

Here is an example on what the OpenAPI registration can look like in the manifest. More than one OpenAPI file is supported.


```json
"openApiDefinitions" : [ {
  "name" : "KeyValueStore",
  "filename" : "KeyValueStore.json",
  "package" : null,
  "importMappings" : { }
} ]
```

The openAPI file needs to include a server with the basePath variable. If you want to view the openAPI in swagger, see the section Manual/Local Development/OpenAPI Swagger Preview.

Something like one of these is needed:

```json
"servers": [
  {
    "url": "http://localhost:7071/keyvaluestore/{basePath}",
    "variables": {
      "basePath": {
        "default": "api/v1"
      }
    }
  }
]
```

From an OpenAPI file, classes can be generated. When this is done, new classes are created in two places.

In the **"generated"** folder, many new classes are created; these handle the REST Api, interface and any optional data models. All these classes are overwritten if a new generation is started, which means that no modifications should be done here.

In the **"services"** folder, an implementation class is created. Here is where all modifications should be done. If modifications are done to the OpenAPI file, they are not added to the implementation file. The user must do this through VS Code instead.

Note: It is recommended to use "referenced" data model objects instead of "inline" objects. For an example of a "referenced" data model object, see the _"KeyValueStore"_ project and the _"MyDataObject"_ class. This project is included in the documentation as a download.

Renaming an OpenAPI file

If an OpenAPI file is renamed and the code is re-generated, some manual clean-up is needed.

In the "generated" folder, the classes with the old name can be deleted. This is true also for the implementation file; just make sure to copy any existing code first to the new implementation.

In addition to this, the following files must have the old class from the "generated" folder removed:

  • Java: "src/main/resources/META-INF/services/com.infor.baas.commons.interfaces.RestHandler"
  • Typescript: "src/exports/rest-exports.ts"