opensearch-java: [PROPOSAL] Experiment with using Smithy API spec to generate missing APIs

What/Why

What are you proposing?

Performing an experiment using the WIP Smithy API specification for OpenSearch to generate missing functionality in the client for a small API without re-creating the entire client.

What users have asked for this feature?

What problems are you trying to solve?

  • Reduce friction in adoption of new OpenSearch APIs & features in the language clients.
  • Reduce maintenance overhead

What is the developer experience going to be?

A script/tool that can be run to automatically fetch the API spec and generate the chosen code.

Are there any security considerations?

n/a

Are there any breaking changes to the API

This experiment is only successful if it does not break compatibility.

What is the user experience going to be?

Same as developer experience.

Are there breaking changes to the User Experience?

See above.

Why should it be built? Any reason not to?

The learnings from this experiment, if successful:

  • Will be broadly applicable to all language clients.
  • Will reduce workloads for maintainers.
  • Will speed up adoption of new APIs in clients.
  • Will fill in gaps in API coverage If the experiment is unsuccessful, it will not be merged, negating almost any potential downsides. It may not be feasible to integrate generated code from an off-the-shelf generator with the pre-existing client code.

What will it take to execute?

  • Will use the /_remotestore/_restore API as a low-risk low-touch use-case
  • Potentially configuring or customising an off-the-shelf generator, at worst hand-rolling a minimal generator for our use-case.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 33 (5 by maintainers)

Most upvoted comments

Just wanted to share I’d started looking at writing a PoC “from-scratch” OpenAPI based generator, as I’d mentioned in a previous comment. It’s still not quite at the point I want to create a draft PR, but if you want to have a look, it’s pushed up here: https://github.com/Xtansia/opensearch-java/tree/experiment/codegen-openapi-scratch/java-codegen

Closing this issue as the spec is now solely authored in OpenAPI and #366 has been merged

I have raised a draft PR with my working PoC for the from scratch OpenAPI based generator: https://github.com/opensearch-project/opensearch-java/pull/366

thanks @nhtruong

JSON schema is only meant for the request/response bodies, not the entire API spec right?

Correct for request/response bodies, but the spec has own schema here [1]

[1] https://github.com/opensearch-project/OpenSearch/blob/main/rest-api-spec/src/main/resources/schema.json

@reta it’s quite a funny coincidence. I discovered that ES spec while studying this commit to review this PR. Told @wbeckler about it yesterday and he told me this morning that you just brought up the same thing 😆

Anyway, it’s cool that OpenAPI 3.1 can do that. I’ll have to look into it. But I have a hunch that we should still convert it to native OpenAPI spec to make it easier to maintain, more consistent with the spec for future endpoints, and more compatible with off-the-shell parsers. (Again just a hunch. Still need to do research on it)

For reference this is as far as I got with the custom openapi-generator templates/generator before hitting the fact I could not generate code in the same structure as the existing client: main…Xtansia:opensearch-java:experiment/codegen-openapi

@Xtansia thanks for sharing, I picked up your work here https://github.com/opensearch-project/opensearch-java/pull/336, there are no generator changes at the moment (no need, templates are just enough) but I hope to finalize the PoC by getting as close to exiting generated model as possible.

@VachaShah @reta Here’s the example output for that openapi-generator, https://gist.github.com/Xtansia/b88ad73bde610a5e677b0b293c6155ea, while it’s obviously not complete functional code, the main thing to notice is how the models only represent the body of the request/response, and the query params are shifted to the operation method and “flattened” (ie. if there’s n query params then the method will have n+ params)

@Xtansia This is awesome, thank you! For @reta’s question, is it also possible to post what gets generated (maybe a snippet of a class) from the custom Smithy build plugin vs the custom open-api generator? This would give more insights into what kind of client is generated for each option.

For reference this is as far as I got with the custom openapi-generator templates/generator before hitting the fact I could not generate code in the same structure as the existing client: https://github.com/opensearch-project/opensearch-java/compare/main...Xtansia:opensearch-java:experiment/codegen-openapi