This is some super-alpha POC code to generate FDC3 apis (well, the open
method) from OpenAPI.
run mvn install
Generates some java code like:
*/
@Path("/")
public interface DefaultApi {
/**
* Opens an FDC3 App
*
*/
@POST
@Path("/open/{appId}")
@Consumes({ "application/json" })
@Operation(summary = "Opens an FDC3 App", tags={ })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK") })
public void open(Context body, @PathParam("appId") String appId);
}
Use openapi-typescript
sudo npm i --location=global openapi-typescript
Generates:
export class DefaultService {
/**
* Opens an FDC3 App
* @param appId
* @param requestBody Optional description in *Markdown*
* @returns any OK
* @throws ApiError
*/
public static open(
appId: string,
requestBody: Context,
): CancelablePromise<any> {
return __request(OpenAPI, {
method: 'POST',
url: '/open/{appId}',
path: {
'appId': appId,
},
body: requestBody,
mediaType: 'application/json',
});
}
}
Something like:
sudo openapi-generator-cli generate -i src/main/resources/openapi/desktop-agent.yaml -g aspnetcore -o "target/generated-sources/swagger/DesktopAgent.web" --package-name DesktopAgent.web
Generates:
namespace DesktopAgent.web.Controllers
{
/// <summary>
///
/// </summary>
[ApiController]
public class DefaultApiController : ControllerBase
{
/// <summary>
/// Opens an FDC3 App
/// </summary>
/// <param name="appId"></param>
/// <param name="context">Optional description in *Markdown*</param>
/// <response code="200">OK</response>
[HttpPost]
[Route("/open/{appId}")]
[Consumes("application/json")]
[ValidateModelState]
[SwaggerOperation("Open")]
public virtual IActionResult Open([FromRoute (Name = "appId")][Required]string appId, [FromBody]Context context)
{
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(200);
throw new NotImplementedException();
}
}
}
Copyright 2019 Fintech Open Source Foundation
Distributed under the Apache License, Version 2.0.
SPDX-License-Identifier: Apache-2.0