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

set specific encoding for all platforms #298

Merged
merged 2 commits into from
Nov 8, 2023

Conversation

AllyW
Copy link
Member

@AllyW AllyW commented Oct 30, 2023

For *nix os, utf8 is default system encoding which is used when python open func is working without a given encoding format.

However, windows may use local systems encoding which might be incompatible with non-ascii characters in files.

Set encoding in file operations can avoid this error.

image

Copy link
Collaborator

@kairu-ms kairu-ms left a comment

Choose a reason for hiding this comment

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

Most characters are gibberish, do we need support them? Or we can filter them out from swagger source.

@AllyW
Copy link
Member Author

AllyW commented Oct 30, 2023

Most characters are gibberish, do we need support them?

CodeGen, or workspace manager in Codegen here is in charge of loading and enabling the management of related api definitions in swagger file.

Swagger quality and cleaning can be checked and enhanced by service developer when generating codes or by codegen developer when pre-loading swaggers (if planed later), in my view.

@kairu-ms
Copy link
Collaborator

Most characters are gibberish, do we need support them?

CodeGen, or workspace manager in Codegen here is in charge of loading and enabling the management of related api definitions in swagger file.

Swagger quality and cleaning can be checked and enhanced by service developer when generating codes or by codegen developer when pre-loading swaggers (if planed later), in my view.

It's better clean then when loading swaggers. Can you add this support in current PR? I think those can be added in this function

def load_file(self, file_path):
from swagger.model.schema.swagger import Swagger
loaded = self.get_loaded(file_path)
if loaded is not None:
return loaded
with open(file_path, 'r', encoding='utf-8') as f:
body = json.load(f)
if 'example' in file_path.lower():
loaded = body
else:
self.patch_swagger(body)
loaded = Swagger(body)
self.loaded_swaggers[file_path] = loaded
self._cache_loaded(loaded, file_path)
return loaded

@AllyW AllyW force-pushed the fix-charmap-encoding-except branch from b020396 to 4b4786f Compare November 8, 2023 03:18
@kairu-ms kairu-ms merged commit ed8c7ff into Azure:dev Nov 8, 2023
@kairu-ms kairu-ms mentioned this pull request Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants