Skip to content

Openapi generated client - #125

Closed
MalteEbner wants to merge 9 commits into
develop_active_learningfrom
openapi_generated_client
Closed

Openapi generated client#125
MalteEbner wants to merge 9 commits into
develop_active_learningfrom
openapi_generated_client

Conversation

@MalteEbner

@MalteEbner MalteEbner commented Feb 11, 2021

Copy link
Copy Markdown
Contributor

PR consist of following steps / commits:

  1. copied templates to generate client -> all changed files in the folder openapi_client_generator/python/
  2. wrote script to generated the client at openapi_client_generator/generate_openapi_client.sh-> should be tested
  3. generated the client using the script -> all changed files in the folder lightly/openapi_generated/
  4. changed the .mustache template to allow required and nullable values to be None (e.g. the previousTagId). First the model.mustache template was changed, then the script war rerun, which caused the generated code to change.

@codecov

codecov Bot commented Feb 11, 2021

Copy link
Copy Markdown

Codecov Report

Merging #125 (bde4a85) into develop_active_learning (e9e1b3d) will decrease coverage by 0.12%.
The diff coverage is n/a.

Impacted file tree graph

@@                     Coverage Diff                     @@
##           develop_active_learning     #125      +/-   ##
===========================================================
- Coverage                    82.00%   81.87%   -0.13%     
===========================================================
  Files                           58       56       -2     
  Lines                         1800     1788      -12     
===========================================================
- Hits                          1476     1464      -12     
  Misses                         324      324              
Impacted Files Coverage Δ
lightly/models/__init__.py
lightly/api/__init__.py

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e9e1b3d...bde4a85. Read the comment docs.

@philippmwirth philippmwirth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct me if I'm wrong.

In my understanding, the following points hold:

  • We have a part of this repo in our repo
  • Everytime we build the api from scratch, we also need to make changes to tag_data.py and model.mustache

If so, please make changes such that the necessary code from the other repo is not part of our repository. Instead, give instructions on how to get the required code or clone it automatically in the generator script. Also, can we apply the necessary changes to the two files as a patch or similar?

Let me know if anything is unclear.


# install swagger-codegen following the instructions at https://github.com/swagger-api/swagger-codegen#compatibility
swagger-codegen generate -l python -i $PATH_TO_SPEC -o lightly/openapi_generated --template-dir openapi_client_generator/python --template-engine mustache

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should have the openapi_client_generator code as part of our repository..

There are two options which I would prefer:

  1. Add a line to this script which clones the generator repo at a specified commit
  2. Describe in the README how someone who wants to build the package from scratch can clone the repo and then set the path

six >= 1.10
python_dateutil >= 2.5.3
setuptools >= 21.0.0
urllib3 >= 1.15.1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces new requirements, they should be specified in the PIP package requirements.

_return_http_data_only=params.get('_return_http_data_only'),
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we need the annotations api for?

_return_http_data_only=params.get('_return_http_data_only'),
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that this code should not be public. Can you remove all the generated API code which is not being used?

if not isinstance(other, AnnotationState):
return True

return self.to_dict() != other.to_dict()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the annotation data / requests are not needed by the PIP package, or am I wrong?

if not isinstance(other, CreateCFBucketActivityRequest):
return True

return self.to_dict() != other.to_dict()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed in the PIP package

{{/nullable}}
{{/required}}
{{#isEnum}}
{{#isContainer}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok do we have to change this everytime we generate the API code? In that case I would make an additional change in the generate_openapi_client.sh script which applies this as a patch.

@MalteEbner

Copy link
Copy Markdown
Contributor Author

@philippmwirth:
Do I understand you correctly, that you basically wish the following changes?

  1. If one generates a new python client from a new api.yml, no manual changes, to anything (neither .mustache files, nor generated files) should be necessary. This point is already fulfilled:
    The change with the /nullable to the model.mustach-template only has the be made once (in this PR), it basically creates our own python code generator. If a new api is written, only the script has to be rerun, no manual changes of any code have to be performed.
  2. We do not want that many copied files as template. Ideally, we could use the generator without customers templates. To achieve this, I create the following PR for swagger-codegen: [Python] Nullable bugfix in model.mustache swagger-api/swagger-codegen#10906
  3. The lightly pip package should not contain any code needed for generating the client. We could solve this by putting the files in the folder openapi_client_generator into the lightly-core package. What do you think about that?
  4. There should be as little files and code in the repo as possible. Thus all generated files not needed should be deleted.
  5. The new requirements added should be specified in the PIP package requirements.

@philippmwirth

Copy link
Copy Markdown
Contributor

@philippmwirth:
Do I understand you correctly, that you basically wish the following changes?

1. If one generates a new python client from a new api.yml, no manual changes, to anything (neither .mustache files, nor generated files) should be necessary. This point is already fulfilled:
   The change with the /nullable to the model.mustach-template only has the be made once (in this PR), it basically creates our own python code generator. If a new api is written, only the script has to be rerun, no manual changes of any code have to be performed.

2. We do not want that many copied files as template. Ideally, we could use the generator without customers templates. To achieve this, I create the following PR for swagger-codegen: [swagger-api/swagger-codegen#10906](https://github.com/swagger-api/swagger-codegen/pull/10906)

3. The lightly pip package should not contain any code needed for generating the client. We could solve this by putting the files in the folder `openapi_client_generator` into the lightly-core package. What do you think about that?

4. There should be as little files and code in the repo as possible. Thus all generated files not needed should be deleted.

5. The new requirements added should be specified in the PIP package requirements.

@philippmwirth:
Do I understand you correctly, that you basically wish the following changes?

1. If one generates a new python client from a new api.yml, no manual changes, to anything (neither .mustache files, nor generated files) should be necessary. This point is already fulfilled:
   The change with the /nullable to the model.mustach-template only has the be made once (in this PR), it basically creates our own python code generator. If a new api is written, only the script has to be rerun, no manual changes of any code have to be performed.

2. We do not want that many copied files as template. Ideally, we could use the generator without customers templates. To achieve this, I create the following PR for swagger-codegen: [swagger-api/swagger-codegen#10906](https://github.com/swagger-api/swagger-codegen/pull/10906)

3. The lightly pip package should not contain any code needed for generating the client. We could solve this by putting the files in the folder `openapi_client_generator` into the lightly-core package. What do you think about that?

4. There should be as little files and code in the repo as possible. Thus all generated files not needed should be deleted.

5. The new requirements added should be specified in the PIP package requirements.

Yes, this is pretty accurate. Only one thing: I don't think it would be such a good idea to put the generator in the lightly-core repo. Can we not simply clone the code and apply the changes with a patch? My guess is we could write a script which retrieves the code, applies the patch, and then generates the openapi code.

@MalteEbner
MalteEbner force-pushed the openapi_generated_client branch from 24f6766 to bde4a85 Compare February 15, 2021 08:19
@MalteEbner
MalteEbner marked this pull request as draft February 15, 2021 08:55
@MalteEbner MalteEbner closed this Feb 15, 2021
@MalteEbner
MalteEbner deleted the openapi_generated_client branch February 15, 2021 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants