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

Single quotes in example values breaks auto-generated test cases #112

Closed
fullcircle23 opened this issue Apr 10, 2020 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@fullcircle23
Copy link

fullcircle23 commented Apr 10, 2020

OpenAPI Generator for Python auto-generates fully formed test cases in Travis-CI. These tests revealed possible issues and/or room for improvements in the OpenAPI spec.

The first type of issue that broke several tests with invalid syntax error are the single quotes in example values. Screenshot of the errors (sample) in travis job log below or view the raw log.

image

Examples of the OpenAPI spec that caused the error:

Example 1:
maxTransactionsPerAggregate:
type: string
description: Maximum number of transactions per aggregate.
example: 1'000

Example 2:
currencyMosaicId:
type: string
description: Mosaic id used as primary chain currency.
example: 0x621E'C5B4'0385'6FC2

The fix is to remove the single quotes in the example values.
1.) 1'000 is replaced with 1000
2.) 0x621E'C5B4'0385'6FC2 is replaced with 0x621EC5B403856FC2

Altogether, the invalid syntax errors were found in 12 test cases and the corresponding values (with some repeats) are as follows:

  1. test_aggregate_network_properties_dto.py
    • max_transactions_per_aggregate = '1'000'
  2. test_chain_properties_dto.py
    • currency_mosaic_id = '0x621E'C5B4'0385'6FC2'
  3. test_hash_lock_network_properties_dto.py
    • locked_funds_per_aggregate = '10'000'000'
  4. test_mosaic_network_properties_dto.py
    • max_mosaics_per_account = '10'000'
  5. test_network_configuration_dto.py
    • currency_mosaic_id = '0x621E'C5B4'0385'6FC2'
  6. test_plugins_properties_dto.py
    • max_transactions_per_aggregate = '1'000'
  7. test_chain_properties_dto.py
    • harvesting_mosaic_id = '0x4291'ED23'000A'037A'
  8. test_mosaic_network_properties_dto.py
    • max_mosaics_per_account = '10'000'
  9. test_network_configuration_dto.py
    • harvesting_mosaic_id = '0x4291'ED23'000A'037A'
  10. test_plugins_properties_dto.py
    • max_mosaics_per_account = '10'000'
  11. test_chain_properties_dto.py
    • initial_currency_atomic_units = '8'998'999'998'000'000'
  12. test_network_configuration_dto.py
    • initial_currency_atomic_units = '8'998'999'998'000'000'

As a workaround, I've added a script in existing download-and-patch.sh to fix the above values. I've also attached the openapi yml with and without the single quote fix patch for comparison:
openapi3-any-of-patch.yml.txt
openapi3-any-of-patch-single-quote-patch.yml.txt

@dgarcia360 I can also fix the above values in the spec files in this repo and remove the workaround patch. Please let me know.

I'm also looking into the other failed test cases.

@dgarcia360 dgarcia360 added the bug Something isn't working label Apr 10, 2020
@dgarcia360
Copy link
Contributor

@fullcircle23 The API returns the values with quotes like 0x621E'C5B4'0385'6FC2, we'll have to skip the quotes somehow rather than remove them from the examples. Let's keep your patch so that you can advance with the development while we investigate how we can scape the quotes.

Could you please test if the Python generator does not complain if you wrap the affected examples with double quotes?

Example:

currencyMosaicId:
	type: string
	description: Mosaic id used as primary chain currency.
	example: "0x621E'C5B4'0385'6FC2"

@fullcircle23
Copy link
Author

Thanks @dgarcia360. I'll test wrapping the affected examples with double quotes.

Btw, which API "returns the values with quotes"?

@dgarcia360
Copy link
Contributor

@fullcircle23 /network/properties endpoint from catapult-rest. You can check a response example here: http://api-01.us-west-1.symboldev.network:3000/network/properties

@fullcircle23
Copy link
Author

fullcircle23 commented Apr 14, 2020

@dgarcia360 Wrapping with double quotes worked on my local environment but not on travis. On travis (trusty), the openapi generator for python converted the double quotes to single quotes yielding incorrect syntax, for example:
max_transactions_per_aggregate = '1'000'
whereas in my local (macOS), the single quotes were stripped:
max_transactions_per_aggregate = '1000'

Following are the same versions in both my local env and in travis:

  • Python 3.6.3
  • openapi-generator 4.2.3

Following are different:

OS

  • local: macOS High Sierra
  • travis: Ubuntu 14.04

pyenv

  • local: 1.2.18
  • travis: 1.1.5

Spent a whole day on this including setting up my laptop with pyenv to have matching python versions and various other config changes but not getting very far.

There's a related openapi-generator [BUG][PYTHON] Single quotes not escaped
but it's closed.

Anyway, it seems like a bug still, probably related to the environment. So I've sent a request to travis-ci support to activate debug mode for the repository.

Meanwhile, I'm going to switch back to stripping the single quotes from those values in the download-and-patch.sh script.

@fullcircle23
Copy link
Author

@dgarcia360 Wrapping with double quotes worked on my local environment but not on travis. On travis (trusty), the openapi generator for python converted the double quotes to single quotes yielding incorrect syntax, for example:
max_transactions_per_aggregate = '1'000'
whereas in my local (macOS), the single quotes were stripped:
max_transactions_per_aggregate = '1000'

I've managed to replicate the results in travis on my local env after fixing some issues in my local java environment. So I can confirm that string values with single quotes that are wrapped in double quotes ends up being wrapped in single quotes in the generated test files. I've found a bug in openapi-generator that caused this and will be raising an issue over there.

@fullcircle23
Copy link
Author

I've fixed this issue in OpenAPITools/openapi-generator.
Issue is OpenAPITools/openapi-generator#5981.
Pending merge of PR OpenAPITools/openapi-generator#6451.

@rg911 rg911 closed this as completed Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants