gerlowskija opened a new pull request, #1681:
URL: https://github.com/apache/solr/pull/1681

   https://issues.apache.org/jira/browse/SOLR-16835
   
   # Description
   
   Currently, Solr only offers one "first-party" client, SolrJ, which can only 
be used within JVM environments.  This is obviously limiting for our users.
   
   Historically, keeping client bindings in multiple languages up to date has 
been too daunting for the project to undertake.  But now that Solr produces an 
OpenAPI spec for its upcoming "v2" API, we have the ability to generate client 
bindings from that for a variety of languages with very little additional 
maintenance cost.
   
   # Solution
   
   This PR uses the 'openapi-generator' gradle plugin to create a Python client 
based on our OpenAPI spec.  A few details:
   
   - `./gradlew openApiValidate` to generate the OpenAPI spec and ensure it's 
valid to use for code-generation.
   - `./gradlew openApiGenerate` to generate the Python client
   - Generation uses a template that we can modify if we'd like to.  (Currently 
this PR just uses template unmodified.)
   - Once created, client is available at `solr/core/build/generated/python` 
and can be installed to the user's Python environment with `python setup.py 
install --user`
   - Generated code uses urllib3 to send requests (though that's abstracted 
away entirely afaict)
   - The organization (and to an extent, quality) of the generated code depends 
in part on some OpenAPI annotations that we don't use across-the-board 
currently.  This PR adds those annotations to a few Java classes so the 
generated client is a little easier to demo.  We already have other JIRA 
tickets for doing this more comprehensively though.
   
   See below for a snippet that uses the generated client to create a 
collection:
   
   ```
   import solr
   from solr.api import collection_api
   from solr.model.create_collection_request_body import 
CreateCollectionRequestBody
   
   configuration = solr.Configuration(host = "http://localhost:8983/api";)
   with solr.ApiClient(configuration) as api_client:
       api_instance = collection_api.CollectionApi(api_client)
       create_params = CreateCollectionRequestBody(
               name = "somecollection",
               num_shards = 1 
       )   
       try:
           api_response = 
api_instance.create_collection(create_collection_request_body = create_params)
           pprint(api_response)
       except solr.ApiException as e:
           print("Exception when calling CollectionApi->create_collection: 
%s\n" % e)
   ```
    
   # Tests
   
   The code-generator has an option to generate tests for the generated client 
code.  I've disabled that currently, trusting the generator to do its thing, 
but we can enable that if it's something we'd feel more comfortable using.
   
   Other than those generated tests, this has mostly been manual testing on my 
part.
   
   # Checklist
   
   Please review the following and check all that apply:
   
   - [x] I have reviewed the guidelines for [How to 
Contribute](https://wiki.apache.org/solr/HowToContribute) and my code conforms 
to the standards described there to the best of my ability.
   - [x] I have created a Jira issue and added the issue ID to my pull request 
title.
   - [x] I have given Solr maintainers 
[access](https://help.github.com/en/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork)
 to contribute to my PR branch. (optional but recommended)
   - [x] I have developed this patch against the `main` branch.
   - [ ] I have run `./gradlew check`.
   - [ ] I have added tests for my changes.
   - [ ] I have added documentation for the [Reference 
Guide](https://github.com/apache/solr/tree/main/solr/solr-ref-guide)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to