Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nms): generate swagger api for typescript #12757

Merged
merged 4 commits into from May 23, 2022

Conversation

Neudrino
Copy link
Contributor

@Neudrino Neudrino commented May 17, 2022

Summary

Generate the Swagger API for TypeScript in parallel to the one for Flow.
This is a preparatory step for migrating the NMS to TypeScript.

The tool the we are using for the flow API generation is discontinued and generates a broken TypeScript API.
Therefore we had to use a different tool for TypeScript.

We found an issues in our current swagger spec that we had to work around. There are three endpoints that return a differently shaped response based on a query parameter. This has been realised by putting the URL a second time into the swagger spec with a hard coded query parameter, which is not allowed. We should probably fix that by splitting the endpoints at some point.

Another problem that we ran into is more related to the generation tool. It will create types with reserved keywords. Since this only effected a very sparingly used subtype we renamed the type to unblock us.

The TypeScript API will be added in a separate PR #12761.

Fixes #12756

Done in pairing with @thmsschmitt .

@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines. label May 17, 2022
@github-actions
Copy link
Contributor

Thanks for opening a PR! 💯

A couple initial guidelines

Howto

  • Reviews. The "Reviewers" listed for this PR are the Magma maintainers who will shepherd it.
  • Checks. All required CI checks must pass before merge.
  • Merge. Once approved and passing CI checks, use the ready2merge label to indicate the maintainers can merge your PR.

More info

Please take a moment to read through the Magma project's

If this is your first Magma PR, also consider reading

@github-actions github-actions bot added component: nms NMS-related issue component: orc8r Orchestrator-related issue labels May 17, 2022
@Neudrino Neudrino requested a review from thmsschmitt May 17, 2022 14:33
@magma magma deleted a comment from github-actions bot May 17, 2022
@magma magma deleted a comment from github-actions bot May 17, 2022
@magma magma deleted a comment from github-actions bot May 17, 2022
@magma magma deleted a comment from github-actions bot May 17, 2022
@magma magma deleted a comment from github-actions bot May 17, 2022
@magma magma deleted a comment from github-actions bot May 17, 2022
@magma magma deleted a comment from github-actions bot May 17, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 17, 2022

feg-workflow

    2 files  202 suites   38s ⏱️
371 tests 371 ✔️ 0 💤 0
385 runs  385 ✔️ 0 💤 0

Results for commit dce6a29.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented May 17, 2022

nms-workflow

0 files  0 suites   0s ⏱️
0 tests 0 ✔️ 0 💤 0

Results for commit dce6a29.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented May 17, 2022

dp-workflow

  2 files    2 suites   4m 1s ⏱️
15 tests 15 ✔️ 0 💤 0

Results for commit dce6a29.

♻️ This comment has been updated with latest results.

@Neudrino Neudrino force-pushed the nms/typescript-api-generation branch from cc6052e to f1ba4d5 Compare May 17, 2022 15:16
@pull-request-size pull-request-size bot added size/L Denotes a Pull Request that changes 100-499 lines. and removed size/M Denotes a PR that changes 30-99 lines. labels May 17, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 17, 2022

cloud-workflow

    7 files  354 suites   2m 23s ⏱️
942 tests 942 ✔️ 0 💤 0

Results for commit dce6a29.

♻️ This comment has been updated with latest results.

@thmsschmitt thmsschmitt force-pushed the nms/typescript-api-generation branch 3 times, most recently from ca72c95 to c546c67 Compare May 17, 2022 16:22
@thmsschmitt thmsschmitt marked this pull request as ready for review May 17, 2022 17:12
@thmsschmitt thmsschmitt requested review from a team and maxhbr May 17, 2022 17:12
@github-actions
Copy link
Contributor

github-actions bot commented May 17, 2022

agw-workflow

     78 files     123 suites   7m 10s ⏱️
1 159 tests 1 154 ✔️ 4 💤 1
1 191 runs  1 185 ✔️ 4 💤 2

For more details on these failures, see this check.

Results for commit dce6a29.

♻️ This comment has been updated with latest results.

@thmsschmitt thmsschmitt force-pushed the nms/typescript-api-generation branch from c546c67 to 5099783 Compare May 18, 2022 06:45
Copy link
Contributor

@sebathomas sebathomas left a comment

Choose a reason for hiding this comment

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

Looking good.

Comment on lines 61 to 63
sed -i -e 's/?view=full(/_view_full(/g' "${file}"
sed -i -e 's/?verbose=false(/_verbose_false(/g' "${file}"
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is the workaround for the hard-coded query parameters? Maybe add a TODO to remove them.

@magma magma deleted a comment from github-actions bot May 18, 2022
@thmsschmitt thmsschmitt force-pushed the nms/typescript-api-generation branch from 5099783 to 7934353 Compare May 18, 2022 13:52
@maxhbr
Copy link
Member

maxhbr commented May 18, 2022

Another problem that we ran into is more related to the generation tool. It will create types with reserved keywords. Since this only effected a very sparingly used subtype we renamed the type to unblock us.

Changing the name of the type is not breaking API, right?

@thmsschmitt
Copy link
Contributor

Changing the name of the type is not breaking API, right?

Correct, that is only an internal thing.

Copy link
Member

@maxhbr maxhbr left a comment

Choose a reason for hiding this comment

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

a lot of nitpicking on Bash, but please replace the find in line 58 with something more specific.

nms/scripts/generateAPIFromSwaggerForTypeScript.sh Outdated Show resolved Hide resolved
nms/scripts/generateAPIFromSwaggerForTypeScript.sh Outdated Show resolved Hide resolved
nms/scripts/generateAPIFromSwaggerForTypeScript.sh Outdated Show resolved Hide resolved
nms/scripts/generateAPIFromSwaggerForTypeScript.sh Outdated Show resolved Hide resolved

nms_gen:
# generate Swagger API bindings for NMS
$(MAGMA_ROOT)/nms/scripts/generateAPIFromSwagger.sh $(SWAGGER_V1_YML) $(SWAGGER_NMS_OUT)
$(MAGMA_ROOT)/nms/scripts/generateAPIFromSwaggerForTypeScript.sh $(SWAGGER_V1_YML) $(SWAGGER_NMS_OUT_TS)
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be more idiomatic to call a gen target in the nms makefile. But since it was done that way also previously, it might be fine.

echo "Input file: $INPUT";
echo "Output directory: $OUTPUT";

yarn --silent openapi -i "${INPUT}" -o "${OUTPUT}"
Copy link
Contributor

Choose a reason for hiding this comment

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

We have to set --client axios because we also used this API from node in a few places.

@thmsschmitt thmsschmitt force-pushed the nms/typescript-api-generation branch from 7934353 to b602119 Compare May 18, 2022 17:44
Copy link
Member

@maxhbr maxhbr left a comment

Choose a reason for hiding this comment

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

LGTM

@thmsschmitt thmsschmitt force-pushed the nms/typescript-api-generation branch from b602119 to ada007d Compare May 19, 2022 10:51
@thmsschmitt thmsschmitt force-pushed the nms/typescript-api-generation branch from ada007d to b49efa5 Compare May 19, 2022 11:05
Neudrino and others added 4 commits May 23, 2022 12:05
Signed-off-by: Fritz Lehnert <13189449+Neudrino@users.noreply.github.com>
Signed-off-by: Fritz Lehnert <13189449+Neudrino@users.noreply.github.com>
Signed-off-by: Fritz Lehnert <13189449+Neudrino@users.noreply.github.com>
…ackageType usage

Signed-off-by: Thomas Schmitt <thomas.schmitt@tngtech.com>
@Neudrino Neudrino force-pushed the nms/typescript-api-generation branch from b49efa5 to dce6a29 Compare May 23, 2022 10:05
@thmsschmitt thmsschmitt merged commit fef3749 into magma:master May 23, 2022
@thmsschmitt thmsschmitt deleted the nms/typescript-api-generation branch May 23, 2022 11:17
@Neudrino
Copy link
Contributor Author

A follow up is at #12761.

mpfirrmann pushed a commit to mpfirrmann/magma that referenced this pull request May 31, 2022
* feat(nms): generate swagger api for typescript

Signed-off-by: Fritz Lehnert <13189449+Neudrino@users.noreply.github.com>

* feat(nms): rename package in swagger api

Signed-off-by: Fritz Lehnert <13189449+Neudrino@users.noreply.github.com>

* feat(nms): auto-generated files from swagger

Signed-off-by: Fritz Lehnert <13189449+Neudrino@users.noreply.github.com>

* refactor(nms): Make TypeScript generation script executable and fix PackageType usage

Signed-off-by: Thomas Schmitt <thomas.schmitt@tngtech.com>

Co-authored-by: Thomas Schmitt <thomas.schmitt@tngtech.com>
emakeev pushed a commit to emakeev/magma that referenced this pull request Aug 5, 2022
* feat(nms): generate swagger api for typescript

Signed-off-by: Fritz Lehnert <13189449+Neudrino@users.noreply.github.com>

* feat(nms): rename package in swagger api

Signed-off-by: Fritz Lehnert <13189449+Neudrino@users.noreply.github.com>

* feat(nms): auto-generated files from swagger

Signed-off-by: Fritz Lehnert <13189449+Neudrino@users.noreply.github.com>

* refactor(nms): Make TypeScript generation script executable and fix PackageType usage

Signed-off-by: Thomas Schmitt <thomas.schmitt@tngtech.com>

Co-authored-by: Thomas Schmitt <thomas.schmitt@tngtech.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: nms NMS-related issue component: orc8r Orchestrator-related issue size/L Denotes a Pull Request that changes 100-499 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix swagger.yml issue and generate typescript API
4 participants